pub struct WalWriter { /* private fields */ }Expand description
Appends LogEntry values to a segment-based WAL on disk.
Segment files are named wal-{segment_id:08}.seg inside the configured
directory. When the current segment exceeds
max_segment_size a new segment is
created automatically.
Implementations§
Source§impl WalWriter
impl WalWriter
Sourcepub fn new(
dir: &Path,
sync_mode: SyncMode,
max_segment_size: u64,
) -> RaftResult<Self>
pub fn new( dir: &Path, sync_mode: SyncMode, max_segment_size: u64, ) -> RaftResult<Self>
Create a new writer rooted at dir.
The directory is created if it does not exist. Any existing segments are discovered so that new writes continue from the latest segment.
Sourcepub fn append(&mut self, entry: &LogEntry) -> RaftResult<()>
pub fn append(&mut self, entry: &LogEntry) -> RaftResult<()>
Append a single log entry to the WAL.
Rotates to a new segment when the current one exceeds the configured
maximum size. Calls fsync according to the configured
SyncMode.
Sourcepub fn sync(&mut self) -> RaftResult<()>
pub fn sync(&mut self) -> RaftResult<()>
Force an fsync on the current segment, regardless of SyncMode.
Sourcepub fn truncate_from(&mut self, from_index: LogIndex) -> RaftResult<()>
pub fn truncate_from(&mut self, from_index: LogIndex) -> RaftResult<()>
Truncate all entries with index >= from_index.
This rewrites segment files, removing entries at or beyond the given index. After truncation the writer re-opens the last remaining segment (or creates a fresh one if all entries were removed).