Skip to main content

SegmentedWal

Struct SegmentedWal 

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

A segmented write-ahead log.

Manages a directory of WAL segment files. Records are appended to the active segment. When the active segment exceeds segment_target_size, a new segment is created automatically on the next append.

Implementations§

Source§

impl SegmentedWal

Source

pub fn open(config: SegmentedWalConfig) -> Result<Self>

Open or create a segmented WAL in the given directory.

On first startup, creates the directory and the first segment. On subsequent startups, discovers existing segments and opens the last one for continued appending.

Source

pub fn set_encryption_ring(&mut self, ring: KeyRing) -> Result<()>

Set the encryption key ring. All subsequent records will be encrypted.

Must be called before the first append. Returns an error if records have already been written to the active segment.

Source

pub fn configure_encryption_ring(&mut self, ring: KeyRing) -> Result<()>

Configure encryption for a newly created WAL or roll an already-open active segment before switching keys on restart.

Source

pub fn encryption_ring(&self) -> Option<&KeyRing>

Get the encryption key ring (for replay decryption).

Source

pub fn rotate_encryption_ring(&mut self, ring: KeyRing) -> Result<()>

Seal the active segment and start a new segment under ring. This is the only safe runtime key-rotation boundary because a segment’s encryption epoch and key are fixed by its preamble.

Source

pub fn append( &mut self, record_type: u32, tenant_id: u64, vshard_id: u32, database_id: u64, payload: &[u8], ) -> Result<u64>

Append a record to the WAL. Returns the assigned LSN.

If the active segment has exceeded the target size, a new segment is created before appending. The rollover is transparent to the caller.

database_id is stored in header bytes 34-41. Pass 0 for the default database (backward-compatible with pre-existing records).

Source

pub fn append_keyed( &mut self, target: RecordTarget, payload: &[u8], apply_key: u64, ) -> Result<u64>

Self::append for a record appended by the apply of the replicated proposal apply_key, carrying the event source in target (see crate::WalRecord::new_stamped).

Source

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

Flush all buffered records and fsync the active segment.

Source

pub fn seal_active_segment(&mut self) -> Result<()>

Seal the active segment and start the next one, so every record appended so far sits in a sealed segment. A no-op when the active segment holds no record.

Source

pub fn next_lsn(&self) -> u64

The next LSN that will be assigned.

Source

pub fn max_payload(&self) -> usize

The largest payload one record takes (see WalWriter::max_payload).

Source

pub fn active_segment_first_lsn(&self) -> u64

First LSN of the active (currently written) segment.

Source

pub fn wal_dir(&self) -> &Path

The WAL directory path.

Source

pub fn truncate_before(&self, checkpoint_lsn: u64) -> Result<TruncateResult>

Truncate old WAL segments that are fully below the checkpoint LSN.

Only sealed (non-active) segments are eligible for deletion. The active segment is never deleted.

Returns the number of segments deleted and bytes reclaimed.

Source

pub fn replay(&self) -> Result<Vec<WalRecord>>

Replay all committed records across all segments, in LSN order.

Used for crash recovery on startup. Payloads are returned as plaintext: this WAL’s own key ring is applied to every encrypted record.

Source

pub fn replay_from(&self, from_lsn: u64) -> Result<Vec<WalRecord>>

Replay only records with LSN >= from_lsn.

Used when recovering from a checkpoint — records before the checkpoint LSN have already been applied from the snapshot.

Fails with WalError::ReplayBelowRetainedFloor when from_lsn names an LSN truncation has already deleted, rather than returning the shorter suffix that survives. Delegating to replay_from_limit_dir keeps that check — and the per-segment continuity and torn-tail checks — in one place instead of replaying everything and filtering afterwards.

Source

pub fn replay_from_limit( &self, from_lsn: u64, max_records: usize, ) -> Result<(Vec<WalRecord>, bool)>

Paginated replay (delegates to standalone replay_from_limit_dir).

Source

pub fn list_segments(&self) -> Result<Vec<SegmentMeta>>

List all segment metadata (for monitoring / operational tooling).

Source

pub fn total_size_bytes(&self) -> Result<u64>

Total WAL size on disk across all 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more