pub struct SegmentedStore { /* private fields */ }Expand description
A WalStore that stripes one flat byte space across fixed-size segment
files in a directory.
Open one with SegmentedStore::open and hand it to
Wal::with_store, or use the
Wal::open_segmented convenience constructor.
Segments are created lazily as the log grows, and sync
flushes every segment written since the last sync, not the whole history.
The segment size is recorded in a meta file next to the segments; opening
with another size is refused rather than reading the bytes at the wrong
offsets.
§Examples
use wal_db::{SegmentedStore, Wal};
// 1 MiB segments. Records larger than a segment simply span several.
let store = SegmentedStore::open(dir.path(), 1024 * 1024)?;
let wal = Wal::with_store(store)?;
wal.append(b"spans nothing yet")?;
wal.sync()?;Implementations§
Source§impl SegmentedStore
impl SegmentedStore
Sourcepub fn open(dir: impl AsRef<Path>, segment_size: u64) -> Result<Self>
pub fn open(dir: impl AsRef<Path>, segment_size: u64) -> Result<Self>
Open the segmented log in dir, creating the directory if needed, with
segments of segment_size bytes.
Existing segment files are picked up so the log can be recovered. The
store does not validate record contents — that is
Wal::open’s recovery scan, which runs unchanged over
the flat space. Every existing segment is flushed first: a process that
stopped without syncing may have left bytes only in the page cache, and
recovery must not trust what a power loss could still take away.
§Errors
WalError::Ioifsegment_sizeis zero, or if the directory or a segment cannot be created, read, or flushed.WalError::Corruptionif the log was written with another segment size, or if its first segments were dropped and the head marker that says where it now starts is missing or damaged. Nothing is deleted.
Sourcepub fn segment_size(&self) -> u64
pub fn segment_size(&self) -> u64
The configured segment size in bytes.
Trait Implementations§
Source§impl Debug for SegmentedStore
impl Debug for SegmentedStore
Source§impl WalStore for SegmentedStore
impl WalStore for SegmentedStore
Source§fn write_at(&self, offset: u64, bytes: &[u8]) -> Result<()>
fn write_at(&self, offset: u64, bytes: &[u8]) -> Result<()>
bytes at byte offset, growing the store and zero-filling any
gap if offset is beyond the current end.Source§fn truncate(&self, len: u64) -> Result<()>
fn truncate(&self, len: u64) -> Result<()>
len, shrinking the store to exactly
len bytes.