pub struct OriginBreaker { /* private fields */ }Expand description
Per-origin circuit-breaker. One instance fronts each origin’s
pull-through retry loop in crate::CacheEngine.
Cheap to construct and Send + Sync; the engine holds one per origin
in a parallel Vec. A disabled policy (!policy.is_active()) makes
every Self::acquire return Admission::Proceed with an inert
guard whose TrialGuard::record is a no-op, so an opted-out
operator pays nothing but a mutex-free is_active check on the hot
path.
Implementations§
Source§impl OriginBreaker
impl OriginBreaker
Sourcepub fn new(
policy: CircuitBreakerPolicy,
clock: Arc<dyn Clock>,
metrics: Option<Arc<CacheMetrics>>,
) -> Self
pub fn new( policy: CircuitBreakerPolicy, clock: Arc<dyn Clock>, metrics: Option<Arc<CacheMetrics>>, ) -> Self
Construct a breaker for one origin under policy, using clock
for cooldown timekeeping and bumping transition counters on
metrics when present.
Sourcepub fn state(&self) -> BreakerState
pub fn state(&self) -> BreakerState
Current state, for tests and observability. Note this may run the
lazy OPEN→HALF-OPEN cooldown check is not applied here — it
reports the raw stored phase. Use Self::acquire to drive
transitions.
Sourcepub fn acquire(&self) -> Admission<'_>
pub fn acquire(&self) -> Admission<'_>
Decide whether to admit a pull-through attempt for this origin now, applying the lazy OPEN→HALF-OPEN cooldown transition.
Returns Admission::ShortCircuit when the breaker is OPEN
(cooldown not yet elapsed) or HALF-OPEN with no remaining trial
budget — the caller must fast-fail the miss without running the
retry loop. Otherwise returns Admission::Proceed carrying a
TrialGuard; if that admission was a HALF-OPEN trial, the guard
owns the reserved trial slot and MUST be resolved — either by
TrialGuard::record (which drives the transition) or by being
dropped on cancellation (which reclaims the slot). Either way the
slot is never leaked.
A disabled policy always returns Proceed(Closed, _) with an
inert guard.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for OriginBreaker
impl !RefUnwindSafe for OriginBreaker
impl !UnwindSafe for OriginBreaker
impl Send for OriginBreaker
impl Sync for OriginBreaker
impl Unpin for OriginBreaker
impl UnsafeUnpin for OriginBreaker
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> 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