Skip to content

Commit

Permalink
CBG-4067 Only skip releasing sequences for timeouts (#7050)
Browse files Browse the repository at this point in the history
We want to release sequences in scenarios where we know the write did not occur.
  • Loading branch information
adamcfraser authored and bbrks committed Sep 26, 2024
1 parent 8cffb4e commit 3361fa6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions base/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ func IsTemporaryKvError(err error) bool {
return false
}

func IsTimeoutError(err error) bool {
if err == nil {
return false
}

if errors.Is(err, gocb.ErrTimeout) || errors.Is(err, ErrTimeout) {
return true
}

return false
}

func IsXattrNotFoundError(err error) bool {
if unwrappedErr := pkgerrors.Cause(err); unwrappedErr == nil {
return false
Expand Down
3 changes: 2 additions & 1 deletion db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,8 @@ func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, do

// If the WriteUpdate didn't succeed, check whether there are unused, allocated sequences that need to be accounted for
if err != nil {
if !base.IsTemporaryKvError(err) {
// For timeout errors, the write may or may not have succeeded so we cannot release the sequence as unused
if !base.IsTimeoutError(err) {
if docSequence > 0 {
if seqErr := db.sequences().releaseSequence(ctx, docSequence); seqErr != nil {
base.WarnfCtx(ctx, "Error returned when releasing sequence %d. Falling back to skipped sequence handling. Error:%v", docSequence, seqErr)
Expand Down

0 comments on commit 3361fa6

Please sign in to comment.