Repository navigation
fix(storage): keep nanosecond precision on LRU access-time bumps (#257) - #261
Merged
Merged
Conversation
The access index orders entries by nanosecond and a put records its write time at that precision, but a read bump was queued as whole Unix seconds and rebuilt with time.Unix(sec, 0), i.e. at the START of its second. A key read at hh:mm:ss.8 therefore sorted before every key written at hh:mm:ss.1..ss.7 and was evicted ahead of them. That is the eviction e2e "Protection semantics" flake. The five protecting reads land in the same wall-clock second as the tail of the twenty setup writes whenever the writes are fast, and the failing CI run shows exactly that order: keys 6-9 evicted, then the "protected" 1-3, with 10-20 untouched. PR #230 made the flush deterministic via a graceful restart, but could not fix the timestamp being flushed. The updater now carries time.Time end to end (queue, time-gate LRU, index key), so a bump sorts after everything written before the read. SetAccessTime keeps its Unix-seconds signature for the integration harness. A new unit test pins the ordering and fails on main. Fixes #257 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra Signed-off-by: Ovais Tariq <[email protected]>
Greptile SummaryThis PR fixes LRU eviction ordering by preserving full
Confidence Score: 5/5The PR appears safe to merge and consistently preserves nanosecond ordering across the LRU access-update pipeline. No actionable correctness, security, or repository-rule violations remain; the changed representation matches the existing access-index encoding and production callers. Important Files Changed
Reviews (1): Last reviewed commit: "fix(storage): keep nanosecond precision ..." | Re-trigger Greptile |
singler
approved these changes
Sep 7, 2026
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This was referenced Sep 9, 2026
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.
Fixes #257.
Root cause
The LRU access index sorts entries by nanosecond, and a put records its write time at that precision. A read bump, though, was queued as whole Unix seconds (
time.Now().Unix()) and rebuilt on flush withtime.Unix(sec, 0), i.e. at the start of its second. A key read athh:mm:ss.8therefore sorted before every key written athh:mm:ss.1 … ss.7, and eviction reached it first.The failing CI run on #260 shows exactly that order. Reads of keys 1-5 happened at
04:21:51.81-51.88; keys 10-20 were written at04:21:51.05-51.75. Eviction removed keys 6, 7, 8, 9 (written in second:50), then the "protected" 1, 2, 3, and never touched 10-20. The bumps had been flushed (flushed batch of size 15on the restart) but at51.000.PR #230 made the flush deterministic with a graceful restart. It could not fix the timestamp being flushed, so the flake survived and now fires whenever the twenty setup writes finish within the same wall-clock second as the reads.
Fix
accessUpdatercarriestime.Timeend to end: the queued update, the time-gate LRU, and the index key built influshBatch. A bump now sorts after everything written before the read.Storage.SetAccessTimekeeps its Unix-seconds signature, so the integration harness interface is untouched.No change to eviction, the cleaner, the index key format, or the e2e flow (the restart stays; only a comment was added).
Verification
TestAccessUpdater_ReadBumpOutranksEarlierWritespins the ordering. Run against unfixedmainit fails with the bumped entry at…661000000000and the later write at…661880483000.make test-storage,make test-integration-cleaner,make test-e2e-eviction(LRU: 5/5 read keys survive; FIFO: 0/5, as required),make lintall pass locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01YCoN4Him5ZY4hZovVp37ra
Note
Medium Risk
Changes how read-driven LRU index timestamps are persisted, which directly affects eviction order under disk caps; scope is limited to the async access updater with no index format or cleaner changes.
Overview
Fixes #257 by stopping LRU read recency bumps from being truncated to whole Unix seconds, which could sort a recently read key before keys written later in the same second and evict the “protected” entries first.
accessUpdaternow carriestime.Timethrough queued updates, the time-gate LRU, andflushBatch(viakeys.MakeBucketedAccessKey), so read bumps keep the same nanosecond ordering as writes.UpdateNowusestime.Now()directly; stale gating compares durations withtime.Subinstead ofUnixround-trips.Storage.SetAccessTimestill accepts Unix seconds for tests and converts withtime.Unix(accessTime, 0).Adds
TestAccessUpdater_ReadBumpOutranksEarlierWritesand adjusts existing access-updater tests; the eviction e2e script only documents why nanosecond precision matters for LRU protection.Reviewed by Cursor Bugbot for commit fadd5dc. Bugbot is set up for automated code reviews on this repo. Configure here.