Skip to main content

GcraStore

Struct GcraStore 

Source
pub struct GcraStore<C = SystemClock> { /* private fields */ }
Expand description

A hard-bounded, process-local generic-cell-rate-algorithm store.

Each key occupies one constant-size entry. The store refuses to evict active entries, performs bounded cleanup per check, and preserves atomic all-or-nothing batches in caller order.

Implementations§

Source§

impl GcraStore<SystemClock>

Source

pub fn new(config: MemoryStoreConfig) -> Self

Creates a store using the system monotonic clock.

Source§

impl<C: Clock> GcraStore<C>

Source

pub fn with_clock(config: MemoryStoreConfig, clock: C) -> Self

Creates a store using a caller-supplied monotonic clock.

Source

pub fn with_observer(self, observer: Arc<dyn Observer>) -> Self

Returns this store with an operational observer.

Source

pub fn check( &self, check: &Check<'_, GcraPolicy>, ) -> Result<Decision, GcraStoreError>

Evaluates and, when allowed, consumes one GCRA check.

§Errors

Fails closed when the target shard is poisoned or exact arithmetic cannot represent the caller-supplied clock value.

Source

pub fn check_all( &self, checks: &[Check<'_, GcraPolicy>], ) -> Result<BatchDecision, GcraStoreError>

Evaluates an atomic batch of GCRA checks.

Allowed decisions preserve input order. A denied or shadow-denied batch consumes no quota.

§Errors

Fails closed for invalid batches, poisoned shards, an unsatisfiable per-shard batch, or arithmetic overflow.

Source

pub fn stats(&self) -> Result<MemoryStoreStats, MemoryStoreError>

Returns current bounded storage use.

§Errors

Returns an error if any shard is poisoned.

Source

pub fn clear(&self) -> Result<(), MemoryStoreError>

Removes every stored counter.

§Errors

Returns an error if any shard is poisoned.

Source

pub fn recover_poisoned(&self) -> usize

Rebuilds poisoned shards by discarding their untrusted counter state.

Trait Implementations§

Source§

impl<C> Debug for GcraStore<C>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Clock> Limiter for GcraStore<C>

Source§

type Policy = GcraPolicy

Policy algorithm supported by this backend.
Source§

type Error = GcraStoreError

Backend-specific operational failure.
Source§

fn check( &self, check: &Check<'_, Self::Policy>, ) -> impl Future<Output = Result<Decision, Self::Error>> + Send

Evaluates and, when allowed, consumes one check.
Source§

fn check_all( &self, checks: &[Check<'_, Self::Policy>], ) -> impl Future<Output = Result<BatchDecision, Self::Error>> + Send

Evaluates a batch atomically. Read more

Auto Trait Implementations§

§

impl<C = SystemClock> !RefUnwindSafe for GcraStore<C>

§

impl<C = SystemClock> !UnwindSafe for GcraStore<C>

§

impl<C> Freeze for GcraStore<C>
where C: Freeze,

§

impl<C> Send for GcraStore<C>
where C: Send,

§

impl<C> Sync for GcraStore<C>
where C: Sync,

§

impl<C> Unpin for GcraStore<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for GcraStore<C>
where C: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.