pub struct RaftConfig {
pub node_id: NodeId,
pub peers: Vec<NodeId>,
pub election_timeout_range: (u64, u64),
pub heartbeat_interval: u64,
pub max_entries_per_message: usize,
pub enable_compaction: bool,
pub snapshot_threshold: u64,
pub max_snapshots: usize,
pub snapshot_dir: Option<PathBuf>,
pub persistence_dir: Option<PathBuf>,
pub wal_dir: Option<PathBuf>,
pub sync_on_write: bool,
}Expand description
Configuration for a Raft node
Fields§
§node_id: NodeIdThis node’s ID
peers: Vec<NodeId>List of all peer node IDs (including this node)
election_timeout_range: (u64, u64)Election timeout range (min, max) in milliseconds
heartbeat_interval: u64Heartbeat interval in milliseconds
max_entries_per_message: usizeMaximum number of entries to send in a single AppendEntries RPC
enable_compaction: boolWhether to enable log compaction
snapshot_threshold: u64Snapshot threshold (number of log entries before triggering snapshot)
max_snapshots: usizeMaximum number of snapshots to retain on disk
snapshot_dir: Option<PathBuf>Directory for storing snapshots (None = snapshots disabled on disk)
persistence_dir: Option<PathBuf>Directory for Raft persistent state and log (None = in-memory only)
wal_dir: Option<PathBuf>Directory for segment-based WAL replay on startup (None = WAL replay disabled)
sync_on_write: boolWhether to fsync after every persistent write (default: true)
Implementations§
Source§impl RaftConfig
impl RaftConfig
Sourcepub fn new(node_id: NodeId, peers: Vec<NodeId>) -> Self
pub fn new(node_id: NodeId, peers: Vec<NodeId>) -> Self
Create a new Raft configuration with sensible defaults
Sourcepub fn random_election_timeout(&self) -> Duration
pub fn random_election_timeout(&self) -> Duration
Get a random election timeout within the configured range
Sourcepub fn heartbeat_interval(&self) -> Duration
pub fn heartbeat_interval(&self) -> Duration
Get the heartbeat interval
Sourcepub fn quorum_size(&self) -> usize
pub fn quorum_size(&self) -> usize
Calculate the quorum size (majority)
Trait Implementations§
Source§impl Clone for RaftConfig
impl Clone for RaftConfig
Source§fn clone(&self) -> RaftConfig
fn clone(&self) -> RaftConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more