pub struct RedisBreakers<C> { /* private fields */ }Expand description
A BreakerStore in Redis, which the deliverers of every process
sharing it count their failures in, and let one probe through between, as
Mastodon’s Sidekiq processes share their Stoplights.
A breaker is three keys, after the prefix the application gives, for each
destination its CircuitBreaker is kept for:
stoplight:<key>:failures, the failures in a row while it is closed;
stoplight:<key>:recovery_after, when an open breaker turns half-open,
in milliseconds since the epoch; and stoplight:<key>:probe, the lock
the probe through a half-open one holds, for at most the cool-off. Each
lasts a week after it last changed, as Stoplight’s metadata does.
A breaker Redis cannot be asked about lets the delivery through. A probe whose outcome is never recorded — its delivery was dropped mid-way — keeps its lock until the cool-off lapses, and the next delivery probes.
The commands sent are GET, SET (with NX, PX and EX), DEL,
INCRBY, EXPIRE, and EVAL or FCALL as ProbeRelease says.
Implementations§
Source§impl<C> RedisBreakers<C>
impl<C> RedisBreakers<C>
Sourcepub fn new(connection: C, prefix: impl Into<String>) -> Self
pub fn new(connection: C, prefix: impl Into<String>) -> Self
Breakers over connection, every key of which starts with prefix,
separator included: "tenant-a:", or "" for none.
Sourcepub fn release_with(self, release: ProbeRelease) -> Self
pub fn release_with(self, release: ProbeRelease) -> Self
Release probes’ locks as release says.
Source§impl<C> RedisBreakers<C>
impl<C> RedisBreakers<C>
Sourcepub async fn admit(&self, breaker: &CircuitBreaker, key: &str) -> Admission
pub async fn admit(&self, breaker: &CircuitBreaker, key: &str) -> Admission
Light#run’s choice of strategy: closed (green) lets the delivery
through; open (red) holds it until the cool-off has passed; half-open
(yellow) lets it through as the probe if it takes the probe’s lock,
which starts the count of failures again, and holds it otherwise.
Trait Implementations§
Source§impl<C> BreakerStore for RedisBreakers<C>
impl<C> BreakerStore for RedisBreakers<C>
Source§fn admit<'a>(
&'a self,
breaker: &'a CircuitBreaker,
key: &'a str,
) -> BreakerFuture<'a, Admission>
fn admit<'a>( &'a self, breaker: &'a CircuitBreaker, key: &'a str, ) -> BreakerFuture<'a, Admission>
key may be sent, as CircuitBreaker says.
Letting one through as a probe takes the probe, so that no other
delivery is let through until it is given back.Source§fn record<'a>(
&'a self,
breaker: &'a CircuitBreaker,
key: &'a str,
failed: bool,
probe: Option<Probe>,
) -> BreakerFuture<'a, ()>
fn record<'a>( &'a self, breaker: &'a CircuitBreaker, key: &'a str, failed: bool, probe: Option<Probe>, ) -> BreakerFuture<'a, ()>
key that was let through went: as a
probe, when probe is the one BreakerStore::admit took for it,
which closes the breaker or opens it again, and is given back after.Source§impl<C: Clone> Clone for RedisBreakers<C>
impl<C: Clone> Clone for RedisBreakers<C>
Source§fn clone(&self) -> RedisBreakers<C>
fn clone(&self) -> RedisBreakers<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more