pub struct WalFsWriter { /* private fields */ }Expand description
A file system backed WAL writer.
The writer opens a file in read-write mode and manually seeks to end before each write. On write failure, it truncates back to the pre-write position to ensure atomicity. If truncation itself fails, the writer becomes permanently poisoned and rejects all subsequent appends.
Implementations§
Source§impl WalFsWriter
impl WalFsWriter
Sourcepub fn new(path: PathBuf) -> Result<Self, WalFsWriterInitError>
pub fn new(path: PathBuf) -> Result<Self, WalFsWriterInitError>
Creates a new WAL writer at the given path.
If the file does not exist, it will be created. If it exists, events will be appended to the end of the file.
During initialization, the writer strictly validates all existing framed records from the start of the WAL. Any trailing corruption (partial header, partial payload, unsupported version, or decode failure) hard-fails bootstrap with typed corruption diagnostics.
§Arguments
path- The filesystem path where the WAL file should be located
§Errors
Returns WalFsWriterInitError::IoError if the WAL file cannot be
opened or read during bootstrap.
Returns WalFsWriterInitError::Corruption if strict WAL tail
validation detects corruption in existing bytes.
Sourcepub fn new_with_repair(
path: PathBuf,
policy: RepairPolicy,
) -> Result<Self, WalFsWriterInitError>
pub fn new_with_repair( path: PathBuf, policy: RepairPolicy, ) -> Result<Self, WalFsWriterInitError>
Creates a new WAL writer with the specified repair policy.
Under RepairPolicy::Strict, behaves identically to new.
Under RepairPolicy::TruncatePartial, if only trailing bytes are
corrupt (incomplete record at the end), they are truncated and the
writer opens normally from the last valid record. Mid-stream
corruption (corrupt record followed by valid records) still hard-fails.
Sourcepub fn current_sequence(&self) -> u64
pub fn current_sequence(&self) -> u64
Returns the highest sequence number observed in the WAL (0 for empty WAL).
Trait Implementations§
Source§impl Drop for WalFsWriter
impl Drop for WalFsWriter
Source§impl WalWriter for WalFsWriter
impl WalWriter for WalFsWriter
Source§fn append(&mut self, event: &WalEvent) -> Result<(), WalWriterError>
fn append(&mut self, event: &WalEvent) -> Result<(), WalWriterError>
Append an event to the WAL.
The event is encoded using the codec’s encode function and
appended to the underlying file. The current sequence tracker
is updated to the event’s sequence number if it’s higher.
§Arguments
event- The WAL event to append
§Errors
Returns WalWriterError::Closed if the writer has been closed.
Returns WalWriterError::IoError if the write operation fails.
Source§fn flush(&mut self) -> Result<(), WalWriterError>
fn flush(&mut self) -> Result<(), WalWriterError>
Flushes pending writes to durable storage.
This ensures that all buffered data is written to disk before returning. The flush operation is synchronous and will block until the data is persisted.
§Errors
Returns WalWriterError::Closed if the writer has been closed.
Returns WalWriterError::IoError if the flush operation fails.
Source§fn close(self) -> Result<(), WalWriterError>
fn close(self) -> Result<(), WalWriterError>
Closes the writer, releasing the file handle.
A flush is performed before closing to ensure all data is persisted. Once closed, the writer cannot be used for further operations.
§Errors
Returns WalWriterError::IoError if the flush or close operation fails.