Repository navigation
feat(cache): convert LRU eviction + fixNarInfoFileSize to Ent - #1215
Merged
Merged
Conversation
This was referenced May 21, 2026
Owner
Author
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 00:07
64a722f to
98d03dc
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 00:35
08e7741 to
4e5a13c
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 00:35
98d03dc to
453905e
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 03:31
4e5a13c to
0837f5b
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 03:31
453905e to
670f6c8
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 03:45
0837f5b to
d0dcb9a
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 03:45
670f6c8 to
4666bf5
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 03:57
d0dcb9a to
8a0ccdd
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 03:58
4666bf5 to
81acd51
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 04:10
8a0ccdd to
bac66ef
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 04:10
81acd51 to
569579a
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 04:22
bac66ef to
e1f465c
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 04:22
569579a to
6a3ce50
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 04:34
e1f465c to
863819b
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 04:34
6a3ce50 to
25f0f6b
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 04:47
863819b to
50639e1
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 04:47
25f0f6b to
ec0d521
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 04:49
50639e1 to
18dbdaa
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 04:49
ec0d521 to
d1dd3fc
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 05:24
18dbdaa to
d9d2ee9
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 05:24
d1dd3fc to
b57e527
Compare
kalbasit
force-pushed
the
fix-ent-schema-parity-race
branch
from
May 23, 2026 05:28
d9d2ee9 to
c3ee587
Compare
kalbasit
force-pushed
the
feat-cache-lru-eviction-to-ent
branch
from
May 23, 2026 05:28
b57e527 to
30ac78c
Compare
§11.5 last batch: deleteLRURecordsFromDB, calculateCleanupSize, and
fixNarInfoFileSize now run under withEntTransaction. The legacy
sqlc-style executeTransaction/withTransaction wrapping is dropped from
runLRU; results flow back to the caller via closed-over vars so the
store-side deletions happen outside the DB transaction the way they did
before.
Notable preserved invariant:
deleteLRURecordsFromDB now mirrors the legacy GetLeastUsedNarInfos
cumulative-bytes filter in Go. Candidates are fetched LRU-ordered
with the linked nar_file eager-loaded; we then keep the prefix whose
cumulative file_size stays within 2*cleanupSize bytes (saturating on
overflow, always including the first row so we make progress even
when a single nar_file dwarfs the budget). The actual delete loop
walks that prefix and breaks once cleanupSize bytes have been
reclaimed -- so we never over-evict the way a naive Limit(n)
replacement would when nar_file sizes vary widely.
This collapses the legacy N+1 GetNarFileByNarInfoID per-narinfo lookup
into one eager load; the orphaned-nar_file / orphaned-chunk passes
become Not(HasNarInfoNarFiles()) / Not(HasNarFileLinks()) predicates on
NarFile.Delete and Chunk.Delete.
TestCacheBackends/{SQLite,PostgreSQL,MySQL} all green under -race; the
TestRunLRU regression that prompted the original revert is covered.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/cache/cache.go`:
- Around line 5737-5748: The query limits reclamation to the first maxFetchRows
rows (tx.NarInfo.Query()...Limit(maxFetchRows)), which can leave older
reclaimable rows unexamined; change the eviction routine to page through the
full LRU space using keyset pagination: loop fetching batches ordered by
entnarinfo.FieldLastAccessedAt then entnarinfo.FieldID, passing a predicate on
the next query that selects rows with (LastAccessedAt > lastSeen) OR
(LastAccessedAt == lastSeen AND ID > lastID) until no more rows, accumulating
reclaimed size and breaking when cleanupSize/other stop conditions are met;
update the code paths that use maxFetchRows, Order, Limit and the
WithNarInfoNarFiles/WithNarFile fetch to perform repeated batched queries
instead of a single Limit call.
- Around line 6080-6082: The early-return currently checks only
narInfoHashesToRemove and chunkHashesToRemove and skips calling
parallelDeleteFromStores when narURLsToRemove contains entries (so orphaned
NarFile blobs remain); modify the condition around the return to include
narURLsToRemove (i.e., only return when all three collections are empty) or
otherwise ensure parallelDeleteFromStores is invoked whenever narURLsToRemove is
non-empty so orphaned NarFile blobs (from NarFile deletions) are passed to
parallelDeleteFromStores for cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1215 +/- ##
=====================================
Coverage 5.68% 5.68%
=====================================
Files 6 6
Lines 387 387
=====================================
Hits 22 22
Misses 361 361
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3 tasks done
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.
§11.5 last batch: deleteLRURecordsFromDB, calculateCleanupSize, and
fixNarInfoFileSize now run under withEntTransaction. The legacy
sqlc-style executeTransaction/withTransaction wrapping is dropped from
runLRU; results flow back to the caller via closed-over vars so the
store-side deletions happen outside the DB transaction the way they did
before.
Notable preserved invariant:
deleteLRURecordsFromDB now mirrors the legacy GetLeastUsedNarInfos
cumulative-bytes filter in Go. Candidates are fetched LRU-ordered
with the linked nar_file eager-loaded; we then keep the prefix whose
cumulative file_size stays within 2*cleanupSize bytes (saturating on
overflow, always including the first row so we make progress even
when a single nar_file dwarfs the budget). The actual delete loop
walks that prefix and breaks once cleanupSize bytes have been
reclaimed -- so we never over-evict the way a naive Limit(n)
replacement would when nar_file sizes vary widely.
This collapses the legacy N+1 GetNarFileByNarInfoID per-narinfo lookup
into one eager load; the orphaned-nar_file / orphaned-chunk passes
become Not(HasNarInfoNarFiles()) / Not(HasNarFileLinks()) predicates on
NarFile.Delete and Chunk.Delete.
TestCacheBackends/{SQLite,PostgreSQL,MySQL} all green under -race; the
TestRunLRU regression that prompted the original revert is covered.
Co-Authored-By: Claude Opus 4.7 [email protected]