Skip to main content

amaters_cluster/
lib.rs

1//! Consensus layer for AmateRS (Ukehi - The Sacred Pledge)
2//!
3//! This crate implements Raft consensus with support for encrypted logs
4//! and distributed cluster management.
5//!
6//! ## Architecture
7//!
8//! The consensus layer consists of:
9//!
10//! - **Raft Node**: Core consensus implementation with leader election and log replication
11//! - **Log Management**: Persistent log with in-memory cache and compaction
12//! - **State Management**: Persistent and volatile state tracking
13//! - **RPC Layer**: Request/response messages for inter-node communication
14//!
15//! ## Example
16//!
17//! ```rust,ignore
18//! use amaters_cluster::{RaftNode, RaftConfig, Command};
19//!
20//! // Create a 3-node cluster
21//! let config = RaftConfig::new(1, vec![1, 2, 3]);
22//! let node = RaftNode::new(config)?;
23//!
24//! // Propose a command (as leader)
25//! let cmd = Command::from_str("SET key value");
26//! let index = node.propose(cmd)?;
27//! ```
28
29pub mod encryption;
30pub mod error;
31pub mod failover;
32pub mod heartbeat;
33pub mod log;
34pub mod metrics;
35pub mod node;
36pub mod persistence;
37pub mod rpc;
38pub mod snapshot;
39pub mod state;
40pub mod types;
41pub mod wal;
42// Re-exports for convenience
43pub use encryption::{EncryptedPayload, EntryEncryptor, LogEncryptionKey, LogIntegrityVerifier};
44pub use error::{RaftError, RaftResult};
45pub use failover::{FailoverConfig, FailoverCoordinator, FailoverEvent};
46pub use heartbeat::FailureDetector;
47pub use log::{ApplyResult, Command, LogEntry, RaftLog, SnapshotData, StateMachine};
48pub use metrics::ClusterMetrics;
49pub use node::RaftNode;
50pub use persistence::{FilePersistence, MemoryPersistence, RaftPersistence};
51pub use rpc::{
52    AppendEntriesRequest, AppendEntriesResponse, RequestVoteRequest, RequestVoteResponse,
53};
54pub use snapshot::{
55    DiskSnapshotStore, InstallSnapshotRequest, InstallSnapshotResponse, Snapshot, SnapshotConfig,
56    SnapshotManager, SnapshotMetadata, SnapshotPolicy, SnapshotReceiver, SnapshotStore,
57};
58pub use state::{CandidateState, FencingTokenState, LeaderState, PersistentState, VolatileState};
59pub use types::{
60    ClusterConfig, ConfigState, FailureEvent, FencingToken, HeartbeatConfig, LogIndex,
61    MembershipChange, NodeId, NodeState, RaftConfig, Term,
62};
63pub use wal::{CorruptionPolicy, SyncMode, WalDiagnostics, WalReader, WalWriter};
64
65/// Library version
66pub const VERSION: &str = env!("CARGO_PKG_VERSION");
67
68/// Library name
69pub const NAME: &str = env!("CARGO_PKG_NAME");