Repository navigation
feat(node): --dry-run preview for decdn node evict (#379) - #398
Conversation
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]>
|
/gemini review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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]>
Summary
--dry-runtodecdn node evict(issue Implement a--dry-runflag fordecdn node evictthat reports what would be evicted (blob size, last-access time, whether it is pinned) without actually removing the blob from the store #379) so operators can preview what an evict would touch — blob size, last-access elapsed time, pin status, and already-evicted flag — before committing the durable takedownCacheEngine::inspect()snapshot through the admin RPC (EvictRequest.dry_run+EvictResponse.preview) and out through the CLI's grep-friendly multi-line plain output (and full JSON via--json)was_presentand the prior real-evict behaviour are unchanged;serde(default)on the new fields keeps older clients parsing the response cleanlyMutating evicts append to
<cache_dir>/evicted.logwithfsyncand 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()readsBlobStatusdirectly (not viahas()), so the reportedsize_bytesreflects 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-upsize_bytes=not_stored,last_accessed=never) so an operator can tell "engine has no record" from "record at the floor"EvictResponse.previewis nested rather than flat to keep the bool count underclippy::struct_excessive_boolsTest plan
cargo buildcleancargo clippy --workspace --all-targets -- -D warningscleancargo test --workspace(all 217 unit tests pass; the unrelatedprobe_rate_limit_returns_rate_limited_close_codeis flaky under parallel load and passes when run alone)cargo fmt -- --checkcleanpre-commit run --all-filesclean (incl.cargo deny)Closes #379.
🤖 Generated with Claude Code