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
impl Ring
Sourcepub fn new<T: OrbitTyped>() -> Self
pub fn new<T: OrbitTyped>() -> Self
Create the process-local ring declared by T::RING_SPEC for a
single-member fleet.
Sourcepub fn new_for_fleet<T: OrbitTyped>(fleet_capacity: u16) -> Self
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.
Sourcepub fn payload_capacity(&self) -> usize
pub fn payload_capacity(&self) -> usize
Maximum inline payload bytes for this ring lane.
pub fn spec(&self) -> RingSpec
Sourcepub fn lane_count(&self) -> usize
pub fn lane_count(&self) -> usize
Number of physical writer lanes in this ring.
Sourcepub fn next_version(&self) -> u64
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.
Sourcepub fn current_version(&self) -> u64
pub fn current_version(&self) -> u64
Last semantic version allocated for this ring.
Sourcepub fn write(
&self,
node_id: NodeId,
frame_kind: u8,
ver: u64,
payload: Bytes,
) -> NetId64
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).
Sourcepub fn write_batch(
&self,
node_id: NodeId,
frame_kind: u8,
ver: u64,
payloads: Vec<Bytes>,
) -> Vec<NetId64>
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.
Sourcepub fn read(&self, id: NetId64) -> Option<Frame>
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).Noneif the slot is empty, has wrapped past, or holds a different id than the one asked for.
Sourcepub fn read_head(&self) -> Option<Frame>
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.
Sourcepub fn read_at(&self, counter: u64) -> Option<Frame>
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.