Skip to content

Commit

Permalink
Fixes duplicate idempotent key issue during recovery and non-recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
charithabandi committed Dec 1, 2023
1 parent c139049 commit 827a61c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
3 changes: 1 addition & 2 deletions internal/sessions/committable/committable.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ func (a *SavepointCommittable) Commit(ctx context.Context, idempotencyKey []byte
a.writable = false

if a.skip {
a.skip = false
return a.db.Get(ctx, ApphashKey, true)
}

if a.savepoint == nil {
return nil, fmt.Errorf("no session exists")
}

a.skip = false

var appHash []byte
if a.idFn != nil {
var err error
Expand Down
6 changes: 1 addition & 5 deletions internal/sessions/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func (m *MultiCommitter) Begin(ctx context.Context, idempotencyKey []byte) (err
}

// if lastKey is not nil, we are recovering from a crash
if lastKey != nil {
if !bytes.Equal(lastKey, idempotencyKey) {
return fmt.Errorf("%w on recovery: expected %s, got %s", ErrIdempotencyKeyMismatch, lastKey, idempotencyKey)
}
if bytes.Equal(lastKey, idempotencyKey) {
for _, committable := range m.committables {
err = committable.BeginRecovery(ctx, idempotencyKey)
if err != nil {
Expand Down Expand Up @@ -143,7 +140,6 @@ func (m *MultiCommitter) Commit(ctx context.Context, idempotencyKey []byte) (id
id = append(id, newId...)
}

err = deleteCurrentKey(m.kv)
return id, err
}

Expand Down

0 comments on commit 827a61c

Please sign in to comment.