Skip to main content

Wal

Struct Wal 

Source
pub struct Wal { /* private fields */ }

Implementations§

Source§

impl Wal

Source

pub fn create(path: &Path) -> Result<Self>

Creates a fresh WAL file, truncating any existing one. Writes the header synchronously so a subsequent open sees a valid file even if the caller panics before appending any frames. Always takes an exclusive lock — create is a write operation by definition.

Source

pub fn open(path: &Path) -> Result<Self>

Opens an existing WAL file with an exclusive lock (read-write). Convenience wrapper around Wal::open_with_mode.

Source

pub fn open_with_mode(path: &Path, mode: AccessMode) -> Result<Self>

Opens an existing WAL file with the given access mode. In ReadOnly mode the file descriptor is opened read-only and the advisory lock is shared — multiple read-only openers may coexist. Walks every frame from the start, validates checksums, and builds the in-memory latest_frame index. A torn or corrupted frame is treated as the end of the log — its bytes and anything after stay on disk but are ignored by reads.

Source

pub fn header(&self) -> WalHeader

Source

pub fn frame_count(&self) -> usize

Source

pub fn last_commit_page_count(&self) -> Option<u32>

Source

pub fn clock_high_water(&self) -> u64

Phase 11.2 — the MVCC logical-clock high-water mark persisted in this WAL’s header. Returns 0 for fresh-from-create WALs and for v1 WALs (where the bytes were reserved-zero). The Pager (Phase 11.3) seeds the in-memory MvccClock from this on open.

Source

pub fn set_clock_high_water(&mut self, value: u64) -> Result<()>

Phase 11.2 — overrides the in-memory clock high-water value. truncate writes whatever value the WAL is carrying when it runs, so callers update this just before checkpoint to persist the latest in-memory clock value. The setter rejects a non-monotonic update (a value below the existing high-water mark) — that would either be a bug in the caller or evidence of a corrupted in-memory clock. Same value is a no-op.

Source

pub fn load_committed_into( &mut self, dest: &mut HashMap<u32, Box<[u8; 4096]>>, ) -> Result<()>

Bulk-loads every committed page from the WAL into dest. Used by Pager::open to warm a WAL cache so subsequent reads don’t have to seek back into the WAL file. Uncommitted frames are skipped (same rule as read_page).

Source

pub fn append_frame( &mut self, page_num: u32, content: &[u8; 4096], commit_page_count: Option<u32>, ) -> Result<()>

Appends a new frame at the current end of file. commit_page_count of None writes a dirty (in-progress) frame; Some(n) writes a commit frame carrying the post-commit page count. On commit the frame is fsync’d; dirty frames are not — torn writes are recovered by the checksum check on next open.

Source

pub fn read_page(&mut self, page_num: u32) -> Result<Option<Box<[u8; 4096]>>>

Reads the most recent committed copy of a page from the WAL, or None if no committed frame has been written for this page since the last checkpoint. Uncommitted (dirty) frames are skipped — a reader must only see committed state.

Source

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

Truncates the WAL back to just the header and rolls the salt. Called by the checkpointer (Phase 4d) once it has applied accumulated frames to the main file.

Source

pub fn append_mvcc_batch(&mut self, batch: &MvccCommitBatch) -> Result<()>

Phase 11.9 — appends an MVCC commit batch as a single WAL frame whose page_num is set to MVCC_FRAME_MARKER.

Writes the frame as a “dirty” frame (commit_page_count = None) so it doesn’t seal a transaction by itself — it piggybacks on the next legacy page-commit frame’s fsync. This is the durability boundary for BEGIN CONCURRENT: the MVCC batch and the legacy page updates of the same transaction land in the WAL together and either both survive the next fsync or both fall away at the torn-write boundary on reopen.

Connection::commit_concurrent calls this right before save_database, so the same fsync covers both.

Source

pub fn recovered_mvcc_commits(&self) -> &[MvccCommitBatch]

Phase 11.9 — returns the MVCC commit batches recovered from the WAL on open, in commit order. Empty if no MVCC frames were present (a brand-new WAL, a pre-11.9 v1/v2 WAL, or one where the last commit barrier dropped MVCC frames).

Trait Implementations§

Source§

impl Debug for Wal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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