From e9c99508cc3a5d3419f6050d0ea83443bf853b33 Mon Sep 17 00:00:00 2001 From: Jim Witschey Date: Wed, 7 Jun 2017 15:36:52 -0400 Subject: [PATCH] add blacklist example to HFPolicy docs --- cassandra/policies.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cassandra/policies.py b/cassandra/policies.py index 418055ba..789092b0 100644 --- a/cassandra/policies.py +++ b/cassandra/policies.py @@ -466,6 +466,29 @@ class HostFilterPolicy(LoadBalancingPolicy): This policy defers to the child policy for hosts where ``predicate(host)`` is truthy. Hosts for which ``predicate(host)`` is falsey will be considered :attr:`.IGNORED`, and will not be used in a query plan. + + This can be used in the cases where you need a whitelist or blacklist + policy, e.g. to prepare for decommissioning nodes or for testing: + + .. code-block:: python + + def address_is_ignored(host): + return host.address not in [ignored_address0, ignored_address1] + + blacklist_filter_policy = HostFilterPolicy( + child_policy=RoundRobinPolicy(), + predicate=address_is_ignored + ) + + cluster = Cluster( + primary_host, + load_balancing_policy=blacklist_filter_policy, + ) + + Please note that whitelist and blacklist policies are not recommended for + general, day-to-day use. You probably want something like + :class:`.DCAwareRoundRobinPolicy`, which prefers a local DC but has + fallbacks, over a brute-force method like whitelisting or blacklisting. """ _predicate = None