Skip to main content

Ring

Struct Ring 

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

A fixed-capacity, fleet-wide append-only log keyed on KIND byte.

V0 is single-process; V1 is SHM-backed. The API is the same.

Implementations§

Source§

impl Ring

Source

pub fn new<T: OrbitTyped>() -> Self

Create the process-local ring declared by T::RING_SPEC for a single-member fleet.

Source

pub fn new_for_fleet<T: OrbitTyped>(fleet_capacity: u16) -> Self

Create the process-local ring declared by T::RING_SPEC with the physical lane count required by fleet_capacity.

Source

pub fn kind(&self) -> u8

The KIND byte this ring carries (equals T::KIND).

Source

pub fn capacity(&self) -> usize

Total slot count — fixed at construction.

Source

pub fn payload_capacity(&self) -> usize

Maximum inline payload bytes for this ring lane.

Source

pub fn spec(&self) -> RingSpec

Source

pub fn head(&self) -> u64

Head of the sole shared lane, or lane zero for a per-node ring.

Source

pub fn lane_count(&self) -> usize

Number of physical writer lanes in this ring.

Source

pub fn lane_head(&self, node_id: NodeId) -> u64

Current head for node_id’s logical lane.

Source

pub fn next_version(&self) -> u64

Allocate one non-zero semantic version shared by every writer lane.

This counter is independent of physical ring positions. Semantic layers can use it when per-node lanes need one deterministic last-write-wins order.

Source

pub fn current_version(&self) -> u64

Last semantic version allocated for this ring.

Source

pub fn write( &self, node_id: NodeId, frame_kind: u8, ver: u64, payload: Bytes, ) -> NetId64

Append a frame. Atomically reserves the next counter, mints the NetId64, and writes the frame into the corresponding slot. Returns the minted id.

frame_kind is the message class byte (V0: pass 0). ver is the version / tick at write time (V0: caller’s choice).

Source

pub fn write_batch( &self, node_id: NodeId, frame_kind: u8, ver: u64, payloads: Vec<Bytes>, ) -> Vec<NetId64>

Append a contiguous batch to one lane and return its consecutive ids.

Per-node and shared-ordered lanes expose the new head only after the whole batch commits. An empty batch is a no-op. A batch larger than the ring is rejected because its first frames could not remain addressable when the method returns.

Source

pub fn read(&self, id: NetId64) -> Option<Frame>

Read the slot that the given NetId64’s counter points at.

Returns:

  • Some(frame) if the slot’s stored id matches the queried id exactly (the slot has not been overwritten by a later writer).
  • None if the slot is empty, has wrapped past, or holds a different id than the one asked for.
Source

pub fn read_head(&self) -> Option<Frame>

Read the most recent frame, regardless of who wrote it. Useful for “what’s the current state?” — ignores counter-by-counter walking.

Source

pub fn read_at(&self, counter: u64) -> Option<Frame>

Read whatever frame currently occupies the slot at counter % capacity, regardless of which counter is stored in it. Used by walking readers that need slot-by-slot access without knowing the writer’s NetId64 ahead of time.

Returns None if the slot is empty.

Source

pub fn reset(&self)

Clear all slots and reset every lane head to zero.

Intended for owner-controlled boot-time cleanup. Do not call while other threads are publishing to this ring.

Trait Implementations§

Source§

impl Debug for Ring

Source§

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

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

impl RingFrameSource for Ring

Source§

fn kind(&self) -> u8

The OrbitTyped::KIND carried by this ring.
Source§

fn head(&self) -> u64

Monotonic visible head. Depending on topology, this counts counters reserved by writers or frames committed by writers.
Source§

fn capacity(&self) -> usize

Fixed slot count for this ring.
Source§

fn read_at(&self, counter: u64) -> Option<Frame>

Read the frame currently occupying counter % capacity.
Source§

fn read_state_at(&self, counter: u64) -> RingRead

Classify the logical counter currently addressed by counter % capacity. Read more

Auto Trait Implementations§

§

impl !Freeze for Ring

§

impl RefUnwindSafe for Ring

§

impl Send for Ring

§

impl Sync for Ring

§

impl Unpin for Ring

§

impl UnsafeUnpin for Ring

§

impl UnwindSafe for Ring

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 = !

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