pub struct CircuitBreakerPolicy {
pub enabled: bool,
pub failure_threshold: u32,
pub cooldown_ms: u64,
pub half_open_max_calls: u32,
}Expand description
Per-origin circuit-breaker policy (#963). Field-level validation
lives at config-resolve time
(crates/common/src/config/mod.rs::resolve_circuit_breaker); this
struct just carries the values.
The breaker fronts each origin’s pull-through retry loop. After
failure_threshold consecutive transient/origin-unavailable
failures it trips OPEN and fast-fails every subsequent miss for
cooldown_ms (no retry/backoff incurred). Once the cooldown elapses
it goes HALF-OPEN and admits up to half_open_max_calls trial pulls;
a trial success closes the breaker, a trial failure re-opens it.
Permanent per-object failures (HTTP 404 → NotFound, other 4xx /
decode / cap breaches → Permanent) deliberately do not count
toward the threshold: a missing object is not an origin outage, and
tripping the breaker on 404s would shed load for content the origin
is perfectly able to serve.
enabled == false (or failure_threshold == 0) disables the breaker
entirely — every miss runs the full retry/backoff loop regardless of
origin health.
Fields§
§enabled: boolMaster switch. false disables the breaker, so every cache miss
runs the full retry/backoff loop. The thresholds below are
ignored while disabled.
failure_threshold: u32Consecutive transient/origin-unavailable failures that trip the
breaker from CLOSED to OPEN. 0 is treated as “disabled” (same
as enabled = false) so an operator can’t accidentally configure
a breaker that trips on the very first blip. Defaults to 5:
high enough to ride out a single flaky request, low enough that a
genuine outage trips within a handful of misses.
cooldown_ms: u64How long the breaker stays OPEN (fast-failing every miss) before
transitioning to HALF-OPEN to probe for recovery, in
milliseconds. Defaults to 30_000 (30s): long enough to shed the
retry-storm during a real outage, short enough that a recovered
origin resumes serving promptly.
half_open_max_calls: u32Maximum number of trial pulls admitted while HALF-OPEN. The first
half_open_max_calls misses after the cooldown are allowed
through (each running its normal retry budget); further misses
fast-fail until a trial resolves. A single trial success closes
the breaker; a single trial failure re-opens it (resetting the
cooldown). Defaults to 1: the standard half-open single-probe
recipe — admit exactly one request to test the waters without
re-flooding a still-sick origin.
Implementations§
Source§impl CircuitBreakerPolicy
impl CircuitBreakerPolicy
Sourcepub const fn disabled() -> CircuitBreakerPolicy
pub const fn disabled() -> CircuitBreakerPolicy
A policy with the breaker disabled — every miss runs the full retry/backoff loop. Useful in tests and for operators who want to opt out.
Trait Implementations§
Source§impl Clone for CircuitBreakerPolicy
impl Clone for CircuitBreakerPolicy
Source§fn clone(&self) -> CircuitBreakerPolicy
fn clone(&self) -> CircuitBreakerPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CircuitBreakerPolicy
Source§impl Debug for CircuitBreakerPolicy
impl Debug for CircuitBreakerPolicy
Source§impl Default for CircuitBreakerPolicy
impl Default for CircuitBreakerPolicy
Source§fn default() -> CircuitBreakerPolicy
fn default() -> CircuitBreakerPolicy
Defaults: breaker on, trips after 5 consecutive
origin-unavailable failures, stays OPEN for 30s, then admits
1 half-open trial. See the field docs for per-knob rationale.
Source§impl<'de> Deserialize<'de> for CircuitBreakerPolicywhere
CircuitBreakerPolicy: Default,
impl<'de> Deserialize<'de> for CircuitBreakerPolicywhere
CircuitBreakerPolicy: Default,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CircuitBreakerPolicy, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CircuitBreakerPolicy, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for CircuitBreakerPolicy
Source§impl PartialEq for CircuitBreakerPolicy
impl PartialEq for CircuitBreakerPolicy
Source§impl Serialize for CircuitBreakerPolicy
impl Serialize for CircuitBreakerPolicy
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for CircuitBreakerPolicy
Auto Trait Implementations§
impl Freeze for CircuitBreakerPolicy
impl RefUnwindSafe for CircuitBreakerPolicy
impl Send for CircuitBreakerPolicy
impl Sync for CircuitBreakerPolicy
impl Unpin for CircuitBreakerPolicy
impl UnsafeUnpin for CircuitBreakerPolicy
impl UnwindSafe for CircuitBreakerPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more