pub struct RingLog { /* private fields */ }Expand description
Append-only circular replay log backed by a real file. Callers
drive append on every host-side publish_slot and replay_all
at cert-time to walk the captured slot stream.
Implementations§
Source§impl RingLog
impl RingLog
Sourcepub fn open(
path: impl AsRef<Path>,
capacity: u64,
) -> Result<Self, ReplayLogError>
pub fn open( path: impl AsRef<Path>, capacity: u64, ) -> Result<Self, ReplayLogError>
Open a log at path, creating + preallocating one with
capacity records if no file exists yet.
§Errors
ReplayLogError::ZeroCapacityifcapacity == 0.ReplayLogError::CapacityOverflowifcapacity > u32::MAX.ReplayLogError::Ioon any syscall failure.ReplayLogError::HeaderMismatchwhen an existing file has the wrong magic or version.
Sourcepub fn capacity(&self) -> u64
pub fn capacity(&self) -> u64
Number of record slots in the log. Records past this capacity wrap and overwrite the oldest entry.
Sourcepub fn append(&mut self, slot: RecordedSlot) -> Result<(), ReplayLogError>
pub fn append(&mut self, slot: RecordedSlot) -> Result<(), ReplayLogError>
Append a record. Overwrites the oldest slot when the log wraps. The cursor is persisted to disk on every append so a crash mid-session does not desynchronise the replay.
§Errors
Propagates ReplayLogError::Io on any file I/O failure.
Sourcepub fn append_with_failure(
&mut self,
slot: RecordedSlot,
failure: ReplayFailureEvidence,
) -> Result<(), ReplayLogError>
pub fn append_with_failure( &mut self, slot: RecordedSlot, failure: ReplayFailureEvidence, ) -> Result<(), ReplayLogError>
Append a record with backend/runtime failure evidence.
§Errors
Propagates ReplayLogError::Io on any file I/O failure.
Sourcepub fn replay_all(&mut self) -> Result<Vec<RecordedSlot>, ReplayLogError>
pub fn replay_all(&mut self) -> Result<Vec<RecordedSlot>, ReplayLogError>
Walk the log in publish order starting at the record
immediately after the current cursor (oldest still-live
record). Stops at the first record whose magic differs from
the crate-private RECORD_MAGIC sentinel - meaning the log
is still before wraparound at that position - unless every record
has been written.
§Errors
Propagates ReplayLogError::Io on read failure.
Sourcepub fn replay_records(&mut self) -> Result<Vec<ReplayRecord>, ReplayLogError>
pub fn replay_records(&mut self) -> Result<Vec<ReplayRecord>, ReplayLogError>
Walk the log in publish order and return full records, including optional failure evidence.
§Errors
Propagates ReplayLogError::Io on read failure.
Sourcepub fn sync(&mut self) -> Result<(), ReplayLogError>
pub fn sync(&mut self) -> Result<(), ReplayLogError>
Flush + sync the file to durable storage. Callers invoke this
when they want the log guaranteed on disk - the hot-path
append does not fsync per-record.
§Errors
Propagates ReplayLogError::Io on fsync failure.