1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! # zlayer-consensus
//!
//! A shared Raft consensus library built on [openraft](https://docs.rs/openraft) 0.9.
//! Provides pluggable storage backends and network transports that can be
//! parameterized with any application's state machine types.
//!
//! Used by both **`ZLayer`** (container orchestration) and **Zatabase** (database replication).
//!
//! ## Quick Start
//!
//! ```ignore
//! use zlayer_consensus::{ConsensusNodeBuilder, ConsensusConfig};
//! use zlayer_consensus::storage::mem_store::{MemLogStore, MemStateMachine};
//! use zlayer_consensus::network::http_client::HttpNetwork;
//!
//! // 1. Define your TypeConfig
//! openraft::declare_raft_types!(
//! pub MyTypeConfig:
//! D = MyRequest,
//! R = MyResponse,
//! );
//!
//! // 2. Create storage
//! let log_store = MemLogStore::<MyTypeConfig>::new();
//! let sm = MemStateMachine::<MyTypeConfig, MyState, _>::new(|state, req| {
//! // apply request to state, return response
//! });
//!
//! // 3. Create network
//! let network = HttpNetwork::<MyTypeConfig>::new();
//!
//! // 4. Build the node
//! let node = ConsensusNodeBuilder::new(1, "127.0.0.1:9000".into())
//! .with_config(ConsensusConfig::default())
//! .build_with(log_store, sm, network)
//! .await?;
//!
//! // 5. Bootstrap (first node only)
//! node.bootstrap().await?;
//!
//! // 6. Propose writes
//! let response = node.propose(MyRequest::Set("key".into(), "value".into())).await?;
//! ```
//!
//! ## Feature Flags
//!
//! | Flag | Default | Description |
//! |------|---------|-------------|
//! | `mem-store` | yes | In-memory BTreeMap-based storage (testing/dev) |
//! | `redb-store` | no | Crash-safe persistent storage via redb |
// Re-export key items at the crate root for ergonomics.
pub use ConsensusConfig;
pub use ;
pub use ;
pub use ;
// Re-export openraft types that consumers will commonly need.
pub use openraft;