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
impl WAL
pub fn new(path: PathBuf) -> Self
pub fn path(&self) -> &PathBuf
pub fn append(&mut self, record: WALRecord)
Sourcepub fn log_column_write(
&mut self,
table_id: u64,
col_id: u32,
page_id: u64,
data: &[u8],
)
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.
Sourcepub fn write_raw_buffer(&mut self, local_wal_buffer: &[u8])
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.
pub fn records(&self) -> &[WALRecord]
Sourcepub fn clear(&mut self) -> Result<()>
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.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn total_size(&self) -> usize
pub fn is_dirty(&self) -> bool
Sourcepub fn flush_to_disk(&mut self) -> Result<()>
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) │
└──────────────────────────────────────────────┘Sourcepub fn load_from_disk(&mut self) -> Result<()>
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§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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