Skip to content

Conversation

Copy link

Copilot AI commented Dec 27, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>Call child.make_query_plan in TokenAwarePolicy.make_query_plan only once</issue_title>
<issue_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.

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

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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

Successfully merging this pull request may close these issues.

Call child.make_query_plan in TokenAwarePolicy.make_query_plan only once

2 participants