pub struct RaftLog<T: Types> { /* private fields */ }Expand description
RaftLog is a Write-Ahead-Log implementation for the Raft consensus protocol.
It provides persistent storage for Raft log entries and state, with the following features:
- Append-only log storage with chunk-based organization
- In-memory caching of log payloads
- Exclusive file locking for thread-safe operations
- Support for log truncation and purging
- Statistics tracking for monitoring
Implementations§
Source§impl<T: Types> RaftLog<T>
impl<T: Types> RaftLog<T>
Sourcepub fn dump_data(&self) -> DumpRaftLog<T>
pub fn dump_data(&self) -> DumpRaftLog<T>
Dump the RaftLog data for debugging purposes.
Returns a DumpRaftLog struct containing a complete snapshot of the
RaftLog state.
Sourcepub fn dump(&self) -> RefDump<'_, T>
pub fn dump(&self) -> RefDump<'_, T>
Dump the WAL data in this Raft-log for debugging purposes.
This method returns a reference type RefDump containing the RaftLog
configuration and the RaftLog instance itself.
Sourcepub fn open(config: Arc<Config>) -> Result<Self, Error>
pub fn open(config: Arc<Config>) -> Result<Self, Error>
Opens a RaftLog at the specified directory.
This operation:
- Acquires an exclusive lock on the directory
- Loads existing chunks in order
- Replays WAL records to rebuild the state
- Creates a new open chunk for future writes
§Errors
Returns an error if:
- Directory operations fail
- There are gaps between chunk offsets
- WAL records are invalid
pub fn load_chunk_ids(config: &Config) -> Result<Vec<ChunkId>, Error>
Sourcepub fn update_state(&mut self, state: RaftLogState<T>) -> Result<Segment, Error>
pub fn update_state(&mut self, state: RaftLogState<T>) -> Result<Segment, Error>
Update the RaftLog state.
This method updates the RaftLog state with a new state and appends it to the WAL.
Sourcepub fn read(
&self,
from: u64,
to: u64,
) -> impl Iterator<Item = Result<(T::LogId, T::LogPayload), Error>> + '_
pub fn read( &self, from: u64, to: u64, ) -> impl Iterator<Item = Result<(T::LogId, T::LogPayload), Error>> + '_
Reads log entries in the specified index range.
Returns an iterator over log entries, attempting to serve them from cache first, falling back to disk reads if necessary.
Sourcepub fn log_state(&self) -> &RaftLogState<T>
pub fn log_state(&self) -> &RaftLogState<T>
Get a reference to the latest RaftLog state.
The state is the latest state of the RaftLog, even if the corresponding WAL record is not committed yet.
Sourcepub fn stat(&self) -> Stat<T>
pub fn stat(&self) -> Stat<T>
Get a reference to the RaftLog statistics.
This method returns a Stat struct containing statistics about the
RaftLog, including:
- The number of closed chunks
- The open chunk statistics
Sourcepub fn access_stat(&self) -> &AccessStat
pub fn access_stat(&self) -> &AccessStat
Get a reference to the access statistics.
This method returns a reference to the AccessStat struct, which
contains statistics about the access patterns of the RaftLog.
Sourcepub fn wait_worker_idle(&self)
pub fn wait_worker_idle(&self)
Block until the FlushWorker has processed all queued requests.
After this returns, all file writes, syncs, and cache eviction boundary
updates issued before this call are complete. Note that the payload
cache item count may still be non-deterministic because eviction is
lazy; call drain_cache_evictable() afterwards to normalize it.
Sourcepub fn drain_cache_evictable(&self)
pub fn drain_cache_evictable(&self)
Drain all evictable entries from the payload cache.
Call after wait_worker_idle() to normalize the cache to a
deterministic state. See PayloadCache::drain_evictable for details.
Sourcepub fn on_disk_size(&self) -> u64
pub fn on_disk_size(&self) -> u64
Returns the current size of the log on disk in bytes.
This includes all closed chunks and the open chunk, measuring from the start of the earliest chunk to the end of the open chunk.
Trait Implementations§
Source§impl<T: Types> RaftLogWriter<T> for RaftLog<T>
impl<T: Types> RaftLogWriter<T> for RaftLog<T>
Source§fn truncate(&mut self, index: u64) -> Result<Segment, Error>
fn truncate(&mut self, index: u64) -> Result<Segment, Error>
Truncate at index, keep the record before index.