Skip to content

perf(node,cache): answer per-leaf serve presence from the held watch (#1790 item 3) - #1883

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/1790-item3-serve-leaf-presence
Aug 31, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/1790-item3-serve-leaf-presence

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Item 3 of #1790 (Group C serve-path hot-path audit), landed as its own PR — same per-item cadence as #1879 (item 7, merged) and #1882 (item 5).

Problem

The coherent serve encoder's AwaitingDataReader probed the store for presence on every 16 KiB leaf: present_covers → NodeRangedStore::missing_ranges → CacheEngine::present_ranges, which runs the deny-gate check plus two store-actor hops (status() + observe()) before the leaf's own data read. That's ~3 store round trips per served leaf — ~190 per MiB — so miss-path streaming throughput is bounded by store-actor message rate rather than by disk or upstream bandwidth. The gap widens as upstream bandwidth improves.

The reader already holds a live PresentRangeWatch and awaits it for progress, but it discarded the yielded ranges (.map(|_ranges| ())) and re-probed the store anyway.

Fix

Fold each watch item — the blob's absolute present bitfield — into a local present: ChunkRanges snapshot, and answer per-leaf coverage from it: a ChunkRanges subtraction, no store hop. The watch advances only as the pull fills, so the snapshot grows monotonically and the encoder's forward walk reads each already-landed leaf for free. Presence now costs one watch open per serve (amortized) instead of two store hops per leaf.

Takedown is preserved exactly, not weakened. NodeRangedStore::refuses is a pure in-memory check (lock-free deny/blacklist/evict sets — no store hop), folded into the local coverage test so an evicted/blacklisted hash still reads as not-present, mirroring the guard present_ranges applied. The mid-serve eviction model is unchanged: in-flight readers still drain via the durable-clean-end shortcut (untouched), new serves are still blocked at admission. The authoritative store probe survives only for the rare race where a fill retires between the liveness and outcome reads.

Tests

  • covers_locally_answers_from_snapshot_and_refuses_takedown (new) — empty snapshot covers nothing; a snapshot including the range covers it; an evicted hash reads as not-present with no store hop.
  • partial_overlap_shares_one_fill_and_serves_r_byte_exact (existing) — the park-then-resume coalesced serve, the strongest guard on this path, stays byte-exact.
  • Full decdn-node suite (~780 tests) and cache suite green; clippy/doc/fmt/pre-commit clean.

Remaining #1790 items

Items 1, 2, 4, 6, 8, 9 remain open as separate follow-ups (7 merged, 5 in #1882).

🤖 Generated with Claude Code

…1790 item 3)

The coherent serve encoder probed the store for presence on every 16 KiB leaf:
`present_covers` → `missing_ranges` → `present_ranges` did a deny-gate check plus
two store-actor hops (`status` + `observe`) before each leaf's data read — ~190
store round trips per MiB served on the miss path, bounding pull-through
throughput by store-actor message rate rather than by disk or upstream bandwidth.

The reader already holds a live `PresentRangeWatch` and awaits it for progress,
but discarded its yielded ranges and re-probed the store instead. Fold each watch
item (the blob's absolute present bitfield) into a local `present: ChunkRanges`
snapshot and answer per-leaf coverage from it — a `ChunkRanges` subtraction with
no store hop. The watch advances only as the pull fills, so the snapshot grows
monotonically and the encoder's forward walk reads each landed leaf for free.

Takedown enforcement is preserved exactly, not weakened: `NodeRangedStore::refuses`
is a pure in-memory check (lock-free deny/blacklist/evict sets), folded into the
local coverage test so an evicted/blacklisted hash still reads as not-present —
mirroring the guard `present_ranges` applied, minus the round trip. The
authoritative store probe survives only for the rare race where a fill retires
between the liveness and outcome reads, and the durable-clean-end shortcut is
untouched.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 14:58

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.

Pull request overview

This PR improves miss-path streaming throughput in the node’s coherent serve encoder by eliminating per-leaf store presence probes and instead answering “is this leaf present?” from the already-held PresentRangeWatch snapshot (while still applying the refusal/takedown gate locally).

Changes:

  • Add a local present: ChunkRanges snapshot to AwaitingDataReader and use it to satisfy per-leaf coverage checks without store actor round trips.
  • Keep refusal/takedown semantics in the fast path by checking NodeRangedStore::refuses() alongside the snapshot coverage test.
  • Add a targeted unit test to validate snapshot coverage behavior and refusal gating (eviction) without requiring store presence probes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/node/src/handlers/client/serve_encoder.rs Cache per-hash present-range snapshots from PresentRangeWatch and use them for per-leaf coverage checks; add a unit test for snapshot + refusal behavior.
crates/cache/src/ranged_store.rs Expose NodeRangedStore::refuses() as a cheap in-memory gate so the node serve encoder can fold refusal into local coverage checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.31% (was 80.30%, ▲ +2.01%) — 69479/84407 lines

File Coverage Lines Δ
crates/cache/src/ranged_store.rs 100.00% 140/140 new
crates/node/src/handlers/client/serve_encoder.rs 87.80% 446/508 new
History
Commit Total Δ vs base
059ca5e (HEAD) 82.31% ▲ +2.01%

@alpergundogdu
alpergundogdu merged commit 61dd0c7 into main Aug 31, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/1790-item3-serve-leaf-presence branch August 31, 2026 15:14
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