@@ -14,6 +14,8 @@ import (
14
14
"github.com/golang-migrate/migrate/v4"
15
15
"github.com/golang-migrate/migrate/v4/database"
16
16
"github.com/hashicorp/go-multierror"
17
+ "github.com/jackc/pgconn"
18
+ "github.com/jackc/pgerrcode"
17
19
"github.com/lib/pq"
18
20
"go.uber.org/atomic"
19
21
)
@@ -462,18 +464,16 @@ func (c *YugabyteDB) newBackoff(ctx context.Context) backoff.BackOff {
462
464
}
463
465
464
466
func errIsRetryable (err error ) bool {
465
- pqErr := pq. Error {}
466
- if ! errors .As (err , & pqErr ) {
467
+ var pgErr * pgconn. PgError
468
+ if ! errors .As (err , & pgErr ) {
467
469
return false
468
470
}
469
471
470
- code := string (pqErr .Code )
471
-
472
472
// Assume that it's safe to retry 08006 and XX000 because we check for lock existence
473
473
// before creating and lock ID is primary key. Version field in migrations table is primary key too
474
- // and delete all versions is an idempotend operation.
475
- return code == "40001" || // Serialization error ( optimistic locking conflict)
476
- code == "40P01" || // Deadlock
477
- code == "08006" || // Connection failure ( node down, need to reconnect)
478
- code == "XX000" // Internal error ( may happen during HA)
474
+ // and delete all versions is an idempotent operation.
475
+ return pgErr . Code == pgerrcode . SerializationFailure || // optimistic locking conflict
476
+ pgErr . Code == pgerrcode . DeadlockDetected ||
477
+ pgErr . Code == pgerrcode . ConnectionFailure || // node down, need to reconnect
478
+ pgErr . Code == pgerrcode . InternalError // may happen during HA
479
479
}
0 commit comments