pub struct DoubleWriteBuffer { /* private fields */ }Expand description
Double-write buffer file.
Implementations§
Source§impl DoubleWriteBuffer
impl DoubleWriteBuffer
Sourcepub fn open(path: &Path, mode: DwbMode) -> Result<Self>
pub fn open(path: &Path, mode: DwbMode) -> Result<Self>
Open or create the double-write buffer file in the requested I/O mode.
Returns None-wrapped errors for unsupported modes via
Err(WalError::…); callers that want “off” should not call this at all.
Sourcepub fn write_record(&mut self, record: &WalRecord) -> Result<()>
pub fn write_record(&mut self, record: &WalRecord) -> Result<()>
Write a WAL record to the double-write buffer before WAL append.
The record is written at the current circular position and the file
is fsynced immediately. Use write_record_deferred + flush for
batch mode (multiple records per fsync).
Sourcepub fn write_record_deferred(&mut self, record: &WalRecord) -> Result<()>
pub fn write_record_deferred(&mut self, record: &WalRecord) -> Result<()>
Write a WAL record to the DWB without fsyncing.
The data is written to the OS page cache (Buffered mode) or directly
to the block device (Direct mode) but not guaranteed durable until
flush() is called. Use this in batch mode: write all records in a
group commit batch, then call flush() once — reducing fsync calls
from N-per-batch to 1-per-batch.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flush the DWB header and fsync the file.
Must be called after one or more write_record_deferred calls to make
the records durable. The single fsync covers all deferred writes since
the last flush — amortizing the cost across the group commit batch.
Sourcepub fn recover_record(&mut self, target_lsn: u64) -> Result<Option<WalRecord>>
pub fn recover_record(&mut self, target_lsn: u64) -> Result<Option<WalRecord>>
Try to recover a WAL record by LSN from the double-write buffer.
Scans all DWB_CAPACITY slots for a record matching the given LSN
with valid CRC. We scan every slot rather than relying on count or
write_pos because the header itself may be stale or corrupted after
a crash. Each slot is self-describing: the record’s own CRC validates
whether the slot contains usable data.