pub struct HintStore { /* private fields */ }Expand description
Node-local hint store.
The store is internally synchronised so std::sync::Arc
clones share the same per-peer queues. Operations are O(1)
with respect to the number of pending hints for the queried
peer and O(N) for HintStore::expire_now.
Implementations§
Source§impl HintStore
impl HintStore
Sourcepub fn new(max_bytes: u64) -> Self
pub fn new(max_bytes: u64) -> Self
Build a new store with the supplied byte cap.
max_bytes of zero means “no cap”; this is intended for
tests that drive enqueue/take patterns and never want to
exercise the back-pressure branch.
Sourcepub fn enqueue(
&self,
peer_idx: u32,
payload: Vec<u8>,
ttl: Duration,
) -> Result<(), HintStoreError>
pub fn enqueue( &self, peer_idx: u32, payload: Vec<u8>, ttl: Duration, ) -> Result<(), HintStoreError>
Append a hint for peer_idx. The hint expires at
Instant::now() + ttl.
§Errors
HintStoreError::ZeroTtlwhenttlis zero.HintStoreError::EmptyPayloadwhenpayloadis empty.HintStoreError::OverCapacitywhen accepting the hint would push the cumulative payload bytes overmax_bytes.
Sourcepub fn take_for(&self, peer_idx: u32) -> Vec<Hint>
pub fn take_for(&self, peer_idx: u32) -> Vec<Hint>
Drain every pending hint for peer_idx. Hints that have
expired are dropped on the floor (and counted toward
HintStoreStats::expired_total).
Returned hints are ordered by enqueue time, oldest first.
Sourcepub fn expire_now(&self, now: Instant) -> usize
pub fn expire_now(&self, now: Instant) -> usize
Drop every hint whose deadline has passed at now.
Returns the number of hints dropped. Walks the entire
store; intended for the periodic drainer task.
Sourcepub fn len_for(&self, peer_idx: u32) -> usize
pub fn len_for(&self, peer_idx: u32) -> usize
Pending hint count for peer_idx. Useful for tests.
Sourcepub fn stats(&self) -> HintStoreStats
pub fn stats(&self) -> HintStoreStats
Snapshot the store’s accounting fields.
Sourcepub fn peers_with_hints(&self) -> Vec<u32>
pub fn peers_with_hints(&self) -> Vec<u32>
Iterate the peer indices that currently have pending hints. Used by the drainer to decide which peers to ship to without holding the inner lock across the network send.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for HintStore
impl !RefUnwindSafe for HintStore
impl Send for HintStore
impl Sync for HintStore
impl Unpin for HintStore
impl UnsafeUnpin for HintStore
impl UnwindSafe for HintStore
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.