pub struct TrunkWriter { /* private fields */ }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
impl TrunkWriter
Sourcepub fn publish(&self, track_id: u32, retention: RetentionClass, sample: Sample)
pub fn publish(&self, track_id: u32, retention: RetentionClass, sample: Sample)
Publish one sample for track_id under retention.
Sourcepub fn publish_event(&self, event: TimedEvent, anchor: EventAnchor)
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.
Sourcepub fn set_tracks(&self, tracks: Vec<TrackSpec>)
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.