Skip to main content

Wal

Struct Wal 

Source
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

Source

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()?;
Source

pub fn append(&self, payload: impl Into<Vec<u8>>) -> Result<Lsn>

Writes a single event. Returns the assigned LSN.

Source

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.

Source

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.

Source

pub fn flush(&self) -> Result<()>

Blocks until the writer has processed all queued batches.

Does NOT call fsync. For full durability: flush() then sync().

Source

pub fn sync(&self) -> Result<()>

Calls fsync on the underlying storage, making written data durable.

Source

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.

Source

pub fn iterator(&self, from: Lsn) -> Result<WalIterator>

Returns a pull-based iterator starting from the given LSN.

Source

pub fn last_lsn(&self) -> Lsn

Most recently persisted LSN. May lag behind append return values.

Source

pub fn stats(&self) -> Stats

Point-in-time snapshot of WAL statistics.

Source

pub fn shutdown(&self, timeout: Duration) -> Result<()>

Graceful shutdown: drains queue, flushes, syncs, closes storage.

Transitions to Draining (new appends rejected), then to Closed. Respects the timeout — returns Error::Io on timeout. Idempotent: calling on a closed WAL returns Ok(()).

Source

pub fn close(&self) -> Result<()>

Immediate close without draining the write queue.

Pending batches are discarded. For graceful shutdown, use shutdown. Idempotent.

Trait Implementations§

Source§

impl Drop for Wal

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Wal

§

impl !RefUnwindSafe for Wal

§

impl Send for Wal

§

impl Sync for Wal

§

impl Unpin for Wal

§

impl UnsafeUnpin for Wal

§

impl !UnwindSafe for Wal

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.