Skip to content

Commit d90c5a4

Browse files
committed
Fix BasicLoadBalancingPolicy.getReplica empty partitioner
Queries getting paritioner set either from user, or when statement is being built against cdc tablet. In other cases statement does not get any partitioner. For proper tablet routing driver needs to calculate token from the key, which needs partitioner, if partitioner is not present driver returns empty replica list. This fix is rather quick-fix. Implementing proper solution that will help with CDC+tablets case, is scheduled at #502
1 parent 2a62541 commit d90c5a4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Diff for: core/src/main/java/com/datastax/oss/driver/api/core/metadata/TokenMap.java

+4
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,8 @@ default Set<Node> getReplicas(@NonNull String keyspaceName, @NonNull TokenRange
189189
/** The name of the partitioner class in use, as reported by the Cassandra nodes. */
190190
@NonNull
191191
String getPartitionerName();
192+
193+
/** The partitioner class in use, as reported by the Cassandra nodes. */
194+
@NonNull
195+
Partitioner getPartitioner();
192196
}

Diff for: core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/BasicLoadBalancingPolicy.java

+3
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ protected Set<Node> getReplicas(@Nullable Request request, @Nullable Session ses
333333
}
334334

335335
partitioner = request.getPartitioner();
336+
if (partitioner == null && maybeTokenMap.isPresent()) {
337+
partitioner = maybeTokenMap.get().getPartitioner();
338+
}
336339
} catch (Exception e) {
337340
// Protect against poorly-implemented Request instances
338341
LOG.error("Unexpected error while trying to compute query plan", e);

Diff for: core/src/main/java/com/datastax/oss/driver/internal/core/metadata/token/DefaultTokenMap.java

+6
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public String getPartitionerName() {
207207
return tokenFactory.getPartitionerName();
208208
}
209209

210+
@NonNull
211+
@Override
212+
public Partitioner getPartitioner() {
213+
return tokenFactory;
214+
}
215+
210216
private KeyspaceTokenMap getKeyspaceMap(CqlIdentifier keyspace) {
211217
Map<String, String> config = replicationConfigs.get(keyspace);
212218
return (config == null) ? null : keyspaceMaps.get(config);

0 commit comments

Comments
 (0)