pub struct WalLog { /* private fields */ }Available on crate feature
persistence only.Expand description
A durable RaftLog whose entries and hard state survive a process restart.
Open it with open and hand it to
RaftNode::with_log. Reads are served from an
in-memory index; writes are appended to the underlying wal-db log and
become durable when sync returns Ok.
§Examples
use raft_io::{LogEntry, RaftLog, WalLog};
let mut log = WalLog::open("raft.wal")?;
log.append(&[LogEntry::new(1, 1, b"set x = 1".to_vec())])?;
log.sync()?; // durable from here
// After a restart, reopening the same path recovers the entry.
let recovered = WalLog::open("raft.wal")?;
assert_eq!(recovered.last_index(), 1);Implementations§
Source§impl WalLog
impl WalLog
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens the durable log at path, replaying any existing records to recover
the log entries and hard state.
Creates the file if it does not exist. Recovery is exact: the recovered state is the logical result of every mutation that was appended before the process stopped.
§Errors
Returns Error::Storage if the WAL cannot be opened or a record fails
to decode (for example, a checksum mismatch reported by wal-db).
Trait Implementations§
Source§impl RaftLog for WalLog
impl RaftLog for WalLog
Source§fn last_index(&self) -> Index
fn last_index(&self) -> Index
Returns the index of the last entry, or
0 if the log is empty.Source§fn term_at(&self, index: Index) -> Option<Term>
fn term_at(&self, index: Index) -> Option<Term>
Returns the term of the entry at
index. Read moreSource§fn entry(&self, index: Index) -> Option<LogEntry>
fn entry(&self, index: Index) -> Option<LogEntry>
Returns the entry at
index, or None if there is none.Source§fn entries(&self, from: Index, to: Index) -> Vec<LogEntry>
fn entries(&self, from: Index, to: Index) -> Vec<LogEntry>
Returns the entries in the inclusive index range
[from, to]. Read moreSource§fn append(&mut self, entries: &[LogEntry]) -> Result<()>
fn append(&mut self, entries: &[LogEntry]) -> Result<()>
Appends
entries to the end of the log. Read moreSource§fn truncate(&mut self, from: Index) -> Result<()>
fn truncate(&mut self, from: Index) -> Result<()>
Removes every entry whose index is
>= from. Read moreSource§fn hard_state(&self) -> HardState
fn hard_state(&self) -> HardState
Returns the persisted
HardState (current term and vote).Source§fn snapshot_index(&self) -> Index
fn snapshot_index(&self) -> Index
Returns the index the log has been compacted up to — the last index a
snapshot includes — or
0 if there is no snapshot. Read moreAuto Trait Implementations§
impl !Freeze for WalLog
impl RefUnwindSafe for WalLog
impl Send for WalLog
impl Sync for WalLog
impl Unpin for WalLog
impl UnsafeUnpin for WalLog
impl UnwindSafe for WalLog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more