Skip to main content

WALWriter

Struct WALWriter 

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

WAL writer for appending records to WAL file

Handles writing WAL records to disk with proper synchronization for crash recovery. Records are written in format:

[4 bytes: record size (little-endian u32)]
[N bytes: serialized record]

§Durability

Each record is followed by an optional fsync for durability. For performance, multiple records can be batched before syncing.

Implementations§

Source§

impl WALWriter

Source

pub fn new(wal_path: PathBuf, start_lsn: u64) -> NativeResult<Self>

Create a new WAL writer

§Arguments
  • wal_path - Path to WAL file
  • start_lsn - Starting LSN (default LSN_BEGIN for new WAL)
§Returns

Returns error if WAL file exists but cannot be read.

Source

pub fn current_lsn(&self) -> u64

Get current LSN

Source

pub fn committed_lsn(&self) -> u64

Get committed LSN

Source

pub fn write_header(&self) -> NativeResult<()>

Write WAL header (initializes new WAL file)

Source

pub fn append(&mut self, record: &V3WALRecord) -> NativeResult<()>

Append a record to WAL buffer

Record is buffered until flush() is called or buffer threshold is reached.

Source

pub fn flush(&mut self) -> NativeResult<()>

Flush buffered records to disk

Writes all buffered records and optionally syncs to disk.

Source

pub fn commit(&mut self) -> NativeResult<()>

Mark records up to current LSN as committed

Updates the committed_lsn in WAL header. Requires flush to persist the updated header.

Source

pub fn truncate(&self) -> NativeResult<()>

Truncate WAL file (after checkpoint)

Removes WAL records that are no longer needed.

Source

pub fn page_allocate(&mut self, page_id: u64) -> NativeResult<u64>

Write page allocate record

Source

pub fn page_free(&mut self, page_id: u64, checksum: u32) -> NativeResult<u64>

Write page free record

Source

pub fn page_write( &mut self, page_id: u64, offset: u32, data: Vec<u8>, ) -> NativeResult<u64>

Write page write record

Source

pub fn btree_split( &mut self, original_page_id: u64, new_page_id: u64, split_key: u64, page_type: bool, ) -> NativeResult<u64>

Write B+Tree split record

Source

pub fn checkpoint( &mut self, root_page_id: u64, total_pages: u64, btree_height: u32, free_page_list_head: u64, header: &PersistentHeaderV3, ) -> NativeResult<u64>

Write checkpoint record

Source

pub fn transaction_begin(&mut self, tx_id: u64) -> NativeResult<u64>

Write transaction begin record

Source

pub fn transaction_commit(&mut self, tx_id: u64) -> NativeResult<u64>

Write transaction commit record

Source

pub fn transaction_rollback(&mut self, tx_id: u64) -> NativeResult<u64>

Write transaction rollback record

Source

pub fn edge_insert( &mut self, src: i64, dst: i64, direction: u8, page_id: u64, ) -> NativeResult<u64>

Write edge insert record

Records an edge insertion for WAL replay during crash recovery. The edge will be inserted into the edge cluster during recovery.

Source

pub fn set_flush_threshold(&mut self, threshold: usize)

Set buffer flush threshold

Trait Implementations§

Source§

impl Debug for WALWriter

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V