Skip to content

Commit

Permalink
Make TabletMap return empty replica set when stale replica is found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bouncheck committed Nov 28, 2024
1 parent 95fa50b commit d838e54
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions driver-core/src/main/java/com/datastax/driver/core/TabletMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public Map<KeyspaceTableNamePair, TabletSet> getMapping() {
}

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

HashSet<UUID> uuidSet = new HashSet<>();
for (HostShardPair hostShardPair : row.replicas) {
if (cluster.metadata.getHost(hostShardPair.getHost()) != null)
if (cluster.metadata.getHost(hostShardPair.getHost()) == 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());
}
}
return uuidSet;
} finally {
Expand Down

0 comments on commit d838e54

Please sign in to comment.