pub struct StorageWriteAheadLog { /* private fields */ }Expand description
In-memory write-ahead log for crash-safe block operations.
Unlike WriteAheadLog which is CID-centric and thread-safe via
Mutex/AtomicU64, StorageWriteAheadLog is a single-threaded,
tick-driven WAL that tracks total data bytes and supports indexed
checkpoint replay.
Implementations§
Source§impl StorageWriteAheadLog
impl StorageWriteAheadLog
Sourcepub fn new(config: WalConfig) -> Self
pub fn new(config: WalConfig) -> Self
Creates a new StorageWriteAheadLog with the given configuration.
Sourcepub fn append(
&mut self,
kind: WalEntryKind,
key: &str,
data: Vec<u8>,
) -> Result<u64, String>
pub fn append( &mut self, kind: WalEntryKind, key: &str, data: Vec<u8>, ) -> Result<u64, String>
Appends a new entry to the WAL.
If appending would exceed max_entries, the oldest entry is evicted
first. Returns the assigned sequence number.
§Errors
Returns an error if adding data would exceed max_data_bytes.
Sourcepub fn get_entry(&self, sequence: u64) -> Option<&StorageWalEntry>
pub fn get_entry(&self, sequence: u64) -> Option<&StorageWalEntry>
Returns a reference to the entry with the given sequence number, if present.
Sourcepub fn entries_since(&self, sequence: u64) -> Vec<&StorageWalEntry>
pub fn entries_since(&self, sequence: u64) -> Vec<&StorageWalEntry>
Returns references to all entries with sequence numbers strictly
greater than sequence.
Sourcepub fn create_checkpoint(&mut self) -> u64
pub fn create_checkpoint(&mut self) -> u64
Records the current head sequence as a checkpoint and returns it.
Sourcepub fn truncate_before(&mut self, sequence: u64)
pub fn truncate_before(&mut self, sequence: u64)
Removes all entries with sequence numbers strictly less than sequence,
updating total_data_bytes accordingly.
Sourcepub fn replay_from_checkpoint(
&self,
checkpoint_idx: usize,
) -> Result<Vec<&StorageWalEntry>, String>
pub fn replay_from_checkpoint( &self, checkpoint_idx: usize, ) -> Result<Vec<&StorageWalEntry>, String>
Returns all entries from the given checkpoint index to the end.
§Errors
Returns an error if checkpoint_idx is out of range.
Sourcepub fn should_checkpoint(&self) -> bool
pub fn should_checkpoint(&self) -> bool
Returns true if the number of ticks since the last checkpoint is
at least checkpoint_interval.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Returns the number of entries currently in the log.
Sourcepub fn data_bytes(&self) -> u64
pub fn data_bytes(&self) -> u64
Returns the total data bytes across all entries.
Sourcepub fn stats(&self) -> StorageWalStats
pub fn stats(&self) -> StorageWalStats
Returns a point-in-time statistics snapshot.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageWriteAheadLog
impl RefUnwindSafe for StorageWriteAheadLog
impl Send for StorageWriteAheadLog
impl Sync for StorageWriteAheadLog
impl Unpin for StorageWriteAheadLog
impl UnsafeUnpin for StorageWriteAheadLog
impl UnwindSafe for StorageWriteAheadLog
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