forked from apache/cassandra-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
In some scenarios TokenAwarePolicy.make_query_plan can call child.make_query_plan three times.
Let's make sure it is called only once.
python-driver/cassandra/policies.py
Lines 506 to 539 in 2739b29
| def make_query_plan(self, working_keyspace=None, query=None): | |
| keyspace = query.keyspace if query and query.keyspace else working_keyspace | |
| child = self._child_policy | |
| if query is None or query.routing_key is None or keyspace is None: | |
| for host in child.make_query_plan(keyspace, query): | |
| yield host | |
| return | |
| replicas = [] | |
| if self._tablets_routing_v1: | |
| tablet = self._cluster_metadata._tablets.get_tablet_for_key( | |
| keyspace, query.table, self._cluster_metadata.token_map.token_class.from_key(query.routing_key)) | |
| if tablet is not None: | |
| replicas_mapped = set(map(lambda r: r[0], tablet.replicas)) | |
| child_plan = child.make_query_plan(keyspace, query) | |
| replicas = [host for host in child_plan if host.host_id in replicas_mapped] | |
| if not replicas: | |
| replicas = self._cluster_metadata.get_replicas(keyspace, query.routing_key) | |
| if self.shuffle_replicas: | |
| shuffle(replicas) | |
| for replica in replicas: | |
| if replica.is_up and child.distance(replica) in [HostDistance.LOCAL, HostDistance.LOCAL_RACK]: | |
| yield replica | |
| for host in child.make_query_plan(keyspace, query): | |
| # skip if we've already listed this host | |
| if host not in replicas or child.distance(host) == HostDistance.REMOTE: | |
| yield host |
Copilot