Struct Wal

Source
pub struct Wal {
    dir: PathBuf,
    config: WalConfig,
    meta: WalMeta,
    current_writer: Option<BufWriter<File>>,
    current_segment_size: u64,
}
Expand description

Write-Ahead Log.

Fields§

§dir: PathBuf§config: WalConfig§meta: WalMeta§current_writer: Option<BufWriter<File>>§current_segment_size: u64

Implementations§

Source§

impl Wal

Source

pub fn open(dir: &Path, config: WalConfig) -> Result<Self, StorageError>

Open or create a WAL in the given directory.

Source

fn load_or_create_meta(dir: &Path) -> Result<WalMeta, StorageError>

Source

fn segment_path(&self, segment_id: u64) -> PathBuf

Source

fn open_current_segment(&mut self) -> Result<(), StorageError>

Source

fn write_segment_header( writer: &mut BufWriter<File>, segment_id: u64, ) -> Result<(), StorageError>

Source

fn rotate_segment(&mut self) -> Result<(), StorageError>

Source

pub fn append( &mut self, entry_type: EntryType, flags: u8, payload: &[u8], ) -> Result<u64, StorageError>

Append an entry to the WAL. Returns the assigned sequence number.

Source

pub fn commit(&mut self, sequence: u64) -> Result<(), StorageError>

Mark all entries up to sequence as committed.

Ensures durability by syncing segment data to disk before updating metadata, then syncing the directory to make the rename durable. See RFC-002-01 (Pillai et al., OSDI 2014).

Source

pub fn committed_sequence(&self) -> u64

Get the last committed sequence number.

Source

pub fn last_sequence(&self) -> u64

Get the last appended sequence number.

Source

pub fn flush(&mut self) -> Result<(), StorageError>

Flush buffered writes to disk.

Source

fn persist_meta(&self) -> Result<(), StorageError>

Source

pub fn recover(&mut self) -> Result<Vec<WalEntry>, StorageError>

Recover uncommitted entries after a crash.

Scans all segments for entries with sequence > committed_sequence. Validates CRC32 for each entry. Stops at first corrupted entry. Returns valid uncommitted entries for replay.

Source

fn list_segments(&self) -> Result<Vec<u64>, StorageError>

Source

fn read_segment( &self, segment_id: u64, committed_seq: u64, ) -> Result<Vec<WalEntry>, StorageError>

Source

pub fn truncate_uncommitted(&mut self) -> Result<(), StorageError>

Truncate the WAL at the current committed position.

Removes all segments before the committed segment and truncates the committed segment at the committed offset. Used after recovery.

Auto Trait Implementations§

§

impl Freeze for Wal

§

impl RefUnwindSafe for Wal

§

impl Send for Wal

§

impl Sync for Wal

§

impl Unpin for Wal

§

impl UnwindSafe for Wal

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.