Fix DynamoDB KV CAS not retrying on transactional conditional check failures#7706
Merged
yeya24 merged 2 commits intoJul 20, 2026
Merged
Conversation
…ailures The Batch() error detection in the DynamoDB KV store only matched ConditionalCheckFailedException, which DynamoDB returns for single-item operations. TransactWriteItems reports condition failures as TransactionCanceledException with a ConditionalCheckFailed cancellation reason, so errors.As never matched, retry=false was returned, and the CAS loop gave up on the first attempt instead of re-reading the ring and retrying. In practice this means every ring write conflict on the DynamoDB KV store is treated as fatal. During rolling updates where many ingesters join/leave concurrently, a joining ingester that loses the optimistic concurrency race fails startup with 'failed to pick tokens in the KV store' and crashes, instead of retrying with a fresh read. Detect TransactionCanceledException and inspect CancellationReasons for ConditionalCheckFailed. TransactionConflict reasons (concurrent transaction on the same item) are equally transient and also treated as retryable. Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Ben Ye <benye@amazon.com>
danielblando
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
The
Batch()error detection in the DynamoDB KV store only matchesConditionalCheckFailedException, which DynamoDB returns for single-item operations (PutItem/UpdateItemwith aConditionExpression). ButBatch()callsTransactWriteItems, which reports condition failures asTransactionCanceledExceptionwith aConditionalCheckFailedcancellation reason instead.TransactionCanceledExceptionhas noUnwrap()and the cancellation reasons are plain data fields, soerrors.As(err, *ConditionalCheckFailedException)can never match on this code path — the SDK'sTransactWriteItemserror deserializer doesn't even have aConditionalCheckFailedExceptioncase.As a result
retry=falseis always returned for CAS write conflicts, and the CAS loop inclient.gogives up on the first attempt instead of re-reading the ring and retrying with a fresh version. The 10-retry backoff loop (maxCasRetries) is effectively dead code for the most common conflict signal.Production impact observed: during rolling updates where many ingesters cycle concurrently, a joining ingester that loses the optimistic-concurrency race on the ring key fails startup with:
and the process exits (crash + kubelet restart) instead of retrying. The failure occurs ~18ms after the CAS write — no backoff ever happens. The heartbeat path survives the same error only because its caller sleeps and retries at the next heartbeat interval.
The fix: extract the error classification into
isConditionalCheckFailure(), which handles both shapes:ConditionalCheckFailedException(single-item operations) — unchanged behaviorTransactionCanceledExceptionwith aConditionalCheckFailedcancellation reason (transactions)TransactionConflictcancellation reasons (another transaction in progress on the same item) are equally transient under concurrent ring writes and are also treated as retryable.With this fix the CAS loop does what it was designed to do on conflict: re-read the latest ring state, re-apply the mutation, and write with the fresh version condition.
Which issue(s) this PR fixes:
N/A
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags (not needed — no new flags)