Skip to main content

SlotTable

Struct SlotTable 

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

Mutable collection of ReplicaSlots. Slots are addressed by id; duplicate insertion upserts (newer state wins). Replica counts in realistic deployments are small (< 16); a linear Vec is faster than a HashMap at this size and avoids the cost of the hasher the rest of the workspace uses.

Implementations§

Source§

impl SlotTable

Source

pub fn new() -> Self

A fresh empty table.

Source

pub fn len(&self) -> usize

Number of slots currently tracked.

Source

pub fn is_empty(&self) -> bool

Whether the table has no slots.

Source

pub fn get(&self, id: &str) -> Option<&ReplicaSlot>

Look up a slot by id.

Source

pub fn iter(&self) -> impl Iterator<Item = &ReplicaSlot>

Iterate over all slots.

Source

pub fn insert_or_touch(&mut self, id: &str, acked_offset: u64, now_ns: u64)

Insert a new slot or update an existing one. Touching always refreshes last_seen_ns and advances acked_offset if the new value is higher (a slot’s acked offset is monotonic — a peer reporting a lower offset than we already recorded is almost always a bug; the silent max() here defends the invariant).

Source

pub fn remove(&mut self, id: &str) -> bool

Remove the slot with the given id. Returns true if a slot was actually removed.

Source

pub fn expire(&mut self, now_ns: u64, window_ns: u64) -> Vec<String>

Drop slots whose last_seen_ns + window_ns ≤ now_ns. Returns the ids of the dropped slots so callers can fire metrics or log lines. Order is unspecified (swap-remove internally).

Source

pub fn min_acked_offset(&self) -> Option<u64>

Lowest acked offset across all tracked slots. Useful for the streaming loop to know how far back the backlog must still retain frames; None when the table is empty.

Trait Implementations§

Source§

impl Debug for SlotTable

Source§

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

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

impl Default for SlotTable

Source§

fn default() -> SlotTable

Returns the “default value” for a type. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.