Skip to content

Commit d838e54

Browse files
committed
Make TabletMap return empty replica set when stale replica is found
Makes TabletMap return empty collection for some calls to `getReplicas()`. If the current replica list for a tablet turns out to contain a host that is not present in current Metadata then empty collection is returned in an effort to misroute the query. This query will cause the tablet information to be updated when the result with the up to date information is received. It is possible that the query will be randomly routed correctly, but this case is significantly less likely with each subsequent query, although this can depend on underlying load balancing policy. This covers the node removal/replacement case of #378.
1 parent 95fa50b commit d838e54

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

driver-core/src/main/java/com/datastax/driver/core/TabletMap.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public Map<KeyspaceTableNamePair, TabletSet> getMapping() {
5757
}
5858

5959
/**
60-
* Finds hosts that have replicas for a given table and token combination
60+
* Finds hosts that have replicas for a given table and token combination. Meant for use in query
61+
* planning. Can return empty collection if internal replica list information is determined not up
62+
* to date.
6163
*
6264
* @param keyspace the keyspace that table is in
6365
* @param table the table name
@@ -93,8 +95,14 @@ public Set<UUID> getReplicas(String keyspace, String table, long token) {
9395

9496
HashSet<UUID> uuidSet = new HashSet<>();
9597
for (HostShardPair hostShardPair : row.replicas) {
96-
if (cluster.metadata.getHost(hostShardPair.getHost()) != null)
98+
if (cluster.metadata.getHost(hostShardPair.getHost()) == null) {
99+
// We've encountered a stale host. Return an empty set to
100+
// misroute the request. If misrouted then response will
101+
// contain up to date tablet information that will be processed.
102+
return Collections.emptySet();
103+
} else {
97104
uuidSet.add(hostShardPair.getHost());
105+
}
98106
}
99107
return uuidSet;
100108
} finally {

0 commit comments

Comments
 (0)