[POC] Optimistic Locking for Delete Operations#6455
Draft
anasatirbasa wants to merge 1 commit intoaws:masterfrom
Draft
[POC] Optimistic Locking for Delete Operations#6455anasatirbasa wants to merge 1 commit intoaws:masterfrom
anasatirbasa wants to merge 1 commit intoaws:masterfrom
Conversation
5a10899 to
515b581
Compare
30f646c to
927aacb
Compare
1494faa to
a7a2356
Compare
80e81ed to
a1f9cfd
Compare
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.
Description
Adds explicit optimistic locking support for delete operations in the DynamoDB Enhanced Client, while preserving full backward compatibility.
Until now,
deleteItemoperations did not automatically apply version-based conditional checks, even when a record was annotated with@DynamoDbVersionAttribute. This created an inconsistency withputItemandupdateItem, which already integrate optimistic locking viaVersionedRecordExtension.Motivation and Context
This PR addresses community request #2358, where users expected delete operations to respect optimistic locking semantics similar to put/update operations.
An earlier attempt (PR #6043) proposed implicitly enabling version checks on deletes. However, this risked breaking existing applications that relied on unconditional deletes even when using
@DynamoDbVersionAttribute.To preserve backward compatibility, this PR introduces explicit opt-in optimistic locking.
What This PR Introduces
1. Boolean Overloads (Sync & Async)
New overloads allow explicit control of optimistic locking behavior:
T deleteItem(T keyItem, boolean useOptimisticLocking);CompletableFuture<T> deleteItem(T keyItem, boolean useOptimisticLocking);Usage:
The existing
deleteItem(T keyItem)method is now deprecated and delegates todeleteItem(keyItem, false).2. Fluent Builder API
Added discoverable builder methods:
DeleteItemEnhancedRequest.Builder#withOptimisticLocking(...)TransactDeleteItemEnhancedRequest.Builder#withOptimisticLocking(...)Example:
3. Centralized Helper: OptimisticLockingHelper
A new
@SdkPublicApiclass that:<versionAttributeName> = :version_valueANDuseOptimisticLocking == trueIf any of these conditions are not met, the delete proceeds unconditionally.
Modifications
deleteItem(T keyItem, boolean useOptimisticLocking)(Sync & Async)deleteItem(T keyItem)methods.withOptimisticLocking(...)to request buildersOptimisticLockingHelperVersionedRecordExtensionTesting
Includes:
All new and existing tests pass successfully.
Test Coverage on modified classes:
Test Coverage Checklist
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License