Skip to main content

CapacityPubSubRing

Struct CapacityPubSubRing 

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

Runtime-resizable pubsub ring.

Implementations§

Source§

impl CapacityPubSubRing

Source

pub fn create_anon( initial_capacity: usize, ) -> Result<Arc<Self>, PubSubCapacityMorphError>

Anon (in-process) capacity-adaptive pubsub ring.

Source

pub fn create( base_path: impl AsRef<Path>, initial_capacity: usize, ) -> Result<Arc<Self>, PubSubCapacityMorphError>

File-backed capacity-adaptive pubsub ring.

Source

pub fn create_shmfs( name_prefix: &str, initial_capacity: usize, ) -> Result<Arc<Self>, PubSubCapacityMorphError>

ShmFs (named shared memory) capacity-adaptive pubsub ring.

Source

pub fn current_capacity(&self) -> usize

Current capacity of the active backing.

Source

pub fn pin_generation(&self) -> u64

Current pin generation.

Source

pub fn publish(&self, payload: &[u8]) -> u64

Publish a payload to the currently-active backing. Returns the absolute position assigned within that backing (not globally unique across backings - subscribers identify items via payload contents, not position).

The chain lock is held through the inner publish call so a concurrent morph cannot slip in and make this publish land in a backing that just became stale. Subscribers walk the chain oldest-to-newest and only advance forward; if a publish landed in a now-stale backing past where any subscriber had already advanced, those items would be silently lost. Holding the lock through publish prevents that.

Source

pub fn subscribe_from_now(self: &Arc<Self>) -> CapacityPubSubSubscriber

Subscribe to the stream from the CURRENT active backing’s current head. The subscriber drains forward from there, crossing into newly-morphed backings as it catches up. “From now” semantics: late joiners do NOT see history from before they subscribed.

Source

pub fn subscribe_from_oldest(self: &Arc<Self>) -> CapacityPubSubSubscriber

Subscribe starting from the beginning of the OLDEST backing currently in the chain. The subscriber drains every item from every backing oldest-to-newest, crossing chain entries as it catches up. Used when a subscriber needs to replay the full available history.

Source

pub fn morph_capacity_to( &self, new_capacity: usize, ) -> Result<(), PubSubCapacityMorphError>

Morph the active backing’s capacity. Allocates a fresh backing at new_capacity, appends it to the chain, bumps pin_generation, and publishes the new active end. Subscribers reading from older chain entries continue undisturbed; they advance into the new backing individually as their try_next catches up.

Source

pub fn prewarm(&self, capacity: usize) -> Result<(), PubSubCapacityMorphError>

Speculatively build a backing at capacity into the one-slot warm cache, off the morph lock’s critical path. The next morph_capacity_to(capacity) consumes it and skips allocation. Re-prewarming the cached capacity is a no-op; a different capacity replaces the slot.

Source

pub fn warm_capacity(&self) -> Option<usize>

Capacity currently held in the warm cache, if any.

Source

pub fn warm_hits(&self) -> u64

Number of morphs that consumed a warm-cache prediction.

Source

pub fn clear_warm(&self)

Drop any cached prediction, releasing its memory (and its file / shm region for non-anon locales).

Source

pub fn gc(&self) -> usize

Garbage-collect stale backings from the front of the chain. Drops the oldest contiguous run of backings whose strong-count is 1 (only the chain itself holds them; no subscriber is currently reading them). The active backing is never dropped even when it has strong-count 1 - that would lose the producer’s target. Returns the number of stale backings reclaimed.

Source

pub fn ring_handle(&self) -> Arc<PubSubRing>

Direct access to the currently-active PubSubRing.

Source

pub fn chain_len(&self) -> usize

Number of backings currently in the chain (active + any not-yet-gc’d stale entries).

Source

pub fn chain_total_capacity(&self) -> usize

Sum of capacities across every backing currently in the chain. Used by KeepAll-style producers to bound in-flight items to actual buffering room: any item the producer publishes is held in SOME backing until the slowest subscriber catches up; with at most chain_total_capacity() in-flight items, no backing wraps past a subscriber’s position before that subscriber drains it.

Trait Implementations§

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.