Skip to main content

WAL

Struct WAL 

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

Write-Ahead Log for durability.

Uses an append-only on-disk format: each flush_to_disk() call serializes only the new records since the last flush and appends them to the file. The full file is only rewritten during clear() (checkpoint).

Implementations§

Source§

impl WAL

Source

pub fn new(path: PathBuf) -> Self

Source

pub fn path(&self) -> &PathBuf

Source

pub fn append(&mut self, record: WALRecord)

Source

pub fn log_column_write( &mut self, table_id: u64, col_id: u32, page_id: u64, data: &[u8], )

Log a column page write before it is applied to the BufferManager.

Source

pub fn write_raw_buffer(&mut self, local_wal_buffer: &[u8])

Bulk-copy a LocalWAL’s serialized buffer into this global WAL.

Called during commit path: the transaction’s LocalWAL has already been serialized to a byte buffer; this method appends the raw bytes directly to the in-memory record list.

The caller (StorageManager::commit_transaction()) is responsible for holding the Arc<Mutex<WAL>> lock to serialize concurrent calls.

Source

pub fn records(&self) -> &[WALRecord]

Source

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

Clear all in-memory records and truncate the WAL file on disk.

Called during checkpoint after dirty pages have been flushed — at this point the WAL data is durable in the main DB files and can be discarded.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn total_size(&self) -> usize

Source

pub fn is_dirty(&self) -> bool

Source

pub fn replay<F>(&self, apply: F) -> Result<()>
where F: FnMut(&WALRecord) -> Result<()>,

Replay the WAL to recover state after a crash.

Source

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

Append-only flush: serialize only records not yet on disk.

Instead of rewriting the entire WAL file (O(n) per flush → O(n²) total), this method serializes only the new records since the last flush and appends them to the existing file. The header is written once on the first flush after a clear() (checkpoint).

Crash safety: CRC32 per record detects partial appends. A partial final record is silently skipped on recovery.

§On-disk format (v2)
┌──────────────────────────────────────────────┐
│ Header: "AKAR" (4 bytes) + version (u16 LE) │
├──────────────────────────────────────────────┤
│ Per record:                                  │
│   CRC32 (u32 LE) of [tag .. payload]        │
│   tag (1 byte)                               │
│   payload (variable)                         │
└──────────────────────────────────────────────┘
Source

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

Load WAL records from disk.

Supports both v1 (no checksums) and v2 (CRC32 per record) formats. Records with invalid checksums are silently skipped with a warning.

Auto Trait Implementations§

§

impl Freeze for WAL

§

impl RefUnwindSafe for WAL

§

impl Send for WAL

§

impl Sync for WAL

§

impl Unpin for WAL

§

impl UnsafeUnpin for WAL

§

impl UnwindSafe for WAL

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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<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