pub struct Wal { /* private fields */ }Expand description
Append-only write-ahead log.
Implementations§
Source§impl Wal
impl Wal
Sourcepub fn open(dir_path: &Path) -> MenteResult<Self>
pub fn open(dir_path: &Path) -> MenteResult<Self>
Open or create a WAL file at dir_path/wal.log.
Sourcepub fn lock_exclusive(&self) -> MenteResult<()>
pub fn lock_exclusive(&self) -> MenteResult<()>
Acquire a blocking exclusive file lock on the WAL file.
Uses flock(2) (via fs2) which works across processes on the same host.
Blocks until the lock is available — callers should hold it only for
the duration of append + fsync.
Sourcepub fn unlock(&self) -> MenteResult<()>
pub fn unlock(&self) -> MenteResult<()>
Release the file lock on the WAL file.
Sourcepub fn reload_lsn(&mut self) -> MenteResult<()>
pub fn reload_lsn(&mut self) -> MenteResult<()>
Re-read the WAL file to find the highest LSN, updating next_lsn. Must be called under flock to see writes from other processes.
Fast path: reads each entry’s raw payload and CRC-validates it, but skips the expensive LZ4 decompression. Only extracts the LSN (first 8 bytes of each payload).
Sourcepub fn append(
&mut self,
entry_type: WalEntryType,
page_id: u64,
data: &[u8],
) -> MenteResult<Lsn>
pub fn append( &mut self, entry_type: WalEntryType, page_id: u64, data: &[u8], ) -> MenteResult<Lsn>
Append an entry to the WAL and return its LSN.
Sourcepub fn sync(&mut self) -> MenteResult<()>
pub fn sync(&mut self) -> MenteResult<()>
Flush the WAL to durable storage (fdatasync).
Sourcepub fn iterate(&mut self) -> MenteResult<Vec<WalEntry>>
pub fn iterate(&mut self) -> MenteResult<Vec<WalEntry>>
Read all valid entries from the WAL for recovery.
Sourcepub fn truncate(&mut self, before_lsn: Lsn) -> MenteResult<()>
pub fn truncate(&mut self, before_lsn: Lsn) -> MenteResult<()>
Truncate all entries with LSN less than before_lsn.
Uses atomic write-to-temp-then-rename to avoid data loss on crash.