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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! # d-engine-server
//!
//! Complete Raft server with gRPC and storage - batteries included
//!
//! ## When to use this crate directly
//!
//! - ✅ Embedding server in a larger Rust application
//! - ✅ Need programmatic access to server APIs
//! - ✅ Building custom tooling around d-engine
//! - ✅ Already have your own client implementation
//!
//! ## When to use `d-engine` instead
//!
//! Most users should use [`d-engine`](https://crates.io/crates/d-engine):
//!
//! ```toml
//! [dependencies]
//! d-engine = { version = "0.2", features = ["server"] }
//! ```
//!
//! It re-exports this crate plus optional client libraries with simpler dependency management.
//!
//! ## Quick Start
//!
//! **Embedded Mode** (zero-overhead local client):
//!
//! ```rust,ignore
//! use d_engine_server::EmbeddedEngine;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let engine = EmbeddedEngine::start_with("config.toml").await?;
//! engine.wait_ready(Duration::from_secs(5)).await?;
//!
//! let client = engine.client();
//! client.put(b"key".to_vec(), b"value".to_vec()).await?;
//!
//! engine.stop().await?;
//! Ok(())
//! }
//! ```
//!
//! **Standalone Mode** (independent server):
//!
//! ```rust,ignore
//! use d_engine_server::StandaloneServer;
//! use tokio::sync::watch;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! std::env::set_var("CONFIG_PATH", "config.toml");
//! let (_shutdown_tx, shutdown_rx) = watch::channel(());
//! StandaloneServer::run(shutdown_rx).await?;
//! Ok(())
//! }
//! ```
//!
//! ## Features
//!
//! This crate provides:
//! - **gRPC Server** - Production-ready Raft RPC implementation
//! - **Storage Backends** - File-based and RocksDB storage
//! - **Cluster Orchestration** - Node lifecycle and membership management
//! - **Snapshot Coordination** - Automatic log compaction
//! - **Watch API** - Real-time state change notifications
//!
//! ## Custom Storage
//!
//! Implement the [`StateMachine`] and [`StorageEngine`] traits:
//!
//! ```rust,ignore
//! use d_engine_server::{StateMachine, StorageEngine};
//!
//! struct MyStateMachine;
//! impl StateMachine for MyStateMachine {
//! // Apply committed entries to your application state
//! }
//!
//! struct MyStorageEngine;
//! impl StorageEngine for MyStorageEngine {
//! // Persist Raft logs and metadata
//! }
//! ```
//!
//! ## Documentation
//!
//! For comprehensive guides:
//! - [Customize Storage Engine](https://docs.rs/d-engine/latest/d_engine/docs/server_guide/customize_storage_engine/index.html)
//! - [Customize State Machine](https://docs.rs/d-engine/latest/d_engine/docs/server_guide/customize_state_machine/index.html)
//! - [Watch Feature Guide](https://docs.rs/d-engine/latest/d_engine/docs/server_guide/watch_feature/index.html)
// ==================== Core Public API ====================
/// Node lifecycle management
///
/// Contains [`Node`] and [`NodeBuilder`] for server setup.
/// Public API layer for different deployment modes
///
/// Contains [`EmbeddedEngine`] and [`StandaloneServer`].
// Re-export LeaderInfo from d-engine-core
pub use LeaderInfo;
/// Storage layer implementations
///
/// Provides file-based and RocksDB storage backends.
// -------------------- Primary Entry Points --------------------
pub use EmbeddedEngine;
pub use StandaloneEngine;
// -------------------- Error Types --------------------
/// Unified error type for all d-engine operations
pub use Error;
/// Hard state (Raft persistent state: term, voted_for, log)
pub use HardState;
/// Log storage trait
pub use LogStore;
/// Metadata storage trait
pub use MetaStore;
/// Protocol buffer error type
pub use ProstError;
/// Unified result type (equivalent to Result<T, Error>)
pub use Result;
/// Snapshot operation error type
pub use SnapshotError;
/// Storage-specific error type
pub use StorageError;
// -------------------- Extension Traits --------------------
pub use EmbeddedClient;
/// Storage trait for implementing custom storage backends
///
/// Implement this trait to create your own storage engine.
pub use ;
pub use Node;
pub use NodeBuilder;
// Re-export storage implementations
pub use ;
// Re-export core types needed by applications
pub use ApplyResult;
// Conditional RocksDB exports
pub use ;
// -------------------- Data Types --------------------
/// Common Raft protocol types
/// Client protocol types
/// Server storage protocol types
// ==================== Internal API (Hidden) ====================
pub use Raft;
// ==================== Test Utilities ====================
/// Test utilities for d-engine-server
///
/// This module is only available when running tests.
///
/// Contains mock implementations and test helpers.
pub