Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Barsukov
zdb
Commits
9471bd0e
Commit
9471bd0e
authored
Jul 28, 2023
by
Vladimir Barsukov
Browse files
fix
parent
ac627f9b
Changes
1
Hide whitespace changes
Inline
Side-by-side
pool.go
View file @
9471bd0e
...
...
@@ -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
.
p
ing
(
q
);
err
!=
nil
{
if
err
=
d
.
P
ing
(
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
)
p
ing
(
q
*
Conn
)
(
err
error
)
{
func
(
d
*
Pool
)
P
ing
(
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
.
p
ing
(
q
);
err
==
nil
{
if
err
:=
d
.
P
ing
(
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
.
p
ing
(
d
.
SrvMaster
)
==
nil
d
.
SrvMaster
.
Alive
=
d
.
P
ing
(
d
.
SrvMaster
)
==
nil
}
time
.
Sleep
(
time
.
Second
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment