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
fd14b971
Commit
fd14b971
authored
May 21, 2023
by
Vladimir Barsukov
Browse files
add sleep on try
parent
d5132e81
Changes
2
Show whitespace changes
Inline
Side-by-side
conn.go
View file @
fd14b971
package
zdb
import
(
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
...
...
@@ -31,3 +32,7 @@ func (c connMode) String() string {
return
"unknown"
}
}
func
(
c
conn
)
ToString
()
string
{
return
fmt
.
Sprintf
(
"%s: %s:%d"
,
c
.
Mode
,
c
.
Config
()
.
ConnConfig
.
Host
,
c
.
Config
()
.
ConnConfig
.
Port
)
}
pool.go
View file @
fd14b971
...
...
@@ -35,6 +35,7 @@ type Pool struct {
Continues
[]
string
ContinuesTry
[]
string
TryOnError
int
TryOnSleep
time
.
Duration
}
func
New
()
*
Pool
{
...
...
@@ -46,6 +47,7 @@ func New() *Pool {
Continues
:
[]
string
{
"connect"
,
"EOF"
,
"conflict with recovery"
},
ContinuesTry
:
[]
string
{
"conflict with recovery"
},
TryOnError
:
1
,
TryOnSleep
:
time
.
Second
*
5
,
}
}
...
...
@@ -152,13 +154,15 @@ func (d *Pool) execWrapper(pool connMode, dst any, f func(conn *conn, dst1 any)
if
try
<
d
.
TryOnError
&&
contains
(
err
.
Error
(),
d
.
ContinuesTry
)
{
try
++
d
.
logger
.
Printf
(
"DB_EXEC_WRAPPER_REPEAT_ERR: TRY: %d, %s"
,
try
,
err
.
Error
())
d
.
logger
.
Printf
(
"DB_EXEC_WRAPPER_REPEAT_ERR: SRV: %s TRY: %d; %s"
,
q
.
ToString
(),
try
,
err
.
Error
())
time
.
Sleep
(
d
.
TryOnSleep
)
goto
repeat
}
if
contains
(
err
.
Error
(),
d
.
Continues
)
{
d
.
setNotAliveConn
(
q
)
d
.
logger
.
Printf
(
"DB_EXEC_WRAPPER_ERR:
%s"
,
err
.
Error
())
d
.
logger
.
Printf
(
"DB_EXEC_WRAPPER_ERR:
SRV: %s; %s"
,
q
.
ToString
()
,
err
.
Error
())
continue
}
else
{
return
err
...
...
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