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
impl SlotTable
Sourcepub fn get(&self, id: &str) -> Option<&ReplicaSlot>
pub fn get(&self, id: &str) -> Option<&ReplicaSlot>
Look up a slot by id.
Sourcepub fn iter(&self) -> impl Iterator<Item = &ReplicaSlot>
pub fn iter(&self) -> impl Iterator<Item = &ReplicaSlot>
Iterate over all slots.
Sourcepub fn insert_or_touch(&mut self, id: &str, acked_offset: u64, now_ns: u64)
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).
Sourcepub fn remove(&mut self, id: &str) -> bool
pub fn remove(&mut self, id: &str) -> bool
Remove the slot with the given id. Returns true if a slot
was actually removed.
Sourcepub fn expire(&mut self, now_ns: u64, window_ns: u64) -> Vec<String>
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).
Sourcepub fn min_acked_offset(&self) -> Option<u64>
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.