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
impl WriteAheadLog
sourcepub fn recover<AsRefPath: AsRef<Path>, Manager: LogManager>(
directory: AsRefPath,
manager: Manager
) -> Result<Self>
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.
sourcepub fn begin_entry(&self) -> Result<EntryWriter<'_>>
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.
sourcepub fn checkpoint_active(&self) -> Result<()>
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.
sourcepub fn read_at(&self, position: LogPosition) -> Result<ChunkReader<'_>>
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.
sourcepub fn shutdown(self) -> Result<()>
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
impl Clone for WriteAheadLog
source§fn clone(&self) -> WriteAheadLog
fn clone(&self) -> WriteAheadLog
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more