3.x: Implement LWT Replica-Only Routing with Local DC Prioritization#796
Merged
dkropachev merged 4 commits intoscylladb:scylla-3.xfrom Feb 9, 2026
Merged
Conversation
nikagra
commented
Jan 30, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Implements replica-only routing for LWT queries within TokenAwarePolicy, prioritizing local-DC replicas and allowing fallback to regular routing based on a new QueryOptions setting.
Changes:
- Removed
RequestHandler’s LWT special-casing so LWTs flow through the configured load balancing policy chain. - Added LWT-aware query planning to
TokenAwarePolicy(replicas-only, local-first, filters DOWN/IGNORED), configurable viaQueryOptions.RequestRoutingMethod. - Added unit tests covering LWT replica filtering and updated README with the new optimization.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java | Adds LWT-specific replica-only query plan behavior and related Javadoc. |
| driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java | Removes LWT replica-routing bypass so LWT uses the LBP chain. |
| driver-core/src/main/java/com/datastax/driver/core/QueryOptions.java | Adds configurable LWT routing method (RequestRoutingMethod) and default. |
| driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java | Adds unit tests for LWT local-first ordering and filtering behavior. |
| README.md | Documents the LWT optimization feature at a high level. |
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java
Show resolved
Hide resolved
nikagra
commented
Jan 30, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
dkropachev
requested changes
Jan 30, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java
Outdated
Show resolved
Hide resolved
9cbf511 to
1292aad
Compare
nikagra
commented
Feb 3, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
2db1bb1 to
12ce4f6
Compare
driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
06f9d1f to
ce77e27
Compare
dkropachev
requested changes
Feb 5, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/RackAwareRoundRobinPolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/RackAwareRoundRobinPolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
ce77e27 to
1a3a14f
Compare
dkropachev
requested changes
Feb 9, 2026
driver-core/src/main/java/com/datastax/driver/core/policies/RackAwareRoundRobinPolicy.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
09482e5 to
19bd2f5
Compare
… in `TokenAwarePolicy`. 🎟️ feat: Enhance LWT query routing by prioritizing local replicas and implementing fallback to child policy feat: Refactor LWT host iterator to preserve replica order and improve host filtering Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dmitry Kropachev <dmitry.kropachev@gmail.com>
19bd2f5 to
a5f4e7a
Compare
dkropachev
approved these changes
Feb 9, 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.
Implement LWT Replica-Only Routing with Local DC Prioritization
Overview
This PR adds specialized load balancing for Lightweight Transaction (LWT) queries in
com.datastax.driver.core.policies.TokenAwarePolicy, optimizing performance by routing exclusively to replicas and prioritizing local datacenter replicas. This reduces coordinator forwarding overhead and minimizes contention during Paxos consensus phases.Motivation
LWT queries require multi-round Paxos coordination and are sensitive to latency and coordinator variance. Prior behavior could:
LOCAL_SERIALtransactionsThis change ensures LWT queries target replicas directly, with local replicas first, resulting in lower latency and reduced contention.
Changes
1. TokenAwarePolicy: LWT-Aware Routing Path
TokenAwarePolicy#newQueryPlan(...).REGULARfor non-LWT, or whenQueryOptions.setLoadBalancingLwtRequestRoutingMethod(REGULAR)is configured.PRESERVE_REPLICA_ORDERfor LWT (default): uses a specialized iterator that returns replicas only, local-first, preserving primary replica order.Metadata#getReplicasList(...).2. LWTHostIterator: Replica-Only, Local-First
TokenAwarePolicy.LWTHostIteratorthat:childPolicy.distance(host) == LOCAL).3. Key Design Decisions
✅ Rack Awareness Intentionally Omitted
✅ Replica-Only with Pragmatic Fallback
✅ Local DC First, Remote DC Second
LOCAL) are returned first; remote replicas (distance ==REMOTE) follow.LOCAL_SERIAL, this keeps Paxos messaging within the local DC for best performance, while still allowing remote replicas when needed.✅ Filter DOWN and IGNORED Hosts
LWTHostIteratorskips hosts that are!isUp()or havedistance == IGNORED.IGNOREDhonors user-configured allowlists and filters.Documentation
com.datastax.driver.core.policies.TokenAwarePolicyexplaining LWT routing behavior, requirements, fallback behavior, and rack avoidance rationale.LWTHostIteratordocuments filtering and ordering logic.Requirements for LWT Replica-Only Routing
For the optimization to apply, the following must be true:
DCAwareRoundRobinPolicyor similar.Configuration
LWT routing method is controlled via:
PRESERVE_REPLICA_ORDER(replicas-only, local-first)REGULAR(uses standard token-aware routing with non-replica fallback)Performance Impact
Expected Improvements (with routing info available)
LOCAL_SERIAL.Fallback Scenario (routing info missing or replicas unavailable)
Compatibility
REGULARis configured.Testing
Unit/Integration Tests
Validation Performed
mvn fmt:format(repo standard)make compile-allormvn compile -pl driver-core -amdriver-coreandintegration-testsmodulesmake checkormvn verify -DskipTestsMigration Notes
No action required for existing users. The optimization is automatic when:
TokenAwarePolicy(default in most configurations)Statement#isLWT()and server-provided metadataUsers not meeting these conditions continue to work with existing behavior.
Related Documentation
manual/load_balancing/com.datastax.driver.core.policies.TokenAwarePolicyCloses
#752