pub struct Wal { /* private fields */ }Implementations§
Source§impl Wal
impl Wal
Sourcepub fn create(path: &Path) -> Result<Self>
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.
Sourcepub fn open(path: &Path) -> Result<Self>
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.
Sourcepub fn open_with_mode(path: &Path, mode: AccessMode) -> Result<Self>
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.
pub fn header(&self) -> WalHeader
pub fn frame_count(&self) -> usize
pub fn last_commit_page_count(&self) -> Option<u32>
Sourcepub fn clock_high_water(&self) -> u64
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.
Sourcepub fn set_clock_high_water(&mut self, value: u64) -> Result<()>
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.
Sourcepub fn load_committed_into(
&mut self,
dest: &mut HashMap<u32, Box<[u8; 4096]>>,
) -> Result<()>
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).
Sourcepub fn append_frame(
&mut self,
page_num: u32,
content: &[u8; 4096],
commit_page_count: Option<u32>,
) -> Result<()>
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.
Sourcepub fn read_page(&mut self, page_num: u32) -> Result<Option<Box<[u8; 4096]>>>
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.
Sourcepub fn truncate(&mut self) -> Result<()>
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.
Sourcepub fn append_mvcc_batch(&mut self, batch: &MvccCommitBatch) -> Result<()>
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.
Sourcepub fn recovered_mvcc_commits(&self) -> &[MvccCommitBatch]
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).