Repository navigation
perf: refresh access LRU recency on gated reads - #210
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Greptile SummaryThis PR refreshes in-memory LRU recency for gated reads while preserving the stored access timestamp. It also adds deterministic capacity-pressure coverage and exposes flush batch counts for benchmark metrics.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking accuracy issue in the newly returned flush count when RocksDB writes fail. The LRU promotion follows the intended single-worker access-tracking model, while Files Needing Attention: storage/access_updater.go Important Files Changed
Reviews (1): Last reviewed commit: "perf: refresh access LRU recency on gate..." | Re-trigger Greptile |
| return 0 | ||
| } | ||
|
|
||
| batchSize := len(a.batch) |
There was a problem hiding this comment.
Flush count includes failed writes
When RocksDB rejects either batch write, flushBatch logs the error, discards the pending updates, and still returns the pre-write batch size. The new Flush result therefore counts entries that were not persisted, making callers and benchmark metrics report work that did not occur.
Knowledge Base Used: Storage Lifecycle: Compaction, Eviction, and Deletion
ovaistariq
left a comment
There was a problem hiding this comment.
Reviewed against source (gate semantics, LRU construction, delay/bucket constants, all Flush callers). Approve.
Core fix (Peek → Get) is correct
The gate LRU's stored value is the last-persisted access time (Add happens on persist inside timeGateUpdate), and its recency should track read traffic. With Peek, a hot key that's read constantly-but-always-gated looks idle, gets evicted from the gate under capacity pressure, and its next read is a miss → a spurious full access-index rewrite (1 point read + 3 key writes per readmission, per flushBatch). Get fixes exactly that with nothing else changing:
Getdoesn't mutate the stored value → the 5-min persist gate (DefaultAccessUpdateDelay) is preserved bit-for-bit.- Single caller goroutine (
run) + lru v2's internal locking → no concurrency concern. - The one real tradeoff: the old code accidentally re-persisted hot keys more often under gate pressure; now hot-key persisted staleness is bounded by the 5-min delay. Eviction buckets are 1-hour (
AccessBucketFormat = "2006010215"), so a ≤5-min skew is immaterial to eviction order — within the design contract.
Impact bound
Prod gate capacity = DefaultAccessUpdateBufferSize = 100k keys, so the bug only bites when >100k distinct keys are read within the delay window (high-cardinality small-object reads). Real fix, small blast radius, essentially free — and the PR body is upfront that the benchmark is a guardrail, not a production model.
Plumbing (Flush() → int)
Handshake checks out: the unbuffered send succeeds only when run commits to the flush branch, the caller then blocks on <-done, run sends the count (the trailing close(doneCh) is redundant-but-harmless), and the shutdown path returns 0. The sole non-test caller (FlushAccessUpdates) legally ignores the return.
Tests
The capacity-2 regression test genuinely discriminates — under the old Peek code the fourth key evicts hot, whose re-read re-enters the batch with a new timestamp and breaks the Equal(firstHotUpdate, …) assertion. b.Loop() is fine on CI's Go 1.24.2.
One minor follow-up (non-blocking)
Agree with the existing Greptile finding: flushBatch captures batchSize before the RocksDB writes and still returns it on a write error (which logs, discards the batch, and drops the updates). The return only feeds tests/benchmark, so it's an observability wart rather than a production bug — but returning 0/actual-written on the error path is a two-liner that would keep the new assertions honest under injected failures. Fine as a follow-up.
|
🎉 This PR is included in version 1.10.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Problem
A gated access-time LRU hit used
Peek, so reads withinAccessUpdateDelaydid not refresh cache recency. Under capacity pressure, a hot key could be evicted from the in-memory gate and then re-enter the update batch on its next read, causing avoidable access-index work.Fix
Use
Getfor the access-time lookup. It preserves the stored timestamp and existing delay gate while promoting every hit. Uncapped storage and FIFO eviction do not use this path.Add a capacity-two regression and an end-to-end
Storage.Getbenchmark that runs the updater worker and access-index flush. The benchmark is a deterministic capacity-pressure guardrail, not a production eviction-rate model.Tests
make test-storage TESTRUN='^TestAccessUpdater_'Workload:
steady-state capacity-two gated Storage.Get access grouphot-key-readmissions/opaccess-index-reads/opaccess-index-key-writes/opGenerated by Perfloop. Human sponsor: Tomas Senart. Measurements and checks.
Note
Low Risk
Localized change to async access-time batching and test-only Flush API; no auth or data-model changes.
Overview
Fixes access-time gating so reads within
AccessUpdateDelaystill count as LRU hits.timeGateUpdatenow usesGetinstead ofPeekon the in-memory access-time cache, promoting hot keys without changing the delay gate or re-batching stale timestamps.Flushnow returns how many distinct updates were written; external flush requests pass that count back through the flush channel. Tests assert the flush count, and new coverage includes a capacity-two LRU recency regression plus an end-to-endStorage.Getbenchmark under capacity pressure.Reviewed by Cursor Bugbot for commit fdced87. Bugbot is set up for automated code reviews on this repo. Configure here.