Struct okaywal::WriteAheadLog

source ·
pub struct WriteAheadLog { /* private fields */ }
Expand description

A Write-Ahead Log that provides atomic and durable writes.

This type implements Clone and can be passed between multiple threads safely.

When WriteAheadLog::begin_entry() is called, an exclusive lock to the active log segment is acquired. The lock is released when the entry is rolled back or once the entry is in queue for synchronization during EntryWriter::commit().

Multiple threads may be queued for synchronization at any given time. This allows good multi-threaded performance in spite of only using a single active file.

Implementations§

source§

impl WriteAheadLog

source

pub fn recover<AsRefPath: AsRef<Path>, Manager: LogManager>( directory: AsRefPath, manager: Manager ) -> Result<Self>

Creates or opens a log in directory using the provided log manager to drive recovery and checkpointing.

source

pub fn begin_entry(&self) -> Result<EntryWriter<'_>>

Begins writing an entry to this log.

A new unique entry id will be allocated for the entry being written. If the entry is rolled back, the entry id will not be reused. The entry id can be retrieved through EntryWriter::id().

This call will acquire an exclusive lock to the active file or block until it can be acquired.

source

pub fn checkpoint_active(&self) -> Result<()>

Checkpoint the currently active file immediately, regardless of its size.

A new logfile is immediately made active for subsequent writes, and the currently active logfile is sent to the checkpoint thread for immediate background checkpointing.

This call will acquire an exclusive lock to the active file or block until it can be acquired.

source

pub fn read_at(&self, position: LogPosition) -> Result<ChunkReader<'_>>

Opens the log to read previously written data.

Errors

May error if:

  • The file cannot be read.
  • The position refers to data that has been checkpointed.
source

pub fn shutdown(self) -> Result<()>

Waits for all other instances of WriteAheadLog to be dropped and for the checkpointing thread to complete.

This call will not interrupt any writers, and will block indefinitely if another instance of this WriteAheadLog exists and is not eventually dropped. This was is the safest to implement, and because a WAL is primarily used in front of another storage layer, it follows that the shutdown logic of both layers should be synchronized.

Trait Implementations§

source§

impl Clone for WriteAheadLog

source§

fn clone(&self) -> WriteAheadLog

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WriteAheadLog

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.