Skip to content

Commit 82e5ec6

Browse files
nikagradkropachev
authored andcommitted
refactor: restructure getRequestRouting per dkropachev's corrected suggestion
Move null guard for defaultLwtRequestRoutingMethod to the call site in newQueryPlan, keeping getRequestRouting() focused on routing logic only: - isLWT() -> return defaultLwtRequestRoutingMethod immediately - serial effective CL -> return defaultLwtRequestRoutingMethod - otherwise -> REGULAR
1 parent 93065c9 commit 82e5ec6

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ public Iterator<Host> newQueryPlan(final String loggedKeyspace, final Statement
438438
clusterMetadata.getReplicasList(
439439
Metadata.quote(keyspace), tableName, statement.getPartitioner(), partitionKey);
440440

441-
switch (getRequestRouting(statement)) {
441+
QueryOptions.RequestRoutingMethod routing =
442+
defaultLwtRequestRoutingMethod != null
443+
? getRequestRouting(statement)
444+
: QueryOptions.RequestRoutingMethod.REGULAR;
445+
switch (routing) {
442446
case PRESERVE_REPLICA_ORDER:
443447
return newQueryPlanPreserveReplicaOrder(keyspace, statement, replicas);
444448
case REGULAR:
@@ -470,14 +474,14 @@ private ColumnDefinitions getRoutingVariables(Statement statement) {
470474
}
471475

472476
private QueryOptions.RequestRoutingMethod getRequestRouting(Statement statement) {
473-
if (defaultLwtRequestRoutingMethod == null) {
474-
return QueryOptions.RequestRoutingMethod.REGULAR;
475-
}
476-
ConsistencyLevel cl = statement.getConsistencyLevel();
477-
if (cl == null) {
478-
cl = queryOptions.getConsistencyLevel();
477+
if (statement.isLWT()) {
478+
return defaultLwtRequestRoutingMethod;
479479
}
480-
if (statement.isLWT() || (cl != null && cl.isSerial())) {
480+
ConsistencyLevel cl =
481+
statement.getConsistencyLevel() != null
482+
? statement.getConsistencyLevel()
483+
: queryOptions.getConsistencyLevel();
484+
if (cl != null && cl.isSerial()) {
481485
return defaultLwtRequestRoutingMethod;
482486
}
483487
return QueryOptions.RequestRoutingMethod.REGULAR;

0 commit comments

Comments
 (0)