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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//! # 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::StandaloneEngine;
//! use tokio::sync::watch;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let (_shutdown_tx, shutdown_rx) = watch::channel(());
//! StandaloneEngine::run("./data", 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 ====================
/// Proto ↔ core type conversions — the single place that bridges gRPC and core types.
/// Node lifecycle management
///
/// Contains [`Node`] and [`NodeBuilder`] for server setup.
/// Public API layer for different deployment modes
///
/// Contains [`EmbeddedEngine`] and [`StandaloneEngine`].
// 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;
pub use MembershipSnapshot;
// -------------------- Error Types --------------------
/// Unified error type for all d-engine operations
pub use Error;
/// Log storage trait
pub use LogStore;
/// Metadata storage trait
pub use MetaStore;
/// Unified result type (equivalent to Result<T, Error>)
pub use Result;
/// Prefix scan result: matching entries + revision anchor for watch deduplication
pub use ScanResult;
/// Storage-specific error type
pub use StorageError;
// Internal types required by storage implementations — not part of user API
pub use HardState;
pub use ProstError;
pub use SnapshotError;
// -------------------- Client API --------------------
pub use EmbeddedClient;
/// Error code discriminator returned by [`ClientApiError::code()`].
/// Use this to pattern-match error categories without inspecting message strings:
/// `e.code() == ErrorCode::NotLeader`
pub use ErrorCode;
/// Unified client operations trait (put/get/delete/CAS/watch).
/// Re-exported here so embedded-mode users don't need a separate d-engine-client dependency.
pub use ;
/// 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;
pub use ;
// Conditional RocksDB exports
pub use ;
// -------------------- Watch API Types --------------------
/// Watch event types and handles — available when the `watch` feature is enabled.
///
/// Use these when implementing embedded watch handlers:
/// ```rust,ignore
/// use d_engine::{WatchEventType, WatcherHandle, WatchEvent};
/// ```
pub use ;
// -------------------- Data Types --------------------
/// Common Raft protocol types
/// Client protocol types
/// Server storage protocol types
// ==================== Internal API (Hidden) ====================
// ==================== Test Utilities ====================
/// Standardized test suite for custom [`StateMachine`] implementations.
///
/// Enable the `__test_support` feature in your `[dev-dependencies]` to access this module:
/// ```toml
/// [dev-dependencies]
/// d-engine = { version = "...", features = ["server", "__test_support"] }
/// ```
pub use state_machine_test;
/// Standardized test suite for custom [`StorageEngine`] implementations.
///
/// Enable the `__test_support` feature in your `[dev-dependencies]` to access this module:
/// ```toml
/// [dev-dependencies]
/// d-engine = { version = "...", features = ["server", "__test_support"] }
/// ```
pub use storage_engine_test;
/// Test utilities for d-engine-server
///
/// This module is only available when running tests.
///
/// Contains mock implementations and test helpers.
pub