pkg/planner, pkg/sessionctx: add delete-by-key support for instance plan cache#67495
pkg/planner, pkg/sessionctx: add delete-by-key support for instance plan cache#67495winoros wants to merge 2 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds an exact-key eviction API to the instance plan cache: Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.4)level=error msg="Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: context deadline exceeded" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Skipping CI for Draft Pull Request. |
|
@winoros I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details. ⏳ This process typically takes 10-30 minutes depending on the complexity of the changes. ℹ️ Learn more details on Pantheon AI. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/planner/core/plan_cache_instance.go (1)
42-50: Document the sentinel and deleted-head invariant.
deletedInstancePCNodeandinstancePCNode.deletedcarry most of the concurrency contract here, but the file never explains why a deleted bucket is different from an empty bucket or why traversals must stop on this exact pointer. A short comment on those invariants would make theDelete/Get/Putinteraction much easier to maintain.As per coding guidelines, "Comments SHOULD explain non-obvious intent, constraints, invariants, concurrency guarantees, SQL/compatibility contracts, or important performance trade-offs, and SHOULD NOT restate what the code already makes clear."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/planner/core/plan_cache_instance.go` around lines 42 - 50, Add a concise comment above the instancePCNode type and the deletedInstancePCNode sentinel that documents the concurrency invariant: explain that deletedInstancePCNode is a unique sentinel (not a nil/empty bucket) used to mark a removed bucket, that instancePCNode.deleted is set to true for nodes that have been logically removed, and that traversals in Delete, Get, and Put must stop when they encounter the exact deletedInstancePCNode pointer (not merely a node with deleted==true) to avoid ABA/race conditions; also note any ordering/visibility expectations (e.g., deleted is set before pointer swaps) and the rationale why deleted vs empty buckets are treated differently for correctness of concurrent traversal and insertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/planner/core/plan_cache_instance.go`:
- Around line 153-170: Delete currently detaches nodes and immediately
decrements pc.totCost/pc.totPlan which races with Put's publish/accounting;
instead, detach the list as you do with
headNode.next.Swap(deletedInstancePCNode) but defer subtracting each node's
MemoryUsage()/count until that node has completed the Put publish/accounting
boundary (detectable via the node's published/ready flag used by Put or by
waiting until the same atomic the Put sets when it finishes accounting).
Concretely: in instancePlanCache.Delete, after firstNode :=
headNode.next.Swap(...), iterate the list but only call pc.totCost.Sub(...) and
pc.totPlan.Sub(1) for nodes whose published flag/atomic is observed true (or
otherwise block/queue the subtraction until the node's publish flag is set);
reference deletedInstancePCNode, headNode.next, pc.totCost and pc.totPlan and
the publish/accounting flag used by Put to synchronize the decrement.
---
Nitpick comments:
In `@pkg/planner/core/plan_cache_instance.go`:
- Around line 42-50: Add a concise comment above the instancePCNode type and the
deletedInstancePCNode sentinel that documents the concurrency invariant: explain
that deletedInstancePCNode is a unique sentinel (not a nil/empty bucket) used to
mark a removed bucket, that instancePCNode.deleted is set to true for nodes that
have been logically removed, and that traversals in Delete, Get, and Put must
stop when they encounter the exact deletedInstancePCNode pointer (not merely a
node with deleted==true) to avoid ABA/race conditions; also note any
ordering/visibility expectations (e.g., deleted is set before pointer swaps) and
the rationale why deleted vs empty buckets are treated differently for
correctness of concurrent traversal and insertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 71398b3f-4160-45ba-b7ae-3a322cbe5f16
📒 Files selected for processing (3)
pkg/planner/core/plan_cache_instance.gopkg/planner/core/plan_cache_instance_test.gopkg/sessionctx/context.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #67495 +/- ##
================================================
- Coverage 77.7401% 77.2192% -0.5209%
================================================
Files 1959 1942 -17
Lines 543377 543437 +60
================================================
- Hits 422422 419638 -2784
- Misses 120114 123797 +3683
+ Partials 841 2 -839
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
@coderabbitai The nitpick is addressed in 702d502 as well. I added concise comments documenting the deleted-head / sentinel invariant, the ordering expectation ( |
|
Tip For best results, initiate chat on the files or code changes.
🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
@winoros: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
closed since #67411 use a way to impl. |
What problem does this PR solve?
Issue Number: close #67493
Problem Summary:
The instance plan cache only exposed
Get,Put,All, andEvict(evictAll bool), so callers had no exact-key deletion capability. When an old exact cache key was known, stale instance-cache entries could only be left to logical invalidation or background eviction instead of being reclaimed eagerly.What changed and how does it work?
Delete(key string) (numDeleted int)tosessionctx.InstancePlanCacheinstancePlanCacheGet/Put/ iteration stay consistent with concurrent deletiontotCostandtotPlanimmediately when a key is deletedCheck List
Tests
Unit test commands:
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
New Features
Tests