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,
impl<W> ChunkedWal<W>where
W: WalTypes,
Sourcepub fn open<SM>(
config: Arc<Config>,
state_machine: &mut SM,
on_chunk_persisted: ChunkPersistedFn<W>,
) -> Result<Self, Error>where
SM: StateMachine<W>,
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.
Sourcepub fn acquire_lock(config: &Config) -> Result<WalLock, Error>
pub fn acquire_lock(config: &Config) -> Result<WalLock, Error>
Acquires the exclusive WAL directory lock.
Sourcepub 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>,
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.
Sourcepub fn dump_records<D>(
config: &Config,
_dir_lock: &WalLock,
write_record: D,
) -> Result<(), Error>
pub fn dump_records<D>( config: &Config, _dir_lock: &WalLock, write_record: D, ) -> Result<(), Error>
Dumps all records while holding the WAL directory lock.
pub fn load_chunk_ids( config: &Config, _dir_lock: &WalLock, ) -> Result<Vec<ChunkId>, Error>
pub fn open_chunk_id(&self) -> ChunkId
pub fn closed_chunk_stats(&self) -> Vec<ChunkStat<W::Checkpoint>>
pub fn open_chunk_stat( &self, checkpoint: W::Checkpoint, ) -> ChunkStat<W::Checkpoint>
pub fn closed_chunk_reader(&self) -> ClosedChunkReader<W>
pub fn drain_closed_chunks_while<F>(&mut self, should_drain: F) -> Vec<ChunkId>
pub fn dump_loaded_records<D>(&self, write_record: D) -> Result<(), Error>
pub fn on_disk_size(&self) -> u64
pub fn last_closed_chunk_truncated_file_size(&self) -> Option<u64>
Sourcepub fn wait_worker_idle(&self)
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.
pub fn flush_metrics(&self) -> FlushMetrics
Sourcepub fn send_pending(
&mut self,
sync: bool,
callback: Option<W::Callback>,
) -> Result<(), Error>
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.
pub fn get_stat(&mut self) -> Result<Vec<FlushStat>, Error>
Sourcepub fn is_open_chunk_full(&self) -> bool
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.
Sourcepub fn try_close_full_chunk<SM>(
&mut self,
state_machine: &SM,
) -> Result<Option<W::Checkpoint>, Error>where
SM: StateMachine<W>,
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