pub struct WriteAheadLog {
pub max_entries: usize,
pub stats: WalStats,
/* private fields */
}Expand description
In-memory write-ahead log providing crash-recovery for block store writes.
§Example
use ipfrs_storage::wal::{WriteAheadLog, WalOp};
let wal = WriteAheadLog::new(1000);
let seq = wal.append(WalOp::Put { cid: "bafytest".into(), data_len: 128 }).unwrap();
assert_eq!(seq, 1);
let ops = wal.replay_ops();
assert_eq!(ops.len(), 1);Fields§
§max_entries: usizeMaximum number of entries allowed in the log before truncation is required.
stats: WalStatsLive statistics.
Implementations§
Source§impl WriteAheadLog
impl WriteAheadLog
Sourcepub fn new(max_entries: usize) -> Self
pub fn new(max_entries: usize) -> Self
Creates a new WriteAheadLog with the given maximum entry count.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Creates a WriteAheadLog with the default maximum of 10 000 entries.
Sourcepub fn append(&self, op: WalOp) -> Result<u64, WalError>
pub fn append(&self, op: WalOp) -> Result<u64, WalError>
Appends an operation to the WAL.
Assigns the next sequence number, computes the CRC-32 (FNV-1a) of the serialized op, and stores the entry. Returns the assigned sequence number.
§Errors
Returns WalError::CapacityExceeded when the number of stored entries
already equals or exceeds max_entries.
Sourcepub fn checkpoint(&self) -> Result<u64, WalError>
pub fn checkpoint(&self) -> Result<u64, WalError>
Appends a WalOp::Checkpoint entry and updates checkpoint_sequence.
Returns the sequence number of the checkpoint entry.
Sourcepub fn entries_since_checkpoint(&self) -> Vec<WalEntry>
pub fn entries_since_checkpoint(&self) -> Vec<WalEntry>
Returns all entries whose sequence number is strictly greater than the last checkpointed sequence.
Sourcepub fn truncate_before(&self, sequence: u64) -> usize
pub fn truncate_before(&self, sequence: u64) -> usize
Removes all entries whose sequence number is strictly less than
sequence. Returns the number of entries removed.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Returns the number of entries currently in the log.
Sourcepub fn replay_ops(&self) -> Vec<WalOp>
pub fn replay_ops(&self) -> Vec<WalOp>
Returns the ops from entries since the last checkpoint, excluding
WalOp::Checkpoint ops themselves (those are metadata, not data ops).
Sourcepub fn checkpoint_sequence(&self) -> u64
pub fn checkpoint_sequence(&self) -> u64
Returns the current checkpoint sequence number.
Sourcepub fn next_sequence(&self) -> u64
pub fn next_sequence(&self) -> u64
Returns the next sequence number that will be assigned (without consuming it).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WriteAheadLog
impl RefUnwindSafe for WriteAheadLog
impl Send for WriteAheadLog
impl Sync for WriteAheadLog
impl Unpin for WriteAheadLog
impl UnsafeUnpin for WriteAheadLog
impl UnwindSafe for WriteAheadLog
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