Skip to main content

TrunkWriter

Struct TrunkWriter 

Source
pub struct TrunkWriter { /* private fields */ }
Available on crate feature std only.
Expand description

The write handle for a Trunk’s samples + events ring group. Obtained via Trunk::writer. See One writer per ring group for why this group is exactly these two rings, and SegmentWriter for the sibling handle covering segments + parts.

publish never blocks and never rejects: a full class ring evicts its oldest entry (see the internal per-class log’s push logic) rather than waiting for a reader or erroring, so ingest never stalls because some SampleCursor is slow — the same non-blocking-producer principle as crate::byte_tap::ByteTap::record, for the same reason (a broadcast head-end does not pause live ingest for a lagging analysis tap or a stalled egress peer).

“Never blocks” describes the absence of any wait-for-a-reader code path, not a claim that the underlying Mutex critical section is instant — publish briefly contends the same lock SampleCursor::poll does, a bounded amount of work independent of how far behind any reader is (this is exactly what spikes/trunk-bench measured as the O(N)-in-cursor-count cost, not an unbounded wait).

Implementations§

Source§

impl TrunkWriter

Source

pub fn publish(&self, track_id: u32, retention: RetentionClass, sample: Sample)

Publish one sample for track_id under retention.

Source

pub fn publish_event(&self, event: TimedEvent, anchor: EventAnchor)

Publish one event. Never blocks and never rejects — a full event log evicts its oldest entry exactly like the sample/segment logs. anchor is resolved immediately against whatever segment starts / time anchor this trunk already knows; if it cannot be resolved yet, the entry is stored exactly as given, and resolves later, in place, once SegmentWriter::note_segment_start/SegmentWriter::set_time_anchor supplies what was missing. See The event log.

Source

pub fn set_tracks(&self, tracks: Vec<TrackSpec>)

Replace this program’s track set wholesale — the write side of Trunk::tracks/Trunk::track_generation, and the method crate::ingress::IngestDriver calls to seed a freshly-minted Trunk from SessionEvent::NewProgram’s tracks and to apply a later SessionEvent::TracksChanged.

tracks is taken as the complete replacement set, matching SessionEvent::TracksChanged’s own doc: a PMT (or any container’s track-declaration mechanism) carries the whole elementary-stream list, so this call is idempotent (calling it twice with the same set leaves the trunk’s tracks unchanged in content, only track_generation advances) and immune to delta-ordering bugs — there is no “add track”/“remove track” pair to apply out of order. A caller that wants to know which track changed diffs the previous Trunk::tracks snapshot against this one itself.

Bumps Trunk::track_generation by exactly one and wakes any Trunk::listen registration, the same event_listener::Event::notify fan-out SegmentWriter::publish_segment/SegmentWriter::publish_part already use — see Trunk’s progress field doc for why a track-set change is folded into that same broad wake rather than a new channel.

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.