Repository navigation
feat(cache): ordered multi-origin fallback chain (#284) - #564
Conversation
Adds `[[cache.origins]]` array-of-tables TOML form (mutually exclusive with the existing `[cache.origin]` singular form) so operators can configure an ordered list of HTTP / filesystem / S3 backends with automatic fallback. The chain advances to the next entry on `NotFound`, permanent error, or per-origin retry-budget exhaustion; deterministic backend misbehaviour (`HashMismatch`, `BlobTooLarge`, local `Store` errors) short-circuits rather than falling through, so a bad backend gets diagnosed instead of silently fronted by its peers. Both wire forms collapse to a canonical `ResolvedCache.origins: Vec<ResolvedOrigin>` in the resolver (singular → 1-element vec, absent → empty vec ⇒ `NoOrigin`), eliminating an either-one-or-many branch through wiring. All-NotFound surfaces `CacheError::NotFound` (=> 404); any in-chain failure surfaces `CacheError::OriginError` carrying the last origin's error (=> 5xx with operator-actionable detail). Permanent / retry-exhausted advances emit `tracing::warn!` so a degraded primary doesn't hide behind a healthy mirror. Breaking public surface: `EvictionPreview.origin_kind: Option<OriginKind>` → `origin_kinds: Vec<OriginKind>`, threaded through admin RPC `EvictPreview` and the CLI `decdn node evict --dry-run` output (now `origin_kinds=http,s3` instead of `origin_kind=http`). External consumers pinned to the pre-#284 JSON schema will need to update. New `decdn_cache_origin_fallback_total` Prometheus counter distinguishes chain-walk steps from per-origin retries. Fail-fast on any per-origin init failure at `build_cache` time with `cache.origins[i]` threaded into the error context. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Implements ordered multi-origin fallback for cache pull-through (#284). Introduces a [[cache.origins]] array-of-tables TOML form alongside the existing [cache.origin] (mutually exclusive), reshapes CacheEngine to take Vec<Arc<dyn Origin>>, and rewrites pull_through as a chain walk that advances on NotFound/Permanent/retry-exhausted but short-circuits on HashMismatch/BlobTooLarge/Store errors. Adds a decdn_cache_origin_fallback_total counter and migrates EvictionPreview.origin_kind → origin_kinds.
Changes:
- Config: new plural
originsfield, validation for mutual-exclusion and empty-array rejection, per-entry indexed error context, duplicate-warning logging, env-expansion threading TOML path. - Engine:
open*constructors now takeVec<Arc<dyn Origin>>;pull_throughwalks the chain emittinginfo!/warn!and a per-steporigin_fallbackcounter; surfaces last error or all-NotFound. - DTO/CLI/admin:
EvictPreview.origin_kinds: Vec<OriginKind>+ comma-separated CLI rendering; existing call sites and tests updated.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/cache/src/engine.rs | Vec-based origin chain in Inner, chain-walk pull_through, EvictionPreview.origin_kinds; tests migrated. |
| crates/cache/src/metrics.rs | Adds origin_fallback counter doc. |
| crates/cache/src/origin/mod.rs | Doc updates referencing renamed origin_kinds. |
| crates/cache/tests/pull_through.rs | New fallback test suite (10 tests) + signature migrations. |
| crates/cache/tests/s3_origin.rs | Updates for new Vec-based open API. |
| crates/common/src/config/types.rs | Adds origins: Option<Vec<OriginConfig>> with extensive docs. |
| crates/common/src/config/resolved.rs | ResolvedCache.origin → origins: Vec<ResolvedOrigin>. |
| crates/common/src/config/mod.rs | resolve_origins collapse + validation + duplicate warning; env-expansion path threading; 7 new tests. |
| crates/common/src/admin.rs | EvictPreview.origin_kinds: Vec<OriginKind>. |
| crates/cli/src/commands/node.rs | CLI dry-run renders comma-separated origin_kinds; new ordered-rendering test. |
| crates/cli/tests/{config_validate,admin_peers}.rs | API migrations. |
| crates/node/src/runtime/mod.rs | build_cache iterates resolved origins with indexed context; origin_kinds_label. |
| crates/node/src/runtime/reload.rs | Test fixture migration. |
| crates/node/src/admin.rs | Threads new origin_kinds; test updates. |
| crates/node/src/metrics.rs | Registers new origin_fallback metric in tests. |
| crates/node/tests/sighup_signal.rs | Test fixture migration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 88.99% (was 89.00%, ▼ 0.01%) — 14034/15770 lines
History
|
There was a problem hiding this comment.
Code Review
This pull request implements a multi-origin fallback chain (#284), transitioning the cache engine from a single origin backend to an ordered list of backends. The CacheEngine now iterates through configured origins on cache misses, advancing to the next entry upon encountering a NotFound result, a permanent error, or retry budget exhaustion, while ensuring that deterministic failures like hash mismatches correctly surface immediately. The configuration layer was updated to support both singular and plural TOML forms, and new metrics were added to track fallback occurrences. Feedback from the review highlights a potential compilation or formatting issue regarding optional S3 prefixes in identity keys and suggests improving error reporting by preserving diagnostic metadata from primary origin failures rather than only returning the final error in the chain.
…#284) Three test sites had `<expr> as Arc<dyn Origin> as Arc<dyn Origin>` — the inner expression was already a typed `Arc<dyn Origin>`, so the outer cast was a no-op artifact from the bulk rewrite that migrated the `Option<Arc<dyn Origin>>` → `Vec<Arc<dyn Origin>>` test fixtures. Caught by Copilot review on PR #564. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Six focused improvements surfaced by the second-pass /review-pr run on PR #564: - expand_origin's S3 DefaultChain arm hardcoded "cache.origin.credentials.profile" even after the prefix-threading refactor; operators with [[cache.origins]][i].credentials.profile = "${VAR}" now get the correct cache.origins[i].credentials.profile path in expansion errors. (mod.rs:1308) - warn! on error-driven chain advance now carries the underlying error string. Operators triaging the user-visible 5xx see *this origin's* failure mode, not just the chain-final one surfaced via CacheError::OriginError. Addresses the "intermediate errors lost" visibility concern raised in both review passes at the log level while keeping the response-error contract (last-wins) unchanged. - The all-exhausted "impossible" branch previously asserted any_not_found via debug_assert! and silently fell through to NotFound in release. Replaced with a tracing::error! that fires in release too, so a future PullThroughOutcome variant that forgets to set a flag surfaces in production logs rather than fabricating a NotFound for content that might exist. (engine.rs:1303-1325) - Extracted the chain-advance log + counter bump into emit_chain_advance() to keep pull_through's cognitive complexity under the workspace clippy threshold; the helper colocates the WHY of the warn!-vs-info! choice with one named entry point. - LabeledPermanentlyFailingOrigin folded into PermanentlyFailingOrigin via an optional marker (with_marker constructor). The two test stubs were 90% duplicate. - Two comment-rot fixes: metrics.rs module doc said "Eight counters" (now nine after origin_fallback); StubOrigin::kind test-only doc said "non-None value" but the field is Vec<OriginKind> post-rename. cargo fmt + clippy --workspace --all-targets -- -D warnings clean; 797/797 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Implements issue #284 — ordered multi-origin fallback for cache pull-through.
[[cache.origins]]array-of-tables TOML form alongside the existing[cache.origin]singular (mutually exclusive). Setting both, ororigins = [], is rejected at config load.CacheEngine::pull_throughas a chain walk: per-origin retry, then advance onNotFound/Permanent/ Transient-exhausted. Deterministic backend misbehaviour (HashMismatch/BlobTooLarge/Store) short-circuits — surfaces, not masks.CacheError::NotFound(=> 404); any error in chain →CacheError::OriginErrorcarrying the last origin's failure (=> 5xx with operator-actionable detail).tracing::warn!(NotFound advances stay atinfo!) so a degraded primary doesn't hide behind a healthy mirror.decdn_cache_origin_fallback_totalcounter distinguishes chain-walk steps from per-origin retries.OriginAssignmentstill governs network-level redundancy).Breaking surface changes
EvictionPreview.origin_kind: Option<OriginKind>→origin_kinds: Vec<OriginKind>(and the admin RPCEvictPreviewDTO mirrors this). CLIdecdn node evict --dry-runoutput now emitsorigin_kinds=http,s3instead oforigin_kind=http. External consumers pinned to the pre-Add support for a[origins]multi-origin table in config allowing ordered fallback across multiple HTTP or filesystem origin backends #284 JSON schema will need updates.decdn-cachepublicCacheEngine::open*constructors now takeVec<Arc<dyn Origin>>(wasOption<Arc<dyn Origin>>).Test plan
cargo fmt --all -- --checkcleancargo clippy --workspace --all-targets -- -D warningsclean (anti-panic policy respected; nounwrap/expect/panic/indexing_slicingin non-test code)cargo nextest run --workspace⇒ 797/797 passed (+19 new tests vs main: 10 engine fallback tests, 7 config-validation tests, 1 CLI multi-kind rendering test, plus inlineorigin_fetches == 1regression-guard assertions)NotFound, advance onPermanent, advance on Transient-exhausted (assertingfirst.fetches() == 1 + max_retries), short-circuit onHashMismatch/BlobTooLarge(assertingsecond.fetches() == 0), all-NotFound surfacesNotFound, all-error surfacesOriginErrorwith the last origin's marker (verified via distinguishable error strings), 3-origin chain confirmsorigin_fallbackincrements per-step (== 2, not 1), single-origin and empty-origin vecs preserve pre-Add support for a[origins]multi-origin table in config allowing ordered fallback across multiple HTTP or filesystem origin backends #284 behaviourorigins = [], singular → 1-element vec back-compat, absent → empty vec, per-entry error threadscache.origins[i]index, duplicate origins resolve without erroringdecdn_cache_origin_fallback_totalincrements and thetracing::warn!/info!chain-walk log lines fire as expectedReviews run before submission
Five specialized reviewers (code-reviewer, pr-test-analyzer, silent-failure-hunter, comment-analyzer, type-design-analyzer) — every flagged critical and important item addressed in this branch.
🤖 Generated with Claude Code