Skip to content

Commit ed5cd3b

Browse files
committed
RackeAware: consider nodes from non-local rack as remotes
Considering them as `LOCAL` confuses `TokenAwarePolicy` as result in some cases it shuffle nodes from non-local and local racks together.
1 parent 3179c16 commit ed5cd3b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

driver-core/src/main/java/com/datastax/driver/core/policies/RackAwareRoundRobinPolicy.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static Builder builder() {
7878
new CopyOnWriteArrayList<Host>();
7979
private final CopyOnWriteArrayList<Host> liveHostsRemoteRacksLocalDC =
8080
new CopyOnWriteArrayList<Host>();
81-
private final AtomicInteger index = new AtomicInteger();
81+
@VisibleForTesting final AtomicInteger index = new AtomicInteger();
8282

8383
@VisibleForTesting volatile String localDc;
8484
@VisibleForTesting volatile String localRack;
@@ -205,7 +205,13 @@ private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> l
205205
@Override
206206
public HostDistance distance(Host host) {
207207
String dc = dc(host);
208-
if (dc == UNSET || dc.equals(localDc)) return HostDistance.LOCAL;
208+
String rack = rack(host);
209+
if (dc == UNSET || dc.equals(localDc)) {
210+
if (rack == UNSET || rack.equals(localRack)) {
211+
return HostDistance.LOCAL;
212+
}
213+
return HostDistance.REMOTE;
214+
}
209215

210216
CopyOnWriteArrayList<Host> dcHosts = perDcLiveHosts.get(dc);
211217
if (dcHosts == null || usedHostsPerRemoteDc == 0) return HostDistance.IGNORED;

0 commit comments

Comments
 (0)