Skip to main content

SharedWal

Struct SharedWal 

Source
pub struct SharedWal { /* private fields */ }
Expand description

A WAL shared across all tables of a Database, multiplexing many tables’ records onto one fd (spec §7.2). Owns the active Wal segment plus the list of rotated segments under <root>/_wal/. Appends are buffered; a single SharedWal::group_sync is the durability point for every concurrent writer that appended since the last sync.

Implementations§

Source§

impl SharedWal

Source

pub fn create(root: &Path, epoch_created: Epoch) -> Result<Self>

Create a fresh shared WAL at <root>/_wal/ starting at epoch_created.

Source

pub fn create_with_dek( root: &Path, epoch_created: Epoch, wal_dek: Option<Zeroizing<[u8; 32]>>, ) -> Result<Self>

Create with optional frame-level encryption (WAL DEK).

Source

pub fn open( root: &Path, epoch_created: Epoch, wal_dek: Option<Zeroizing<[u8; 32]>>, ) -> Result<Self>

Open an existing shared WAL for append, preserving prior segments (which replay reads for recovery). A fresh active segment numbered one past the highest existing is created — old segments are NOT truncated (review fix #6), so a crash mid-recovery can re-replay them safely.

Source

pub fn wal_dir(&self) -> &Path

The active segment’s wal_dir (test/diagnostic).

Source

pub fn append(&mut self, txn_id: u64, _table_id: u64, op: Op) -> Result<u64>

Append a record for (txn_id, table_id). Does not fsync.

Source

pub fn append_commit( &mut self, txn_id: u64, epoch: Epoch, added: &[AddedRun], ) -> Result<u64>

Append a TxnCommit marker sealing txn_id at epoch.

Source

pub fn append_abort(&mut self, txn_id: u64) -> Result<()>

Append a TxnAbort marker for txn_id.

Source

pub fn append_system(&mut self, op: Op) -> Result<u64>

Append a system record (txn_id == 0), e.g. Flush.

Source

pub fn group_sync(&mut self) -> Result<u64>

Flush + fsync the active segment and return the highest durable sequence number. This is the single durability point for every concurrent appender since the last group_sync.

Source

pub fn group_sync_count(&self) -> u64

Number of fsyncs issued so far (test/diagnostic — see [group_sync]).

Source

pub fn durable_seq(&self) -> u64

The highest sequence number reported durable by the last group_sync.

Source

pub fn rotate(&mut self, segment_no: u64) -> Result<()>

Rotate to a fresh segment numbered segment_no (which namespaces nonces under the constant WAL DEK). The current segment must already be synced.

Source

pub fn active_segment_no(&self) -> u64

The active segment number.

Source

pub fn gc_segments(&mut self, min_retained_seq: u64) -> Result<usize>

Delete rotated (non-active) WAL segments whose records are all below min_retained_seq — i.e. every record in them is already durable in a run and not needed by any in-flight or committed-not-flushed txn (spec §6.4/§16). The active segment is never deleted. Returns the count of segment files reaped.

open() mints a fresh active segment on every reopen without truncating the prior ones (so a crash mid-recovery can re-replay), which means old segments accumulate; this is what reaps them once their data is durable.

Source

pub fn verify_segments(&self) -> Vec<(u64, String)>

Verify the on-disk integrity of every WAL segment (spec §16): each seg-NNNNNN.wal file under <root>/_wal/ must open — its header magic and version must parse, and for an encrypted WAL the frame cipher must be derivable from the WAL DEK. A segment that fails to open is corrupt or truncated and would break recovery. Returns one (segment_no, error) pair per failing segment. The active (in-memory) segment is trusted by construction and re-checked from disk like the others.

Source

pub fn replay(root: &Path) -> Result<Vec<Record>>

Replay every record across all segments in <root>/_wal/, in segment order, applying the torn-tail-vs-interior-corruption rule per segment.

Source

pub fn replay_with_dek( root: &Path, wal_dek: Option<&Zeroizing<[u8; 32]>>, ) -> Result<Vec<Record>>

Replay with an optional WAL DEK (for encrypted segments).

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.