scylladb / scylladb/alternator-client-java
Add key route affinity support for TransactWriteItemsRequest
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 0
- Forks
- 7
- Avg merge
- 21h 23m
- Merged PRs (30d)
- 9
Description
Summary
TransactWriteItemsRequest is not currently supported by the key route affinity feature, but transactional writes are a primary use case for LWT (Lightweight Transaction) optimization.
Background
Key route affinity improves LWT performance by routing requests with the same partition key to the same coordinator node, reducing Paxos round-trips. DynamoDB transactions (TransactWriteItems) are implemented using LWT in Alternator, making them ideal candidates for this optimization.
Current Behavior
KeyAffinityRequestClassifier.shouldApply() returns false for TransactWriteItemsRequest, causing all transactional writes to use round-robin routing regardless of the affinity mode setting.
Proposed Solution
Add support for single-partition-key transactions:
- Check if all items in the transaction target the same partition key
- If yes, apply key route affinity
- If no (multi-key transaction), fall back to round-robin
private static boolean shouldApplyTransactWriteItems(
KeyRouteAffinity mode, TransactWriteItemsRequest request) {
if (mode == KeyRouteAffinity.NONE) {
return false;
}
// TransactWriteItems always uses LWT, so both RMW and ANY_WRITE should apply
// But only if all items share the same partition key
List<TransactWriteItem> items = request.transactItems();
if (items == null || items.isEmpty()) {
return false;
}
// Extract partition key from first item and verify all items match
// Return true only if single-key transaction
return isSinglePartitionKeyTransaction(items);
}
Considerations
- Multi-key transactions: Cannot be optimized since items may need different coordinators. These should continue using round-robin.
- Table name extraction: Need to handle Put, Update, Delete, and ConditionCheck within TransactWriteItem.
- Partition key extraction: Each operation type has different structure for accessing the key.
Files to Modify
src/main/java/com/scylladb/alternator/keyrouting/KeyAffinityRequestClassifier.javasrc/test/java/com/scylladb/alternator/keyrouting/KeyAffinityRequestClassifierTest.javasrc/test/java/com/scylladb/alternator/KeyRouteAffinityClientTest.java
Acceptance Criteria
- Single-partition-key
TransactWriteItemsRequestuses key route affinity - Multi-partition-key transactions fall back to round-robin
- Unit tests cover both scenarios
- Integration test verifies transactional writes route correctly
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/main/java/com/scylladb/alternator/keyrouting/KeyAffinityRequestClassifier.java and inspect shouldApply() plus the existing request-classification tests. Add coverage in KeyAffinityRequestClassifierTest.java for single- and multi-partition-key transactions, then use KeyRouteAffinityClientTest.java to verify transactional routing behavior. Done means single-key transactions use affinity and multi-key transactions retain round-robin routing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, java
- Domain
- backend, databases, distributed-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100