Skip to content

Commit 4d5d665

Browse files
committed
(improvement) additional improvements to HostFilter and default policy.
DefaultLoadBalancingPolicy: add make_query_plan_with_exclusion - forward exclusions to child policy - preserve target_host preference while skipping excluded hosts HostFilterPolicy: add make_query_plan_with_exclusion - forward exclusions to child policy - filter excluded hosts via predicate in exclusion-aware plans - add isinstance guard to avoid redundant set() conversion when excluded is already a set Also add isinstance guard in DefaultLoadBalancingPolicy.make_query_plan_with_exclusion for consistency. Benchmark (100K queries, 45-node/5-DC topology, Python 3.14, median of 5 runs): Policy | Kops/s | vs master | delta | Mem KB ----------------------------------------------------------------- DCAware | 206 | +94% | | 1.5 RackAware | 172 | +153% | | 2.0 TokenAware(DCAware) | 97 | +439% | | 1.7 TokenAware(RackAware) | 89 | +424% | | 2.2 Default(DCAware) | 132 | +45% | -4% | 1.6 HostFilter(DCAware) | 54 | +2% | -17% | 1.7 This commit primarily adds exclusion-aware interfaces to Default and HostFilter policies. The throughput deltas are within noise; the main benefit is architectural — enabling these policies to participate in the exclusion protocol for composition with TokenAware. Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>
1 parent 93ede64 commit 4d5d665

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

cassandra/policies.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,18 @@ def make_query_plan(self, working_keyspace=None, query=None):
924924
if self.predicate(host):
925925
yield host
926926

927+
def make_query_plan_with_exclusion(
928+
self, working_keyspace=None, query=None, excluded=()
929+
):
930+
if excluded and not isinstance(excluded, set):
931+
excluded = set(excluded)
932+
child_qp = self._child_policy.make_query_plan_with_exclusion(
933+
working_keyspace=working_keyspace, query=query, excluded=excluded
934+
)
935+
for host in child_qp:
936+
if self.predicate(host):
937+
yield host
938+
927939
def check_supported(self):
928940
return self._child_policy.check_supported()
929941

@@ -1641,6 +1653,29 @@ def make_query_plan(self, working_keyspace=None, query=None):
16411653
for h in child.make_query_plan(keyspace, query):
16421654
yield h
16431655

1656+
def make_query_plan_with_exclusion(
1657+
self, working_keyspace=None, query=None, excluded=()
1658+
):
1659+
if query and query.keyspace:
1660+
keyspace = query.keyspace
1661+
else:
1662+
keyspace = working_keyspace
1663+
1664+
addr = getattr(query, "target_host", None) if query else None
1665+
target_host = self._cluster_metadata.get_host(addr)
1666+
1667+
if excluded and not isinstance(excluded, set):
1668+
excluded = set(excluded)
1669+
1670+
child = self._child_policy
1671+
if target_host and target_host.is_up and target_host not in excluded:
1672+
yield target_host
1673+
for h in child.make_query_plan_with_exclusion(keyspace, query, excluded):
1674+
if h != target_host:
1675+
yield h
1676+
else:
1677+
yield from child.make_query_plan_with_exclusion(keyspace, query, excluded)
1678+
16441679

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

0 commit comments

Comments
 (0)