Skip to main content

WalFsWriter

Struct WalFsWriter 

Source
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

Source

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.

Source

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.

Source

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl WalWriter for WalFsWriter

Source§

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>

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>

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.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more