-
Notifications
You must be signed in to change notification settings - Fork 49
Fix TokenAwarePolicy to call child.make_query_plan once #634
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
base: master
Are you sure you want to change the base?
Conversation
|
@copilot please complete the work on this PR. |
Co-authored-by: mykaul <[email protected]>
Completed! The optimization ensures Summary of changes:
|
| keyspace = 'keyspace' | ||
| routing_key = 'routing_key' | ||
| query = Statement(routing_key=routing_key, keyspace=keyspace) | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
| # Test case 2: Without routing key (should call once) | ||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=None, keyspace=keyspace) | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
| # Test case 3: Without keyspace (should call once) | ||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=routing_key, keyspace=None) | ||
| qplan = list(policy.make_query_plan(None, query)) |
|
|
||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=routing_key, keyspace=keyspace, table='test_table') | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
|
@copilot address review comments from your friendly AI codeQL above. |
Co-authored-by: mykaul <[email protected]>
Co-authored-by: mykaul <[email protected]>
Addressed the memory usage concern from the code review. See commits ec8203e and 85c6ee8. Changes made:
All 83 tests pass and no security issues detected. |
Pre-review checklist
./docs/source/.Description
Optimizes
TokenAwarePolicy.make_query_planto callchild.make_query_planonly once instead of up to 3 times in some scenarios, improving performance by eliminating redundant query plan generation while preserving memory efficiency through lazy evaluation.Problem
In the original implementation,
TokenAwarePolicy.make_query_plancould callchild.make_query_planup to three times:This redundant computation was unnecessary and could impact performance, especially with complex child policies.
Changes Made
cassandra/policies.py
TokenAwarePolicy.make_query_planto callchild.make_query_planonly oncechild.make_query_planonce and convert to list for reuse (needed for replica identification and yielding remaining hosts)tests/unit/test_policies.py
test_child_make_query_plan_called_oncethat validates the optimization works in all scenarios:_assert_shuffleto expect one call for both tablet and vnode scenariosPerformance & Memory Impact
child.make_query_planin worst-case scenarioschild.make_query_planTesting
tests/unit/test_policies.pypassOriginal prompt
💡 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.