Skip to content

Commit

Permalink
Work on comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles committed Jan 17, 2024
1 parent c289b58 commit ed7b557
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions connectors/storage/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func DoInTransaction(ctx context.Context, db *DB, fn func(conn QueryExecer) erro
return nil, backoff.Permanent(err) //nolint:wrapcheck // Not needed.
}
})
if errors.Is(err, ErrSerializationFailure) {
if err != nil && (errors.Is(err, ErrSerializationFailure) || errors.Is(err, ErrTxAborted)) {
stdlibtime.Sleep(10 * stdlibtime.Millisecond)

return DoInTransaction(ctx, db, fn)
Expand Down Expand Up @@ -180,7 +180,8 @@ func IsUnexpected(err error) bool {
!IsErr(err, ErrCheckFailed) &&
!IsErr(err, ErrRelationInUse) &&
!IsErr(err, ErrSerializationFailure) &&
!IsErr(err, ErrTxAborted)
!IsErr(err, ErrTxAborted) &&
!IsErr(err, ErrExclusionViolation)
}

func parseDBError(err error) error { //nolint:funlen // .
Expand Down Expand Up @@ -215,11 +216,16 @@ func parseDBError(err error) error { //nolint:funlen // .
return terror.New(ErrCheckFailed, map[string]any{"column": column})
}
if dbErr.SQLState() == "40001" {
return terror.New(ErrSerializationFailure, map[string]any{})
return ErrSerializationFailure
}
if dbErr.SQLState() == "25P02" {
return terror.New(ErrTxAborted, map[string]any{})
return ErrTxAborted
}
if dbErr.SQLState() == "23P01" {
return ErrExclusionViolation
}

return err
}
if errors.Is(err, pgx.ErrNoRows) {
return ErrNotFound
Expand Down
1 change: 1 addition & 0 deletions connectors/storage/v2/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
ErrCheckFailed = errors.New("check failed")
ErrSerializationFailure = errors.New("serialization failure")
ErrTxAborted = errors.New("transaction aborted")
ErrExclusionViolation = errors.New("exclusion violation")
)

type (
Expand Down

0 comments on commit ed7b557

Please sign in to comment.