Skip to content

Commit 98ebc5f

Browse files
committed
Use keyspace metadata in BasicLoadBalancingPolicy#getReplicas
Modifies the getReplicas method to do the tablet lookup if and only if the keyspace metadata indicates that it's a tablets-based keyspace. Otherwise refer to the token map. Previous behavior was to try tablet map lookup first regardless of the keyspace configuration.
1 parent 01987fe commit 98ebc5f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.datastax.oss.driver.api.core.metadata.Tablet;
3838
import com.datastax.oss.driver.api.core.metadata.TabletMap;
3939
import com.datastax.oss.driver.api.core.metadata.TokenMap;
40+
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
4041
import com.datastax.oss.driver.api.core.metadata.token.Partitioner;
4142
import com.datastax.oss.driver.api.core.metadata.token.Token;
4243
import com.datastax.oss.driver.api.core.session.Request;
@@ -328,7 +329,12 @@ protected Set<Node> getReplicas(@Nullable Request request, @Nullable Session ses
328329
return Collections.emptySet();
329330
}
330331

331-
if (table != null) {
332+
Optional<KeyspaceMetadata> ksMetadata =
333+
context.getMetadataManager().getMetadata().getKeyspace(keyspace);
334+
if (ksMetadata.isPresent() && ksMetadata.get().isUsingTablets()) {
335+
if (table == null) {
336+
return Collections.emptySet();
337+
}
332338
if (token == null) {
333339
if (partitioner != null) {
334340
token = partitioner.hash(key);
@@ -338,12 +344,10 @@ protected Set<Node> getReplicas(@Nullable Request request, @Nullable Session ses
338344
Tablet targetTablet =
339345
tabletMap.getTablet(keyspace, table, ((TokenLong64) token).getValue());
340346
if (targetTablet != null) {
341-
Set<Node> replicas = targetTablet.getReplicaNodes();
342-
if (!replicas.isEmpty()) {
343-
return replicas;
344-
}
347+
return targetTablet.getReplicaNodes();
345348
}
346349
}
350+
return Collections.emptySet();
347351
}
348352

349353
if (!maybeTokenMap.isPresent()) {

0 commit comments

Comments
 (0)