Fix cache stats race during dimension removal - #22647
Fix cache stats race during dimension removal#22647GovindBalaji-S-Glean wants to merge 1 commit into
Conversation
Cache-removal callbacks and reset() could update a stats tree while removeDimensions() held a stale leaf snapshot, causing the snapshot to be subtracted twice and aggregate size/items to go negative. Use a read/write lock to serialize existing-node updates with tree changes, and cover both interleavings with deterministic tests. Signed-off-by: Govind Balaji S <govind.balaji@glean.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22647 +/- ##
============================================
+ Coverage 71.42% 71.44% +0.01%
+ Complexity 76853 76815 -38
============================================
Files 6148 6148
Lines 358003 358008 +5
Branches 52179 52180 +1
============================================
+ Hits 255718 255788 +70
+ Misses 81972 81867 -105
- Partials 20313 20353 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
DefaultCacheStatsHolder.removeDimensions() takes a snapshot of a cache entry before subtracting its stats from ancestor nodes. If a concurrent cache-removal callback decrements the same entry first, the stale snapshot is subtracted again, causing aggregate counters to become negative and _nodes/stats serialization to fail. Same can happen during reset().
This change serializes dimension removal with counter updates and adds a deterministic regression test for the race. Tests to reproduce are in the PR.
Related Issues
N/A. Plmk if I should open an issue for this.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.