diff --git a/driver-core/src/main/java/com/datastax/driver/core/Metadata.java b/driver-core/src/main/java/com/datastax/driver/core/Metadata.java index c4cb08ba2b..e9e46cf775 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/Metadata.java +++ b/driver-core/src/main/java/com/datastax/driver/core/Metadata.java @@ -44,7 +44,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -554,9 +553,9 @@ public Set getReplicas( if (keyspace != null && table != null) { Token token = partitioner.hash(partitionKey); assert (token instanceof Token.TokenLong64); - Set hostUuids = tabletMap.getReplicas(keyspace, table, (long) token.getValue()); - if (!hostUuids.isEmpty()) { - return hostUuids.stream().map(this::getHost).collect(Collectors.toSet()); + Set replicas = tabletMap.getReplicas(keyspace, table, (long) token.getValue()); + if (!replicas.isEmpty()) { + return replicas; } } // Fall back to tokenMap diff --git a/driver-core/src/main/java/com/datastax/driver/core/TabletMap.java b/driver-core/src/main/java/com/datastax/driver/core/TabletMap.java index 3ac191fb46..6a959582c9 100644 --- a/driver-core/src/main/java/com/datastax/driver/core/TabletMap.java +++ b/driver-core/src/main/java/com/datastax/driver/core/TabletMap.java @@ -64,9 +64,9 @@ public Map getMapping() { * @param keyspace the keyspace that table is in * @param table the table name * @param token the token to look for - * @return Set of host UUIDS that do have a tablet for given token for a given table. + * @return Set of Host instances that do have a tablet for the given token and table combination. */ - public Set getReplicas(String keyspace, String table, long token) { + public Set getReplicas(String keyspace, String table, long token) { TabletMap.KeyspaceTableNamePair key = new TabletMap.KeyspaceTableNamePair(keyspace, table); if (mapping == null) { @@ -93,18 +93,19 @@ public Set getReplicas(String keyspace, String table, long token) { return Collections.emptySet(); } - HashSet uuidSet = new HashSet<>(); + HashSet replicaSet = new HashSet<>(); for (HostShardPair hostShardPair : row.replicas) { - if (cluster.metadata.getHost(hostShardPair.getHost()) == null) { + Host replica = cluster.metadata.getHost(hostShardPair.getHost()); + if (replica == null) { // We've encountered a stale host. Return an empty set to // misroute the request. If misrouted then response will // contain up to date tablet information that will be processed. return Collections.emptySet(); } else { - uuidSet.add(hostShardPair.getHost()); + replicaSet.add(replica); } } - return uuidSet; + return replicaSet; } finally { readLock.unlock(); }