Skip to content

Fix LWT prepared statement routing failure in PRESERVE_REPLICA_ORDER mode#832

Closed
Copilot wants to merge 5 commits intoscylla-4.xfrom
copilot/sub-pr-831
Closed

Fix LWT prepared statement routing failure in PRESERVE_REPLICA_ORDER mode#832
Copilot wants to merge 5 commits intoscylla-4.xfrom
copilot/sub-pr-831

Conversation

Copy link

Copilot AI commented Mar 6, 2026

LWT queries with PRESERVE_REPLICA_ORDER routing (default since 4.19.0.5) returned empty query plans when replica information wasn't available—common for prepared statements before parameter binding—causing "No node was available" errors.

Changes

  • BasicLoadBalancingPolicy.newQueryPlanPreserveReplicas — Rewrote to always produce a complete query plan with proper 4-tier node prioritization:

    1. Local DC replicas (order preserved)
    2. Remote DC replicas (order preserved)
    3. Local DC non-replicas (rotated by routing key hash or randomly)
    4. Remote DC non-replicas (rotated)
  • Moved LWT routing logic up from DefaultLoadBalancingPolicy to BasicLoadBalancingPolicyRequestRoutingMethod enum, getRequestRoutingMethod(), and newQueryPlanPreserveReplicas now live in the base class so both policy implementations get correct LWT routing.

  • Replaced diceRoll1d4() with randomNextInt(int bound) — General-purpose, easier to mock in tests.

  • Extracted LwtRoutingTestBase — Shared test base for BasicLoadBalancingPolicyLwtRoutingTest and DefaultLoadBalancingPolicyLwtRoutingTest, covering empty replicas fallback, DC prioritization, consistent rotation with routing key, and controlled randomness via Mockito spy.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

dkropachev and others added 5 commits March 5, 2026 22:41
…mode

Addresses issue #830 where LWT prepared statements fail with "No node was available"
error when using PRESERVE_REPLICA_ORDER routing (default in 4.19.0.5).

Changes:
- Enhanced newQueryPlanPreserveReplicas to include non-replica nodes with proper DC prioritization
- Added fallback logic to prevent empty query plans for prepared statements
- Implemented routing-key-based consistent rotation for non-replica nodes
- Replaced diceRoll1d4() with universal randomNextInt(bound) method
- Updated tests to validate new behavior including randomness testing

The fix maintains replica order preservation while ensuring query plans always
contain nodes, resolving the regression introduced in 4.19.0.5.
Fixes compilation warning treated as error in CI build.
Corrects syntax error in method override signature.
…licy

Move newQueryPlanPreserveReplicas, the RequestRoutingMethod enum, LWT
routing dispatch, and randomNextInt from DefaultLoadBalancingPolicy to
BasicLoadBalancingPolicy so both policies support preserve-replica-order
routing for LWT requests.

DefaultLoadBalancingPolicy now only overrides newQueryPlanRegular with
its rack-aware shuffling and slow replica avoidance logic.

Refactor LWT routing tests into an abstract LwtRoutingTestBase that
runs against both BasicLoadBalancingPolicy and DefaultLoadBalancingPolicy,
fixing pre-existing test failures caused by incorrect maxNodesPerRemoteDc
configuration and missing routing token setup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI changed the title [WIP] Fix LWT prepared statement routing failure in PRESERVE_REPLICA_ORDER mode Fix LWT prepared statement routing failure in PRESERVE_REPLICA_ORDER mode Mar 6, 2026
@dkropachev dkropachev force-pushed the fix-lwt-prepared-statement-routing-830 branch 3 times, most recently from 1f98936 to 8122539 Compare March 6, 2026 11:47
Base automatically changed from fix-lwt-prepared-statement-routing-830 to scylla-4.x March 6, 2026 12:03
@dkropachev
Copy link

Done in #831

@dkropachev dkropachev closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants