Repository navigation
fix(storage): remove stale positions HashMap from LRU cache - #147
Merged
Merged
Conversation
The positions HashMap introduced in perf/hashmap-lru-touch was fundamentally broken: every pop_front eviction shifts all remaining VecDeque indices by 1, but stored positions were never updated. This caused touch() to index beyond the end of the order deque, panicking all file-backend benchmarks with 'Out of bounds access' at cache.rs:45. Replace with an O(N) iter().position() search in touch(). For the default 256-page cache this is negligible — touch() is only called from put_dirty(), which already holds a write lock. Also add a regression test that reproduces the exact failure sequence: fill cache, evict LRU, then call put_dirty on a still- cached page to trigger touch() on stale indices. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #147 +/- ##
=======================================
Coverage 83.41% 83.41%
=======================================
Files 26 26
Lines 4823 4811 -12
=======================================
- Hits 4023 4013 -10
+ Misses 800 798 -2
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The
positionsHashMap introduced in #146 (perf/hashmap-lru-touch) became stale after every eviction.pop_front()shifts all remaining VecDeque indices by 1, but the stored positions were never updated. On the nexttouch()call fromput_dirty(), the code read the stale (off-by-one) position, popped the real last element, then triedself.order[stale_pos]— which was now past the end of the deque.This caused all file-backend benchmarks to panic immediately:
The in-memory benchmarks weren't affected because they don't exercise the
put_dirty→touchpath in the same way.Fix
Remove the
positionsHashMap entirely. Replace with an O(N)iter().position()scan intouch(). For the default 256-page cache this is negligible —touch()is only called fromput_dirty(), which already holds a write lock.Regression test
Added
test_put_dirty_after_eviction_does_not_panicwhich reproduces the exact failure sequence: fill cache to capacity, trigger an eviction, then callput_dirtyon a still-cached page to exercisetouch()with previously-stale indices.Test plan
cargo test— 793 tests pass, 0 failures🤖 Generated with Claude Code