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 only the segments with unwritten changes, not the whole history.
§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.
§Errors
Returns WalError::Io if segment_size is zero, or if the directory
cannot be created or read.
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.