Skip to content

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

Closed

Description

@thiras

Summary

After a restart, the eviction driver can evict only blobs that traffic touched since process start. Blobs already on disk before the restart are never candidates. On a node that restarts near its ceiling, eviction evicts the working set it just served. It never reaches the cold content, cannot get below eviction_target_pct, and increments evictions_starved on every tick.

CacheEngine::eviction_candidates (crates/cache/src/engine.rs:4392) iterates only access_times. That map is created empty in open (engine.rs:1529) and filled only by touch. The driver (crates/node/src/runtime/eviction.rs:194) documents the cold-start case and treats it as "wait for traffic". That remedy works only for content that gets traffic. A blob nobody requests after the restart is never evicted. This is the inverse of LRU: the least-recently-used blobs are exactly the ones eviction cannot see.

Evidence (testnet lon1, 2026-09-28)

  • lon1 restarted at 11:15:36 UTC (operator restart). cache_size_mb = 32768, so the limit is 34.36 GB, high water 90 % (30.9 GB) and target 80 % (27.5 GB).
  • decdn_cache_bytes reached 33.2 GB at 11:22, crossed high water, and latched eviction.
  • Three evictions freed 5.57 GB (decdn_cache_evictions_bytes_total) and moved the cache to 30.6 GB and then 30.2 GB. After that the candidate set was empty.
  • decdn_cache_evictions_starved_total has grown ~600 per 10 min (~1 per second) since 11:41, and it is still growing. The cache stays at 30.2 GB, above the 27.5 GB target.
  • By construction, the three evicted blobs were touched after the restart (lon1 served the mistral bundle at 11:16–11:45). Every other blob on disk is untouched, pinned or probe-held. lon1 pins nothing, and probe holds last seconds, so the ~30 GB that remains is untouched pre-restart content.

Proposed fix

Seed access_times at open from the on-disk blob list. iter_hashes already does this walk for the DHT cold-start seed. Give every seeded entry one "older than anything touched" instant, for example the open instant minus a fixed offset. Pre-restart blobs then rank behind everything served since the restart, which restores LRU order. After that change, a starved counter means real pin/hold pressure, not an unseeded map.

Acceptance

  • A unit test: a blob imported before open is an eviction candidate after reopen, with no touch.
  • A unit test: after reopen, a touched blob ranks after an untouched pre-existing blob.
  • On testnet, evictions_starved stays at 0 on a node that restarts above high water with unpinned content.

Activity

  1. self-assigned this
    on Sep 28, 2026
  2. added
    kind:bug
    on Sep 28, 2026
  3. removed their assignment
    on Sep 28, 2026
  4. thiras commented on Sep 29, 2026

    @thiras
    ContributorAuthor

    Live evidence: eviction deletes content the node is still delivering (fra1, 2026-09-29)

    This issue does more than keep the cache over target. After a restart, the only eviction candidates are the blobs that traffic is using right now, so the node releases content mid-delivery. The node then loses bytes it paid for, and a client stream fails.

    Setup. Ansible restarted the fleet at 05:41–05:44 UTC. fra1 came back at 31.4 GB with a 34.4 GB limit. From 05:44:30, decdn_cache_evictions_starved_total grew by one per second. The mistral bundle pull started at 05:48:41 (hash 9194000d…, 74e2cd42 CLI).

    Timeline (fra1).

    • 05:48:30–05:49:00: decdn_cache_evictions_total 0 → 2 and decdn_cache_evictions_bytes_total 0 → 2.60 GB. By 05:49:30 the count is 8.
    • 05:49:15–05:49:30: decdn_cache_gc_runs_total 0 → 1. decdn_cache_bytes drops from 31.4 to 28.8 GB.
    • 05:49:23.6: the client opens 7cbb4846… [518438912, +2277376) on fra1. fra1 does not hold the range, so it pulls the range from bcl (serve-miss).
    • bcl side, trace 7476d0a5baee39ac70ec0b48f74f01fb: serve_stream outcome=completed, bytes=2287680, 1385 ms.
    • fra1 side, trace b0e71c846b2f0604efe05cb472a3e4ba, 05:49:25.248: node-origin: a clean leg advanced neither the paid nor the delivered frontier with paid_frontier = delivered_frontier = 518438912 and paid_wire = 2287680. That is the whole leg, paid, and none of it kept. Next come every covering candidate faulted, coherent range encode faulted and a failed client stream.
    • A later decdn probe of fra1 shows has_blob: false for both 7cbb4846… and b32596…. fra1 served b32596… in the 00:21 run the same day.

    Reading. The LegNoProgress doc says a full paid_wire "points at the store (it did not keep what was paid for)". The release and the GC bracket the leg. The only candidates the driver could see were the blobs this pull had touched since the restart. So the driver evicted the working set while a paid upstream leg was writing into it.

    Cost of the bug.

    • The node pays its upstream for bytes that it then deletes.
    • A client stream fails, and the client must fail over.
    • The node drops a blob that it just advertised in a probe answer.

    The fix proposed above (seed access_times at open with a "colder than anything touched" instant) removes the cause. A second guard is also worth adding: a blob with an in-flight fill or serve session should not be an eviction candidate at all, at any cache state.

  5. self-assigned this
    on Oct 1, 2026
  6. moved this from In progress to Done in deCDNon Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bug

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions