Skip to content

Commit 1c32d98

Browse files
committed
Update TokenAwarePolicy.make_query_plan to schedule to replicas first
End result should be like this: 1. Replicas from the same RACK (if rack is specified) 2. Replicas from the same DC, but Remote RACK (if rack is specified) 3. Replicas from the same DC (if rack is not specified) 3. Replicas from the remote DC 5. Non-replicas in the same order
1 parent f52edbc commit 1c32d98

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cassandra/policies.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,21 @@ def make_query_plan(self, working_keyspace=None, query=None):
530530
if self.shuffle_replicas:
531531
shuffle(replicas)
532532

533-
for replica in replicas:
534-
if replica.is_up and child.distance(replica) in [HostDistance.LOCAL, HostDistance.LOCAL_RACK]:
535-
yield replica
533+
def yield_in_order(hosts):
534+
for replica in hosts:
535+
if replica.is_up and child.distance(replica) == HostDistance.LOCAL_RACK:
536+
yield replica
536537

537-
for host in child.make_query_plan(keyspace, query):
538-
# skip if we've already listed this host
539-
if host not in replicas or child.distance(host) == HostDistance.REMOTE:
540-
yield host
538+
for replica in hosts:
539+
if replica.is_up and child.distance(replica) == HostDistance.LOCAL:
540+
yield replica
541+
542+
for replica in hosts:
543+
if replica.is_up and child.distance(replica) == HostDistance.REMOTE:
544+
yield replica
545+
546+
yield from yield_in_order(replicas)
547+
yield from yield_in_order([host for host in child.make_query_plan(keyspace, query) if host not in replicas])
541548

542549
def on_up(self, *args, **kwargs):
543550
return self._child_policy.on_up(*args, **kwargs)

0 commit comments

Comments
 (0)