dkropachev opened a new pull request, #2084:
URL: https://github.com/apache/cassandra-java-driver/pull/2084
## Summary
Fixes issue #830 where LWT prepared statements fail with "No node was
available" error when using PRESERVE_REPLICA_ORDER routing method (default in
4.19.0.5).
The root cause was that the new LWT routing logic returned empty query plans
when replica information wasn't available (common for prepared statements
before parameter binding).
## Changes
### Core Fix
- **Enhanced `newQueryPlanPreserveReplicas`** to implement proper node
prioritization:
1. Local DC replicas (order preserved)
2. Remote DC replicas (order preserved)
3. Local DC non-replicas (rotated by routing key or randomly)
4. Remote DC non-replicas (rotated by routing key or randomly)
- **Added proper handling** for both `localDc == null` and `localDc != null`
cases
- **Implemented routing-key-based consistent rotation** for deterministic
behavior
- **Replaced `diceRoll1d4()` with universal `randomNextInt(bound)`** for
better testability
### Test Updates
- Updated existing LWT routing tests to match new behavior expectations
- Added controlled randomness testing using Mockito spy to mock
`randomNextInt()`
- Added tests for both consistent (with routing key) and random (without
routing key) rotation
- Updated all test references from `diceRoll1d4()` to `randomNextInt(4)`
## Behavior Changes
**Before:** LWT queries with `PRESERVE_REPLICA_ORDER` could fail with empty
query plans
**After:** LWT queries always include all available nodes with proper DC
prioritization
## Backward Compatibility
- Non-breaking: Only adds nodes that weren't previously included
- When replica information is available, behavior is enhanced but compatible
- Maintains all existing performance optimizations
- Configuration remains the same
## Test Plan
- [x] Unit tests for new query plan logic
- [x] Tests for randomness control and consistency
- [x] Regression test for issue #830 scenario
- [x] Updated existing LWT routing tests
- [ ] CI pipeline validation
Resolves #830
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]