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§
Sourcepub fn create(root: &Path, epoch_created: Epoch) -> Result<Self>
pub fn create(root: &Path, epoch_created: Epoch) -> Result<Self>
Create a fresh shared WAL at <root>/_wal/ starting at epoch_created.
Sourcepub fn create_with_dek(
root: &Path,
epoch_created: Epoch,
wal_dek: Option<Zeroizing<[u8; 32]>>,
) -> Result<Self>
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).
Sourcepub fn open(
root: &Path,
epoch_created: Epoch,
wal_dek: Option<Zeroizing<[u8; 32]>>,
) -> Result<Self>
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.
Sourcepub fn append(&mut self, txn_id: u64, _table_id: u64, op: Op) -> Result<u64>
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.
Sourcepub fn append_commit(
&mut self,
txn_id: u64,
epoch: Epoch,
added: &[AddedRun],
) -> Result<u64>
pub fn append_commit( &mut self, txn_id: u64, epoch: Epoch, added: &[AddedRun], ) -> Result<u64>
Append a TxnCommit marker sealing txn_id at epoch.
Sourcepub fn append_abort(&mut self, txn_id: u64) -> Result<()>
pub fn append_abort(&mut self, txn_id: u64) -> Result<()>
Append a TxnAbort marker for txn_id.
Sourcepub fn append_system(&mut self, op: Op) -> Result<u64>
pub fn append_system(&mut self, op: Op) -> Result<u64>
Append a system record (txn_id == 0), e.g. Flush.
Sourcepub fn group_sync(&mut self) -> Result<u64>
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.
Sourcepub fn group_sync_count(&self) -> u64
pub fn group_sync_count(&self) -> u64
Number of fsyncs issued so far (test/diagnostic — see [group_sync]).
Sourcepub fn durable_seq(&self) -> u64
pub fn durable_seq(&self) -> u64
The highest sequence number reported durable by the last group_sync.
Sourcepub fn rotate(&mut self, segment_no: u64) -> Result<()>
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.
Sourcepub fn active_segment_no(&self) -> u64
pub fn active_segment_no(&self) -> u64
The active segment number.
Sourcepub fn gc_segments(&mut self, min_retained_seq: u64) -> Result<usize>
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.
Sourcepub fn verify_segments(&self) -> Vec<(u64, String)>
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.
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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