Skip to content

feat(node): --dry-run preview for decdn node evict (#379) - #398

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/frosty-cannon-d31731
May 5, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/frosty-cannon-d31731

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Mutating evicts append to <cache_dir>/evicted.log with fsync and there's no rollback once that lands, so the cost of a wrong-hash takedown is the cost of finding the right one and re-pulling. Dry-run lets operators answer "is this the right blob and would this even do anything?" without paying that cost.

Notable behaviour

  • inspect() reads BlobStatus directly (not via has()), so the reported size_bytes reflects on-disk state even after a logical evict — operators see the disk-reclaim potential pending the cache: drop double BLAKE3 hash once iroh-blobs exposes verified-insert #233 GC follow-up
  • Plain output uses sentinels (size_bytes=not_stored, last_accessed=never) so an operator can tell "engine has no record" from "record at the floor"
  • EvictResponse.preview is nested rather than flat to keep the bool count under clippy::struct_excessive_bools

Test plan

  • cargo build clean
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo test --workspace (all 217 unit tests pass; the unrelated probe_rate_limit_returns_rate_limited_close_code is flaky under parallel load and passes when run alone)
  • cargo fmt -- --check clean
  • pre-commit run --all-files clean (incl. cargo deny)
  • New cache-level inspect tests (unknown / served / post-evict / pinned)
  • New admin RPC dry-run tests (no-mutation guard + idempotent-rerun reporting)
  • New CLI formatter tests (happy-path field emission + sentinels for absent data)

Closes #379.

🤖 Generated with Claude Code

Operators running DMCA takedowns or corruption-recovery want a
pre-flight check that confirms the right blob and surfaces decision
inputs (size, last-access elapsed time, pin status, already-evicted
flag) before committing to the durable eviction. Mutating evicts have
no easy rollback once `evicted.log` is fsynced, so the cost of a
"oops, wrong hash" is the cost of finding the right one and re-pulling.

Adds:

- `CacheEngine::inspect(hash)` — read-only snapshot returning
  `EvictionPreview { size_bytes, last_accessed_us_ago, pinned,
  already_evicted, served }`. Reads `BlobStatus` directly so the
  reported size reflects the underlying disk state even after a
  logical evict, surfacing the disk-reclaim potential operators care
  about.
- `EvictRequest.dry_run` (+ `serde(default)`) and `EvictResponse.preview`
  (nested `EvictPreview`). Old clients keep parsing the response on
  `was_present` alone; new clients see the snapshot.
- `decdn node evict --dry-run` — multi-line, grep-friendly plain
  output (`size_bytes=…`, `last_accessed=…`, `pinned=…`,
  `already_evicted=…`) plus full JSON via `--json`. Sentinels
  (`size_bytes=not_stored`, `last_accessed=never`) distinguish
  "engine has no record" from "record at the floor".

Tests: cache-level inspect (unknown / served / post-evict / pinned),
admin RPC dry-run no-mutation + idempotent-rerun reporting, CLI
formatter sentinel + happy-path coverage.

Closes #379.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements a dry-run mode for the evict command, allowing operators to preview the impact of an eviction without mutating cache state. It introduces a new inspect method in the CacheEngine to gather metadata such as blob size, last-access time, and pin status. The admin RPC and CLI have been updated to include a --dry-run flag, and new unit tests verify the inspection logic and human-readable output formatting. I have no feedback to provide as there were no review comments to assess.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a dry-run capability for the blob eviction process, allowing operators to preview a hash's local-cache state—including size, last-access time, and pin status—without mutating the cache. The implementation adds an inspect method to the CacheEngine, updates the admin RPC to support a dry_run flag, and provides a human-readable CLI output for the preview. Feedback on the changes suggests optimizing the inspect method by reducing redundant locking overhead to minimize potential lock contention.

Comment thread crates/cache/src/engine.rs Resolved
alpergundogdu and others added 2 commits May 5, 2026 11:43
Document why the three in-memory probes inside `CacheEngine::inspect`
hit independent synchronization primitives and can't be merged into a
single lock acquisition without either coupling unrelated invariants
or holding a coarser lock across the async `BlobStatus` call. Same
pattern already used by `eviction_candidates`.

No code changes — just preempts future reviewers asking the same
question.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Match the wire field on `EvictResponse` so the human-readable line
and the JSON shape use the same key. Asked for during PR review.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant