Skip to content

Commit 83aa5e9

Browse files
committed
feat: add make_query_plan_with_exclusion to HostFilterPolicy and DefaultLoadBalancingPolicy
Both delegate to their child policy's exclusion-aware query plan while preserving their specific filtering/targeting behavior.
1 parent 3dca0c2 commit 83aa5e9

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

cassandra/policies.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,16 @@ def make_query_plan(self, working_keyspace=None, query=None):
972972
if self.predicate(host):
973973
yield host
974974

975+
def make_query_plan_with_exclusion(self, working_keyspace=None, query=None, excluded=()):
976+
if excluded and not isinstance(excluded, set):
977+
excluded = set(excluded)
978+
child_qp = self._child_policy.make_query_plan_with_exclusion(
979+
working_keyspace=working_keyspace, query=query, excluded=excluded
980+
)
981+
for host in child_qp:
982+
if self.predicate(host):
983+
yield host
984+
975985
def check_supported(self):
976986
return self._child_policy.check_supported()
977987

@@ -1626,6 +1636,27 @@ def make_query_plan(self, working_keyspace=None, query=None):
16261636
for h in child.make_query_plan(keyspace, query):
16271637
yield h
16281638

1639+
def make_query_plan_with_exclusion(self, working_keyspace=None, query=None, excluded=()):
1640+
if query and query.keyspace:
1641+
keyspace = query.keyspace
1642+
else:
1643+
keyspace = working_keyspace
1644+
1645+
addr = getattr(query, 'target_host', None) if query else None
1646+
target_host = self._cluster_metadata.get_host(addr)
1647+
1648+
if excluded and not isinstance(excluded, set):
1649+
excluded = set(excluded)
1650+
1651+
child = self._child_policy
1652+
if target_host and target_host.is_up and target_host not in excluded:
1653+
yield target_host
1654+
for h in child.make_query_plan_with_exclusion(keyspace, query, excluded):
1655+
if h != target_host:
1656+
yield h
1657+
else:
1658+
yield from child.make_query_plan_with_exclusion(keyspace, query, excluded)
1659+
16291660

16301661
# TODO for backward compatibility, remove in next major
16311662
class DSELoadBalancingPolicy(DefaultLoadBalancingPolicy):

0 commit comments

Comments
 (0)