raft_log/api/wal.rs
1//! Write-Ahead Log (WAL) module that provides interfaces for durable logging.
2//!
3//! The WAL is a critical component for maintaining data consistency and
4//! durability in distributed systems. It ensures that all state changes are
5//! first recorded persistently before being applied, enabling:
6//!
7//! - Crash recovery: System can recover its state by replaying the log
8//! - Consistency: Ordered record of all state transitions
9//! - Durability: Persistent storage of operations
10//!
11//! This module defines the core WAL trait that implementations must satisfy.
12
13use std::io;
14
15use crate::types::Segment;
16
17/// Write-Ahead Log (WAL) trait that provides durability and consistency
18/// guarantees for state machine operations.
19///
20/// The WAL ensures that all modifications are first recorded in a sequential
21/// log before being applied to the state machine. This provides crash recovery
22/// and helps maintain data consistency.
23///
24/// Type parameter `R` represents the record type that will be stored in the
25/// log.
26pub trait WAL<R> {
27 // type StateMachine: StateMachine<R>;
28
29 /// Appends a new record to the write-ahead log.
30 ///
31 /// This method provides durability by ensuring that records are written to
32 /// persistent storage before returning.
33 fn append(&mut self, rec: &R) -> Result<(), io::Error>;
34
35 /// Returns the segment representing the last record in the write-ahead log.
36 ///
37 /// A segment contains the offset and size of a record in the log file.
38 /// After appending a record, this method returns a segment describing the
39 /// location and length of that record in the WAL.
40 fn last_segment(&self) -> Segment;
41}