pub struct WalWriter { /* private fields */ }Expand description
A writer for the Write-Ahead Log.
Implementations§
Source§impl WalWriter
impl WalWriter
Sourcepub fn new(path: &Path) -> Result<Self>
pub fn new(path: &Path) -> Result<Self>
Creates a new WAL writer for the given file path.
Before opening for append, the existing log is repaired by truncating it to the end of its last fully-valid record. A crash can leave a torn record at the tail (a partial or checksum-failing frame). Without repair, the next append would land after that torn record, leaving it permanently in the middle of the log; replay stops at the first torn record, so every record appended afterwards would be silently unrecoverable. Repairing on open guarantees appends always extend a fully-replayable log.
Sourcepub fn append(&mut self, record: &WalRecord) -> Result<()>
pub fn append(&mut self, record: &WalRecord) -> Result<()>
Appends a record to the log buffer.
The record is serialized and framed with:
- Length (u32)
- Checksum (u32)
- Data (u8)
This only writes into the in-process buffer; it does not fsync. The
caller must invoke WalWriter::sync at the transaction commit boundary
to make the appended records durable. Decoupling append from fsync turns
an N-record transaction’s N fsyncs into a single fsync at commit, which
is the standard WAL group-commit-at-the-record-boundary pattern (cf.
lsm::wal::SyncMode/force_sync, and fjall/mini-lsm reference impls).
Durability semantics are unchanged: a commit is only acknowledged after
WalWriter::sync returns, so every record of a committed transaction
is on stable storage (v0.5 Durability requirement CORE-5.1).
Sourcepub fn sync(&mut self) -> Result<()>
pub fn sync(&mut self) -> Result<()>
Flushes the buffer and fsyncs the underlying file, making all previously appended records durable.
This is the durability point for a transaction commit: once it returns
Ok, every record appended since the last sync is guaranteed to be on
stable storage. A sync failure is propagated so the caller can refuse
to acknowledge the commit (CORE-5.1: a WAL fsync failure must not be
reported as a successful commit).