Skip to content

refactor(cache): move the eviction driver loop from the node into decdn-cache - #2886

Merged
alpergundogdu merged 1 commit into
mainfrom
cache-eviction-loop
Nov 12, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
cache-eviction-loop

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Second step of moving the decdn gateway cache onto decdn-cache (#2881, after #2884). The gateway needs the same eviction loop the node runs, so the loop moves into the cache crate.

What changes

  • crates/node/src/runtime/eviction.rs becomes decdn_cache::eviction_driver. run, EvictionParams (re-exported at the crate root) and the tick, sweep, pending-reclaim and hysteresis logic are unchanged.
  • Two node-only inputs are now injected:
    • free_space: impl FnMut() -> anyhow::Result<u64> replaces the cache_dir path and the direct decdn_common::disk call. decdn-cache gains no dependency on decdn-common.
    • on_release: impl Fn(Hash) replaces the WarmingAllowance argument. It runs once per hash after a successful release.
  • The node passes statvfs_target(cache_dir).avail as the probe and warming.forget as the callback, so its behaviour is the same.
  • sweep_orders_via_injected_policy now also checks that on_release sees exactly the released hash.
  • Two comments written as history are now in present tense.

Tests

  • cargo nextest run -p decdn-cache -p decdn-node: pass. The 17 driver tests now run under decdn-cache.
  • cargo clippy --workspace --all-targets --all-features and -p decdn-cache --no-default-features --all-targets: clean, with warnings denied.
  • cargo doc --workspace --no-deps --document-private-items, check_crate_edges.py, cargo fmt --check: pass.
  • cargo deny check advisories still fails on crypto-bigint (RUSTSEC-2026-0387) and pin-utils (RUSTSEC-2026-0441), the same as main.

🤖 Generated with Claude Code

…dn-cache

The driver is generic over the cache engine, so any binary that owns a
CacheEngine can hold it under its disk-aware ceiling. The caller injects
the free-disk probe and a callback for each released hash; the node
passes its statvfs probe and the ADR 041 warming-allowance forget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 00:55

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟢 Approval recommended

The eviction driver refactor is accompanied by updated node wiring plus adjusted cache tests and documentation to match the new callback-based API, with no remaining issues noted in the review evidence.

No open issues 🎉

What changed in this PR

Moves the cache eviction driver loop from decdn-node into decdn-cache so other binaries (e.g., decdn gateway) can reuse the same eviction behavior without node-only dependencies.

Changes:

  • Introduces decdn_cache::eviction_driver::run and re-exports EvictionParams from the cache crate root.
  • Replaces node-only dependencies with injected callbacks: a free_space probe and an on_release hook.
  • Updates node wiring, cache tests, and documentation to match the new module location and API.
File Description
crates/​node/​src/​runtime/​mod.rs Updates the node runtime to invoke decdn_cache::eviction_driver::run, injecting the free-space probe and warming release callback to preserve existing behavior.
crates/​cache/​src/​lib.rs Exposes the new eviction_driver module publicly and re-exports EvictionParams, updating crate-level docs to reference the new entrypoint.
crates/​cache/​src/​eviction_driver/​tests.rs Adjusts eviction driver tests to the callback-based API and adds/updates assertions around the on_release hook behavior.
crates/​cache/​src/​eviction_driver.rs Moves the eviction driver loop into decdn-cache and refactors the API to accept injected free_space and on_release functions instead of node-specific inputs.
CLAUDE.md Updates project documentation to reflect that the eviction driver loop now lives in decdn-cache and uses injected inputs.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 5dd72da cache-eviction-loop a35f789 +/-
77% 77% 0%
View coverage of the 5 most impacted files.
File main 5dd72da cache-eviction-loop a35f789 +/-
crates/client/src/lib.rs 90% 89% -1%
crates/node/src...s/client/mod.rs 95% 95% 0%
crates/node/src/runtime/mod.rs 28% 28% 0%
crates/protocol/src/framing.rs 92% 93% +1%
crates/cache/sr...ction_driver.rs 0% 63% +63%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

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.

2 participants