Skip to main content

SegmentedStore

Struct SegmentedStore 

Source
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

Source

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.

Source

pub fn dir(&self) -> &Path

The directory holding the segment files.

Source

pub fn segment_size(&self) -> u64

The configured segment size in bytes.

Trait Implementations§

Source§

impl Debug for SegmentedStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl WalStore for SegmentedStore

Source§

fn write_at(&self, offset: u64, bytes: &[u8]) -> Result<()>

Write bytes at byte offset, growing the store and zero-filling any gap if offset is beyond the current end.
Source§

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

Read into buf starting at byte offset, returning the number of bytes read. Read more
Source§

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

Discard every byte at or after len, shrinking the store to exactly len bytes.
Source§

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

Flush every preceding write_at to stable storage. Read more
Source§

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

The current size of the store in bytes.
Source§

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

The lowest offset that still holds data. Read more
Source§

fn truncate_before(&self, offset: u64) -> Result<u64>

Discard storage entirely below offset, if the backend can, returning the new head. Read more
Source§

fn is_empty(&self) -> Result<bool>

Whether the store holds no bytes. Read more

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, 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<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error