pub struct Wal { /* private fields */ }Expand description
The main write-ahead log.
Create instances exclusively via Wal::open. All methods are safe for
concurrent use from multiple threads.
A WAL progresses through four lifecycle states:
Init → Running → Draining → Closed.
Once closed, a WAL instance cannot be reopened. To continue using the
same file, call Wal::open again.
Implementations§
Source§impl Wal
impl Wal
Sourcepub fn open(path: impl AsRef<Path>) -> WalBuilder
pub fn open(path: impl AsRef<Path>) -> WalBuilder
Starts building a WAL at the given path.
Returns a WalBuilder to configure options before opening.
Call build() to finalize.
let wal = Wal::open("/tmp/my.wal").build()?;Sourcepub fn append(&self, payload: impl Into<Vec<u8>>) -> Result<Lsn>
pub fn append(&self, payload: impl Into<Vec<u8>>) -> Result<Lsn>
Writes a single event. Returns the assigned LSN.
Sourcepub fn append_with_meta(
&self,
payload: impl Into<Vec<u8>>,
meta: impl Into<Vec<u8>>,
) -> Result<Lsn>
pub fn append_with_meta( &self, payload: impl Into<Vec<u8>>, meta: impl Into<Vec<u8>>, ) -> Result<Lsn>
Writes a single event with metadata. Returns the assigned LSN.
Sourcepub fn append_batch(&self, batch: Batch) -> Result<Lsn>
pub fn append_batch(&self, batch: Batch) -> Result<Lsn>
Writes a batch of events atomically. Returns the last assigned LSN.
Takes Batch by value to avoid cloning payloads (move semantics).
Build a new Batch for each call, or .clone() explicitly if reuse is needed.
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Blocks until the writer has processed all queued batches.
Does NOT call fsync. For full durability: flush() then sync().
Sourcepub fn sync(&self) -> Result<()>
pub fn sync(&self) -> Result<()>
Calls fsync on the underlying storage, making written data durable.
Sourcepub fn replay(
&self,
from: Lsn,
f: impl FnMut(Event) -> Result<()>,
) -> Result<()>
pub fn replay( &self, from: Lsn, f: impl FnMut(Event) -> Result<()>, ) -> Result<()>
Reads all events with LSN >= from, calling f for each.
Uses mmap for zero-copy access. The Event passed to f has
payload and meta that are owned copies; they are safe to keep.
Sourcepub fn iterator(&self, from: Lsn) -> Result<WalIterator>
pub fn iterator(&self, from: Lsn) -> Result<WalIterator>
Returns a pull-based iterator starting from the given LSN.
Sourcepub fn last_lsn(&self) -> Lsn
pub fn last_lsn(&self) -> Lsn
Most recently persisted LSN. May lag behind append return values.