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