praborrow_lease/
lib.rs

1//! Lease Consensus Logic
2//!
3//! This crate implements the consensus algorithms required to agree on Lease Validity.
4//!
5//! # Features
6//!
7//! - `std` - Enable standard library (includes tokio)
8//! - `net` - Enable networking (UDP transport)
9//! - `grpc` - Enable gRPC transport with tonic
10//! - `tls` - Enable TLS/mTLS support
11//! - `observability` - Enable Prometheus metrics
12//! - `full` - Enable all features
13//!
14//! # Architecture
15//!
16//! ```text
17//! ┌─────────────────────────────────────────────────────────────┐
18//! │                     ConsensusEngine                         │
19//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
20//! │  │  RaftEngine │  │ RaftNetwork │  │ ReplicatedStateMachine│ │
21//! │  └─────────────┘  └─────────────┘  └─────────────────────┘ │
22//! │         │               │                    │              │
23//! │         ▼               ▼                    ▼              │
24//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
25//! │  │ RaftStorage │  │GrpcTransport│  │   StateMachine      │ │
26//! │  │ (Sled/Mem)  │  │ (or InMem)  │  │   (User-defined)    │ │
27//! │  └─────────────┘  └─────────────┘  └─────────────────────┘ │
28//! └─────────────────────────────────────────────────────────────┘
29//! ```
30
31pub mod builder;
32pub mod deadlock;
33pub mod engine;
34mod manager;
35pub mod metrics;
36pub mod network;
37pub mod raft;
38pub mod state_machine;
39
40#[cfg(feature = "grpc")]
41pub mod grpc;
42
43#[cfg(test)]
44mod cluster_test;
45
46// ============================================================================
47// RE-EXPORTS
48// ============================================================================
49
50pub use manager::LeaseManager;
51
52// Engine exports
53pub use engine::{
54    ConsensusEngine, ConsensusError, ConsensusFactory, ConsensusStrategy, RaftConfig, RaftEngine,
55};
56
57// Network exports
58pub use network::{
59    ConsensusNetwork, InMemoryNetwork, NetworkConfig, NetworkError, Packet, PeerInfo, RaftMessage,
60    RaftNetwork,
61};
62
63// Metrics exports
64pub use metrics::{RaftMetrics, RaftRoleMetric};
65
66// Raft core exports
67pub use raft::{
68    FileStorage, InMemoryStorage, LogEntry, LogIndex, LogInfo, NodeId, RaftNode, RaftRole,
69    RaftStorage, Snapshot, StorageStats, Term,
70};
71
72// State machine exports
73pub use state_machine::{
74    KeyValueStateMachine, KvCommand, KvOutput, NoOpStateMachine, ReplicatedStateMachine,
75    StateMachine,
76};
77
78// gRPC exports (when feature enabled)
79#[cfg(feature = "grpc")]
80pub use grpc::{
81    CircuitBreaker, CircuitBreakerConfig, CircuitState, ConnectionPool, GrpcConfig, GrpcTransport,
82    TlsConfig, start_grpc_server,
83};
84
85// ============================================================================
86// PRELUDE
87// ============================================================================
88
89/// Convenient imports for common use cases.
90pub mod prelude {
91    pub use crate::{
92        ConsensusEngine, ConsensusError, FileStorage, InMemoryNetwork, InMemoryStorage,
93        KeyValueStateMachine, LogEntry, LogIndex, NodeId, RaftConfig, RaftEngine, RaftMessage,
94        RaftNetwork, RaftStorage, ReplicatedStateMachine, StateMachine, Term,
95    };
96}