1pub mod election;
8pub mod log;
9pub mod node;
10pub mod rpc;
11pub mod state;
12
13pub use node::{RaftNode, RaftNodeConfig};
14pub use rpc::{
15 AppendEntriesRequest, AppendEntriesResponse, InstallSnapshotRequest, InstallSnapshotResponse,
16 RequestVoteRequest, RequestVoteResponse,
17};
18pub use state::{LeaderState, PersistentState, RaftState, VolatileState};
19
20use thiserror::Error;
21
22pub type RaftResult<T> = Result<T, RaftError>;
24
25#[derive(Debug, Error)]
27pub enum RaftError {
28 #[error("Node is not the leader")]
29 NotLeader,
30
31 #[error("No leader available")]
32 NoLeader,
33
34 #[error("Invalid term: {0}")]
35 InvalidTerm(u64),
36
37 #[error("Invalid log index: {0}")]
38 InvalidLogIndex(u64),
39
40 #[error("Serialization error: {0}")]
41 SerializationEncodeError(#[from] bincode::error::EncodeError),
42
43 #[error("Deserialization error: {0}")]
44 SerializationDecodeError(#[from] bincode::error::DecodeError),
45
46 #[error("IO error: {0}")]
47 IoError(#[from] std::io::Error),
48
49 #[error("Election timeout")]
50 ElectionTimeout,
51
52 #[error("Log inconsistency detected")]
53 LogInconsistency,
54
55 #[error("Snapshot installation failed: {0}")]
56 SnapshotFailed(String),
57
58 #[error("Configuration error: {0}")]
59 ConfigError(String),
60
61 #[error("Internal error: {0}")]
62 Internal(String),
63}
64
65pub type NodeId = String;
67
68pub type Term = u64;
70
71pub type LogIndex = u64;