Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call child.make_query_plan in TokenAwarePolicy.make_query_plan only once #358

Open
dkropachev opened this issue Aug 5, 2024 · 0 comments

Comments

@dkropachev
Copy link
Collaborator

In some scenarios TokenAwarePolicy.make_query_plan can call child.make_query_plan three times.
Let's make sure it is called only once.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant