Repository navigation
docs(cache): correct stale retry-amplification note and pin the circuit-breaker bound - #1619
Conversation
…bound (#1615) The retry.rs coalescing note claimed the N-concurrent-waiters retry amplification was an unbounded, accepted trade-off with "no shared retry-budget implemented". That predates the per-origin circuit-breaker (#963), which already bounds it: after `failure_threshold` consecutive budget-exhaustions the breaker trips OPEN and later waiters short-circuit before the retry loop, so the worst case is a constant number of full budgets per origin per cooldown window, independent of N. A tighter per-hash "share the owner's failure to all waiters" single-flight is deliberately not done: coalesced waiters do not share origin reach (a `populate_local` owner touches local origins only, while a `get` / `populate` waiter has the full chain including the paid `Peer` origin), and re-election is load-bearing there — a local-only owner's NotFound must not short-circuit a full-chain waiter that could still succeed via Peer. - Rewrite the retry.rs module doc to describe the real bound and why the shared-budget variant is unsafe here. - Strengthen the coalescing exhaustion test into `coalesced_owner_exhaustion_bounded_by_circuit_breaker`, now with N_WAITERS (12) > failure_threshold (5) so the breaker must shed load, and pinning both directions: breaker-disabled gives exactly the O(N) worst case, breaker-enabled caps fetches at failure_threshold * budget and strictly below O(N). - Add a `build_engine_with_retry_and_breaker` test helper so the two breaker policies can be compared. Co-Authored-By: Claude Opus 4.8 <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughThe change adds configurable circuit-breaker setup to cache retry tests. It verifies retry amplification with disabled breakers, bounded fetches with default breakers, retry ordering, and ChangesRetry amplification
Estimated code review effort: 3 (Moderate) | ~20 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.32% (was 80.30%, ▲ +0.02%) — 57109/71103 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR corrects stale documentation around cache-miss retry amplification in decdn-cache by documenting the existing per-origin circuit-breaker bound, and updates the integration test suite to lock in that bound (and its breaker-disabled O(N) fallback) as a regression check.
Changes:
- Update
crates/cache/src/retry.rsmodule docs to reflect that retry amplification is bounded by the per-origin circuit-breaker, and document why a per-hash shared-budget approach is intentionally not implemented. - Replace the prior coalescing/retry amplification test with a two-arm test that asserts exact O(N) behavior when the breaker is disabled and a constant bound when the breaker is enabled.
- Add a test helper to build a
CacheEnginewith an explicitCircuitBreakerPolicyso the enabled/disabled behaviors can be compared directly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/cache/src/retry.rs | Updates module documentation to describe the real retry-amplification bound via the per-origin circuit-breaker and the rationale for not sharing failures across origin-reach variants. |
| crates/cache/tests/pull_through.rs | Reworks the coalescing amplification test to pin both the breaker-disabled O(N) behavior and the breaker-enabled constant bound; adds a helper to configure breaker policy in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Issue #1615 flags the retry amplification at
crates/cache/src/retry.rs: N concurrent waiters coalescing on one missing hash can each, in turn, become the owner and run a full retry budget against a down origin — up to N sequential budgets — and the module comment called the shared retry-budget "not implemented" and asked whether the trade-off needs a bound.Finding: it already has one, and the comment was stale. The comment predates the per-origin circuit-breaker (#963,
circuit_breaker.rs). Each budget-exhaustion against a down origin records oneUnavailableoutcome; afterfailure_thresholdconsecutive exhaustions the breaker trips OPEN and every later waiter short-circuits before the retry loop. So the worst case isfailure_thresholdfull budgets per origin per cooldown window — a constant, independent of N — not O(N).The design call (why not a tighter per-hash single-flight)
The triage suggested a
watch/semaphore guard that shares one owner's failure with all waiters so not evenfailure_thresholdbudgets run. That is unsafe here and is why I did not implement it:populate_local(cache: reactive local-origin pull-through is coupled to node_to_node_pull_through_enabled #1116) touches the operator's local origins only;get/populatewalk the full chain including the paidPeerorigin. Both coalesce on the same hash-keyed in-flight map.handlers/client/dispatch.rs— one client can be at thetry_local_populatestage while another reachestry_pull_through), so apopulate_localowner and a full-chain waiter genuinely coalesce.NotFoundmust not short-circuit a full-chain waiter that could still succeed viaPeer. Sharing the owner's failure blindly would turn that into a wrong answer.A correct shared-failure design would have to be origin-reach-aware — real complexity on a hot, cancellation-sensitive path — for a benefit that overlaps almost entirely with what the breaker already sheds. Not worth the risk. A maintainer who disagrees can weigh in, but the safe, honest fix is to make the existing bound explicit and tested.
Changes
retry.rsmodule doc — rewritten to describe the real bound (the cache: CacheEngine has no circuit-breaker for origin pull-through when the origin returns repeated errors, causing every cache-miss to incur full retry backoff even during a sustained origin outage #963 breaker) and to document why the shared-budget variant is deliberately not implemented.tests/pull_through.rs— the oldcoalesced_owner_exhaustion_bounded_by_serial_owner_countusedN_WAITERS == failure_threshold, so the breaker never actually short-circuited a waiter and its assertion only reproved the O(N) worst case (and its comment framed the amplification as an accepted unbounded trade-off, contradicting reality). Replaced withcoalesced_owner_exhaustion_bounded_by_circuit_breaker, which setsN_WAITERS = 12 > failure_threshold = 5and pins both directions:== N * (1 + max_retries)(exactly the O(N) worst case);<= failure_threshold * (1 + max_retries)and strictly< N * (1 + max_retries).This is the assertion that would regress to O(N) if the breaker were ever unwired from pull-through.
build_engine_with_retry_and_breakertest helper so the two breaker policies can be compared.No production behavior changes — this is a documentation correction plus a regression test that locks in the existing (previously only emergent, untested) bound.
Testing
cargo nextest run -p decdn-cache— 324 passed, 0 failed.bounded < O(N)only holds because waiters short-circuit after the threshold; the breaker-disabled arm asserts the exact== O(N)fallback.cargo clippy -p decdn-cache --all-targets— clean;cargo fmt -- --check— clean; pre-commit hooks (fmt, clippy, doc, deny) — passed.Closes #1615
🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
Tests