Skip to main content

ChunkedWal

Struct ChunkedWal 

Source
pub struct ChunkedWal<W>
where W: WalTypes,
{ /* private fields */ }
Expand description

Chunked write-ahead log implementation.

This WAL implementation manages both open and closed chunks of data. An open chunk is actively being written to, while closed chunks are immutable and may be used for reading historical data.

Implementations§

Source§

impl<W> ChunkedWal<W>
where W: WalTypes,

Source

pub fn open<SM>( config: Arc<Config>, state_machine: &mut SM, on_chunk_persisted: ChunkPersistedFn<W>, ) -> Result<Self, Error>
where SM: StateMachine<W>,

Opens a ChunkedWal instance and replays existing records into a state machine.

Source

pub fn acquire_lock(config: &Config) -> Result<WalLock, Error>

Acquires the exclusive WAL directory lock.

Source

pub fn open_locked<SM>( config: Arc<Config>, state_machine: &mut SM, on_chunk_persisted: ChunkPersistedFn<W>, dir_lock: WalLock, ) -> Result<Self, Error>
where SM: StateMachine<W>,

Opens a ChunkedWal instance with an already-held WAL directory lock.

Source

pub fn dump_records<D>( config: &Config, _dir_lock: &WalLock, write_record: D, ) -> Result<(), Error>

Dumps all records while holding the WAL directory lock.

Source

pub fn load_chunk_ids( config: &Config, _dir_lock: &WalLock, ) -> Result<Vec<ChunkId>, Error>

Source

pub fn open_chunk_id(&self) -> ChunkId

Source

pub fn closed_chunk_stats(&self) -> Vec<ChunkStat<W::Checkpoint>>

Source

pub fn open_chunk_stat( &self, checkpoint: W::Checkpoint, ) -> ChunkStat<W::Checkpoint>

Source

pub fn closed_chunk_reader(&self) -> ClosedChunkReader<W>

Source

pub fn drain_closed_chunks_while<F>(&mut self, should_drain: F) -> Vec<ChunkId>
where F: FnMut(&W::Checkpoint) -> bool,

Source

pub fn dump_loaded_records<D>(&self, write_record: D) -> Result<(), Error>

Source

pub fn on_disk_size(&self) -> u64

Source

pub fn last_closed_chunk_truncated_file_size(&self) -> Option<u64>

Source

pub fn wait_worker_idle(&self)

Block until the FlushWorker has processed all requests sent so far.

Polls done_seq in a 1 ms sleep loop until it reaches sent_seq.

Source

pub fn flush_metrics(&self) -> FlushMetrics

Source

pub fn send_pending( &mut self, sync: bool, callback: Option<W::Callback>, ) -> Result<(), Error>

Hand the pending data buffer to the worker for writing.

Drains OpenChunk::pending_data and packages it as a WriteRequest. The worker always writes the bytes to the OS file. When sync is true it also calls fsync so the data is on stable storage; when sync is false it skips the fsync and durability is deferred to the next sync write that lands in the same or a later batch.

Source

pub fn send_remove_chunks( &mut self, chunk_ids: Vec<ChunkId>, ) -> Result<(), Error>

Requests removal of specified chunks.

§Arguments
  • chunk_ids - IDs of chunk files to be removed
§Errors

Returns an IO error if the remove request cannot be sent

Source

pub fn get_stat(&mut self) -> Result<Vec<FlushStat>, Error>

Source

pub fn is_open_chunk_full(&self) -> bool

Checks if the current open chunk has reached its capacity.

Returns true if either the maximum number of records or maximum chunk size is reached.

Source

pub fn try_close_full_chunk<SM>( &mut self, state_machine: &SM, ) -> Result<Option<W::Checkpoint>, Error>
where SM: StateMachine<W>,

Attempts to close the current chunk if it’s full and creates a new open chunk.

§Arguments
  • state_machine - The state machine that provides the checkpoint to store at the start of the next chunk.
§Returns

Returns the checkpoint if a chunk was closed, None otherwise.

§Errors

Returns an IO error if chunk operations fail

Source

pub fn load_record( &self, chunk_id: &ChunkId, segment: Segment, ) -> Result<WALRecord<W>, Error>

Loads a record from a closed chunk.

§Arguments
  • log_data - Metadata about the log entry to load
§Returns

Returns the log payload if found

§Errors

Returns an IO error if the chunk is not found or reading fails

Trait Implementations§

Source§

impl<W> Debug for ChunkedWal<W>
where W: WalTypes,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W> WAL<WALRecord<W>> for ChunkedWal<W>
where W: WalTypes,

Source§

fn append(&mut self, rec: &WALRecord<W>) -> Result<(), Error>

Appends a new record to the write-ahead log. Read more
Source§

fn last_segment(&self) -> Segment

Returns the segment representing the last record in the write-ahead log. Read more

Auto Trait Implementations§

§

impl<W> Freeze for ChunkedWal<W>

§

impl<W> !RefUnwindSafe for ChunkedWal<W>

§

impl<W> Send for ChunkedWal<W>

§

impl<W> Sync for ChunkedWal<W>
where <W as WalTypes>::Action: Sync,

§

impl<W> Unpin for ChunkedWal<W>
where <W as WalTypes>::Action: Unpin, <W as WalTypes>::Checkpoint: Unpin,

§

impl<W> UnsafeUnpin for ChunkedWal<W>

§

impl<W> !UnwindSafe for ChunkedWal<W>

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