-
Notifications
You must be signed in to change notification settings - Fork 38
3.x: Implement LWT Replica-Only Routing with Local DC Prioritization #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.x: Implement LWT Replica-Only Routing with Local DC Prioritization #796
Conversation
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java
Outdated
Show resolved
Hide resolved
9cbf511 to
1292aad
Compare
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Show resolved
Hide resolved
2db1bb1 to
12ce4f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
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
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
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