Skip to content

Commit

Permalink
tmp getreplicas
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouncheck committed Jan 3, 2025
1 parent 0a108c2 commit b172384
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,25 +559,28 @@ public Set<Host> getReplicas(
String keyspace, String table, Token.Factory partitioner, ByteBuffer partitionKey) {
keyspace = handleId(keyspace);
TokenMap current = tokenMap;
if (current == null) {
return Collections.emptySet();
} else {
if (partitioner == null) {
partitioner = current.factory;
}
// If possible, try tablet lookup first
Token token = null;
if (partitioner == null && current != null) {
partitioner = current.factory;
}
if (partitioner != null) {
token = partitioner.hash(partitionKey);
}

// Tablets:
if (getKeyspace(keyspace).usesTablets()) {
if (keyspace != null && table != null) {
Token token = partitioner.hash(partitionKey);
assert (token instanceof Token.TokenLong64);
Set<Host> replicas = tabletMap.getReplicas(keyspace, table, (long) token.getValue());
if (!replicas.isEmpty()) {
return replicas;
}
return tabletMap.getReplicas(keyspace, table, (long) token.getValue());
} else {
return Collections.emptySet();
}
// Fall back to tokenMap
Set<Host> hosts = current.getReplicas(keyspace, partitioner.hash(partitionKey));
return hosts == null ? Collections.<Host>emptySet() : hosts;
}

// TokenMap:
if (current == null) return Collections.<Host>emptySet();
Set<Host> hosts = current.getReplicas(keyspace, token);
return hosts == null ? Collections.<Host>emptySet() : hosts;
}

/**
Expand Down

0 comments on commit b172384

Please sign in to comment.