Skip to main content

Storage

Trait Storage 

Source
pub trait Storage: Send + Sync {
    // Required methods
    fn write(&mut self, buf: &[u8]) -> Result<usize>;
    fn sync(&mut self) -> Result<()>;
    fn close(&mut self) -> Result<()>;
    fn size(&self) -> Result<u64>;
    fn truncate(&mut self, size: u64) -> Result<()>;
    fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>;
}
Expand description

Persistence backend for the WAL.

The writer thread calls write sequentially; replay and recovery use memory-mapped I/O when available, falling back to read_at for custom implementations. Implementations must handle their own thread safety for concurrent read + write access.

Required Methods§

Source

fn write(&mut self, buf: &[u8]) -> Result<usize>

Appends data. The WAL does not seek before writing.

Source

fn sync(&mut self) -> Result<()>

Ensures all written data is durable (fsync).

Source

fn close(&mut self) -> Result<()>

Releases all resources. After close, all methods must return Error::Closed.

Source

fn size(&self) -> Result<u64>

Current storage size in bytes.

Source

fn truncate(&mut self, size: u64) -> Result<()>

Shrinks storage to size bytes. Used during recovery to remove corrupted trailing records.

Source

fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>

Reads buf.len() bytes starting at offset. Used as a fallback when mmap is not available.

Implementors§