pub struct StorageWriteJournal {
pub entries: Vec<JournalEntry>,
pub next_sequence: u64,
pub max_entries: usize,
}Expand description
An append-only write journal that records all storage mutations.
The journal enforces a bounded capacity: when the number of stored entries
exceeds max_entries, the oldest entry is evicted. Sequence numbers are
never reused — they continue to increment even after eviction, so consumers
holding a JournalCursor can detect that they have fallen behind.
Fields§
§entries: Vec<JournalEntry>Retained entries, in ascending sequence order. Never reordered.
next_sequence: u64The sequence number that will be assigned to the next appended entry.
max_entries: usizeMaximum number of entries to retain. When exceeded, the oldest entry is dropped.
Implementations§
Source§impl StorageWriteJournal
impl StorageWriteJournal
Sourcepub fn new(max_entries: usize) -> Self
pub fn new(max_entries: usize) -> Self
Creates a new, empty journal with the given capacity limit.
next_sequence is initialised to 1.
Sourcepub fn append(
&mut self,
kind: JournalEntryKind,
cid: &str,
size_bytes: u64,
timestamp_secs: u64,
) -> u64
pub fn append( &mut self, kind: JournalEntryKind, cid: &str, size_bytes: u64, timestamp_secs: u64, ) -> u64
Appends a new entry to the journal.
The checksum is computed as fnv1a(cid.as_bytes()) ^ sequence.
If entries.len() > max_entries after appending, the oldest entry
(index 0) is removed.
Returns the sequence number assigned to the new entry.
Sourcepub fn entries_since<'a>(
&'a self,
cursor: &JournalCursor,
) -> Vec<&'a JournalEntry>
pub fn entries_since<'a>( &'a self, cursor: &JournalCursor, ) -> Vec<&'a JournalEntry>
Returns all entries with sequence > cursor.last_sequence, in order.
Sourcepub fn cursor(&self) -> JournalCursor
pub fn cursor(&self) -> JournalCursor
Returns a cursor pointing at the newest retained entry.
If the journal is empty the cursor’s last_sequence is 0.
Sourcepub fn verify_checksum(&self, entry: &JournalEntry) -> bool
pub fn verify_checksum(&self, entry: &JournalEntry) -> bool
Verifies the checksum of entry.
Returns true when fnv1a(entry.cid.as_bytes()) ^ entry.sequence
equals entry.checksum.
Sourcepub fn stats(&self) -> JournalStats
pub fn stats(&self) -> JournalStats
Returns aggregate statistics for the current journal contents.
Sourcepub fn truncate_before(&mut self, sequence: u64)
pub fn truncate_before(&mut self, sequence: u64)
Removes all entries whose sequence number is strictly less than
sequence.
Auto Trait Implementations§
impl Freeze for StorageWriteJournal
impl RefUnwindSafe for StorageWriteJournal
impl Send for StorageWriteJournal
impl Sync for StorageWriteJournal
impl Unpin for StorageWriteJournal
impl UnsafeUnpin for StorageWriteJournal
impl UnwindSafe for StorageWriteJournal
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more