@@ -14,6 +14,8 @@ import (
1414	"github.com/golang-migrate/migrate/v4" 
1515	"github.com/golang-migrate/migrate/v4/database" 
1616	"github.com/hashicorp/go-multierror" 
17+ 	"github.com/jackc/pgconn" 
18+ 	"github.com/jackc/pgerrcode" 
1719	"github.com/lib/pq" 
1820	"go.uber.org/atomic" 
1921)
@@ -462,18 +464,16 @@ func (c *YugabyteDB) newBackoff(ctx context.Context) backoff.BackOff {
462464}
463465
464466func  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 ) {
467469		return  false 
468470	}
469471
470- 	code  :=  string (pqErr .Code )
471- 
472472	// Assume that it's safe to retry 08006 and XX000 because we check for lock existence 
473473	// 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 
479479}
0 commit comments