Skip to main content

InMemoryReplayGuard

Struct InMemoryReplayGuard 

Source
pub struct InMemoryReplayGuard { /* private fields */ }
Expand description

A bounded, in-process ReplayGuard: an LRU map from id to the digest accepted under it, its retention deadline, and the response it produced.

§Suitable when

One process is the sole consumer for the recipient VID it serves, and losing the record on restart is acceptable — that is, the window in which a replay could arrive is shorter than the process’s uptime, or the transport will not redeliver across a restart.

§Not suitable when

The consumer is replicated. Two replicas behind a load balancer each hold their own map, so the same document accepted by replica A is Fresh at replica B and the consequential effect happens twice — the exact failure item 11 exists to prevent. Replicated deployments MUST back ReplayGuard with a store shared by every replica, which is why the seam is a trait.

Eviction is by capacity as well as by retain_until: a burst of distinct documents can push an older record out before its retention deadline, and a replay arriving after that would be accepted. Size the capacity above the number of distinct documents the widest acceptance window can hold.

Implementations§

Source§

impl InMemoryReplayGuard

Source

pub fn new(capacity: usize) -> InMemoryReplayGuard

A guard retaining at most capacity records.

§Panics

If capacity is zero. A guard that retains nothing answers Fresh to every arrival, which is indistinguishable from having no guard at all — and would be a silent, total defeat of item 11 rather than a visible misconfiguration.

Source

pub fn len(&self) -> usize

Number of records currently retained. Exposed for tests and metrics.

Source

pub fn is_empty(&self) -> bool

Whether the guard is currently retaining nothing.

Source

pub fn purge_expired(&self, now: DateTime<Utc>)

Drop every record whose retain_until has passed.

claim already treats an individual expired record as absent, so calling this is an optimisation (it reclaims memory) rather than a correctness requirement.

Trait Implementations§

Source§

impl Default for InMemoryReplayGuard

Source§

fn default() -> InMemoryReplayGuard

10 000 records — a few megabytes at typical document sizes, and enough to cover a five-minute acceptance window at ~33 documents per second.

Source§

impl ReplayGuard for InMemoryReplayGuard

Source§

fn claim<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, digest: &'life2 DocumentDigest, retain_until: Option<DateTime<Utc>>, now: DateTime<Utc>, ) -> Pin<Box<dyn Future<Output = Result<ReplayVerdict, ReplayGuardError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, InMemoryReplayGuard: 'async_trait,

Claim id for execution on behalf of a document with content identity digest. Read more
Source§

fn record_response<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, response: Option<&'life2 Value>, ) -> Pin<Box<dyn Future<Output = Result<(), ReplayGuardError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, InMemoryReplayGuard: 'async_trait,

Attach the response a completed execution produced, so a later duplicate can be answered with it per SPEC §7.2 (Disposition of a duplicate) rather than merely absorbed in silence. Read more
Source§

fn release<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, digest: &'life2 DocumentDigest, ) -> Pin<Box<dyn Future<Output = Result<(), ReplayGuardError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, InMemoryReplayGuard: 'async_trait,

Release a claim whose execution never began — for example because a check after the claim refused the document. Read more

Auto Trait Implementations§

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> At for T

Source§

fn at<M>(self, metadata: M) -> Meta<T, M>

Wraps self inside a Meta<Self, M> using the given metadata. 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> BorrowStripped for T

Source§

fn stripped(&self) -> &Stripped<T>

Source§

impl<T> BorrowUnordered for T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Clear for T

Source§

fn clear(&mut self)

Completely overwrites this value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

Source§

impl<T> InitializableFromZeroed for T
where T: Default,

Source§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ResourceProvider<()> for T

Source§

fn get_resource(&self) -> &()

Returns a reference to the resource of type T.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T

Source§

type Owned = T

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, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = !

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

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.
Source§

impl<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more