Skip to content

fix(cache): seed eviction recency from the on-disk store at open - #2261

Merged
thiras merged 3 commits into
mainfrom
fix/2221-seed-eviction-recency-at-open
Oct 1, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2221-seed-eviction-recency-at-open

Conversation

@yigitdot

@yigitdot yigitdot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • eviction_candidates reads only access_times, which open left empty and only traffic filled. After a restart, blobs already on disk were never candidates: eviction released only the working set it had just served, starved above target (evictions_starved ~1/s on lon1), and on fra1 deleted a blob mid-delivery.
  • open now seeds access_times from iter_hashes (the same walk the DHT cold-start seed uses) at one instant (COLD_SEED_AGE = 1 s before open) older than any post-open access, so unaccessed pre-restart blobs rank first under LRU and first among equal frequency under TinyLFU. Pin / probe-hold / deny filtering in eviction_candidates is unchanged; operator-evicted hashes stay out because iter_hashes skips refused hashes.
  • A failed walk logs a WARN, increments the new decdn_cache_recency_seed_failures_total counter, and leaves the map unseeded; open still succeeds. A dedicated counter is needed because evictions_starved fires only once the cache is over high water, and not at all if post-open traffic supplies candidates. A successful seed logs the seeded count at INFO.
  • Seeded entries are not real accesses: last_accessed and the evict dry-run preview report none for them. The CLI dry-run prints last_accessed=none_since_start (was never), since a blob hot before a restart also has no record.
  • deliver and serve_leg call the new CacheEngine::touch_recency (recency only, no frequency sighting) when a serve starts, so a seeded blob does not rank oldest while it streams. The in-flight session guard below remains the full fix.
  • Seeded blobs share one instant, so LRU and TinyLFU break equal recency largest first, reaching the target in fewer releases.
  • Docs that described recency as empty at open are corrected: ADR 040, EvictPreview / EvictionPreview, the sweep and evictions_starved docs, two DHT-seed comments, and several engine docs.
  • Follow-up, not in this PR: exclude blobs with an in-flight fill/serve session from eviction candidates (second guard proposed in the issue comment). Pre-existing ADR 040 inaccuracies found during review are in docs(cache): ADR 040 and policy docs misstate segment re-observation and deny filtering #2267.

Test plan

  • a_blob_on_disk_before_open_is_an_eviction_candidate: candidate after reopen with no touch, and releasable via release_for_eviction (fails without the seed)
  • a_touched_blob_ranks_after_an_untouched_pre_open_blob: also asserts LruEviction releases the untouched blob first (fails without the seed)
  • a_seeded_blob_reports_no_last_access, a_pinned_pre_open_blob_is_not_a_candidate, an_evicted_pre_open_blob_is_not_seeded
  • restarted_over_limit_cache_evicts_without_traffic (node driver): first tick after a restart evicts, evictions_starved stays 0 (fails without the seed)
  • tinylfu_ranks_a_touched_blob_after_an_untouched_pre_open_blob, a_partial_blob_on_disk_before_open_is_an_eviction_candidate, and size tie-break tests for both policies
  • cargo nextest run -p decdn-cache (488 passed); full decdn-node (1508 passed); decdn-cli node/dry-run (152 passed); client public-API snapshot
  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt -- --check, cargo doc with -D warnings
  • Testnet: decdn_cache_evictions_starved_total stays at 0 on a node restarted above high water with unpinned content; decdn_cache_recency_seed_failures_total stays at 0

Closes #2221

🤖 Generated with Claude Code

eviction_candidates reads only access_times, which open left empty and
only traffic filled. After a restart, blobs already on disk were never
candidates, so eviction starved above target and released only the
working set it had just served.

open now seeds access_times from iter_hashes at one instant older than
any post-open access. A failed walk logs a WARN and leaves the map
unseeded; open still succeeds. last_accessed (and the evict --dry-run
preview) report no access for a seeded entry.

Closes #2221

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 02:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-code-quality

github-code-quality Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 1330a87 in the fix/2221-seed-evicti... branch remains at 87%, unchanged from commit cb83e28 in the main branch.

Show a line coverage summary of the most impacted files.
File main cb83e28 fix/2221-seed-evicti... 1330a87 +/-
crates/node/src/dht/publish.rs 92% 92% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/node/src...s/client/mod.rs 95% 95% 0%
crates/client/s...c/connection.rs 97% 97% 0%
crates/node/src...gin/pull_leg.rs 90% 90% 0%
crates/protocol/src/framing.rs 97% 97% 0%
crates/node/src...ime/eviction.rs 86% 87% +1%
crates/client/src/streamer.rs 91% 92% +1%
crates/cache/sr...licy/tinylfu.rs 99% 100% +1%

Updated October 01, 2026 18:13 UTC

@alpergundogdu

Copy link
Copy Markdown
Contributor

Review: approve with nits

Fixes #2221: every open* constructor goes through the one Inner build, which now seeds recency from the store, so every on-disk blob is an eviction candidate from open. Pins and probe holds stay filtered, the deny-over-pin carve-out still works, and partials are re-touched by an active fill. CI is green.

Findings

  1. Medium: a pre-restart blob that is being served is now the first one evicted. delivery.rs:702 and serve_leg.rs:663 call observe_hit only after StreamEnd. During a long serve after a restart the blob still carries the seed timestamp and ranks oldest, so release_for_eviction can drop its tag and GC can delete the bytes mid-stream. That is the fra1 failure mode, moved onto cold blobs.
    Fix: add a touch_recency(&self, hash) wrapper over record_access (recency only, no frequency hit) and call it when a serve starts in deliver and serve_leg. The in-flight guard deferred in the description is the full fix.

  2. Low: seeded blobs tie on one timestamp and evict in arbitrary order. lru.rs:17 stable-sorts a list built from a HashMap, so ties come out in iteration order and size plays no part.
    Fix: break ties by size, largest first, so fewer releases reach the target.

  3. Low: startup cost. open now waits on a full list() plus one status() per blob, serially, and runtime/mod.rs:1856 walks the store again for the DHT seed.
    Fix: keep the first walk's Vec and let the DHT seed reuse it.

Nits

  • engine.rs:1620: the seed doc says the walk skips quarantined hashes, but quarantine is not persisted, so nothing is quarantined at open. Say "durably evicted hashes stay out".
  • Tests: no TinyLFU variant of a_touched_blob_ranks_after_an_untouched_pre_open_blob, and no check that a partial on disk at open becomes a candidate. Add both.

@alpergundogdu

Copy link
Copy Markdown
Contributor

Decisions on the review findings

  • Mid-serve eviction (finding 1): please fix in this PR: add a recency-only touch_recency(&self, hash) over record_access and call it when deliver and serve_leg start.
  • Tie-break (finding 2): please fix in this PR: break seeded-timestamp ties by size, largest first.
  • Shared boot walk (finding 3): not needed now.
  • Nits (quarantine doc, TinyLFU and partial-at-open tests): please fix in this PR.

A failed store walk at open left eviction blind to pre-restart blobs
with only a WARN to show for it; evictions_starved cannot signal it at
startup. Count it in decdn_cache_recency_seed_failures_total, log the
seeded count on success, and list the failure as a starvation cause.

The evict dry-run prints last_accessed=none_since_start, since a blob
hot before a restart has no access record either. ADR 040 and the
EvictPreview docs no longer describe recency as empty on boot.

Add a driver test that a restarted over-limit cache evicts on its first
tick instead of starving, and a test that operator-evicted blobs stay
out of the seed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y size

A blob still carrying the open-time recency seed ranked oldest while a
serve streamed it, because deliver and serve_leg recorded the access
only at StreamEnd. Add CacheEngine::touch_recency (recency only, no
frequency sighting) and call it when both serve paths start.

Seeded blobs share one instant, so LRU and TinyLFU now break equal
recency largest first, reaching the target in fewer releases.

Add a TinyLFU ranking test for a touched vs untouched pre-open blob, a
test that a partial on disk at open is a releasable candidate, and
tie-break tests for both policies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 2e1a93c into main Oct 1, 2026
30 checks passed
@thiras
thiras deleted the fix/2221-seed-eviction-recency-at-open branch October 1, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache: after a restart, eviction sees only blobs touched since start, so cold content is never evicted

4 participants