Commit 9471bd0e authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

fix

parent ac627f9b
......@@ -37,6 +37,7 @@ type Pool struct {
TryOnError int
TryOnSleep time.Duration
Balance Balance
PingTimout time.Duration
}
func New(ctx context.Context) *Pool {
......@@ -51,6 +52,7 @@ func New(ctx context.Context) *Pool {
TryOnError: 1,
TryOnSleep: time.Second,
Balance: BalanceLeastConn,
PingTimout: time.Second,
}
}
......@@ -79,6 +81,7 @@ func (d *Pool) WithContext(ctx context.Context) *Pool {
TryOnError: d.TryOnError,
TryOnSleep: d.TryOnSleep,
Balance: d.Balance,
PingTimout: d.PingTimout,
}
}
......@@ -150,7 +153,7 @@ func (d *Pool) newConn(mode connMode, pgConnString string) (q *Conn, err error)
q = &Conn{Pool: pgxPool, Alive: false, Mode: mode}
if err = d.ping(q); err != nil {
if err = d.Ping(q); err != nil {
return q, err
}
......@@ -256,10 +259,10 @@ func (d *Pool) execWrapper(pool connMode, dst any, f func(conn *Conn, dst1 any)
}
}
func (d *Pool) ping(q *Conn) (err error) {
func (d *Pool) Ping(q *Conn) (err error) {
var n any
if err = d.qGet(q, &n, "SELECT 1"); err != nil {
if err = d.WithTimeout(d.PingTimout).qGet(q, &n, "SELECT 1"); err != nil {
d.logger.Printf("DB_PING_ERR: SRV: %s; %v",
q.ToString(),
err,
......@@ -304,7 +307,7 @@ func (d *Pool) Start() {
rep:
for i, q := range d.notAliveConns {
if err := d.ping(q); err == nil {
if err := d.Ping(q); err == nil {
d.mu.Lock()
q.Alive = true
d.notAliveConns = remove(d.notAliveConns, i)
......@@ -319,7 +322,7 @@ func (d *Pool) Start() {
}
if d.SrvMaster != nil {
d.SrvMaster.Alive = d.ping(d.SrvMaster) == nil
d.SrvMaster.Alive = d.Ping(d.SrvMaster) == nil
}
time.Sleep(time.Second)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment