pub struct NodeBuilder<SE, SM>{ /* private fields */ }Expand description
Builder for creating a Raft node
Provides a fluent API for configuring and constructing a Node.
§Example
use d_engine_server::{NodeBuilder, FileStorageEngine, FileStateMachine};
let node = NodeBuilder::new(None, shutdown_rx)
.storage_engine(Arc::new(FileStorageEngine::new(...)?))
.state_machine(Arc::new(FileStateMachine::new(...).await?))
.start().await?;Implementations§
Source§impl<SE, SM> NodeBuilder<SE, SM>
impl<SE, SM> NodeBuilder<SE, SM>
Sourcepub fn new(
cluster_path: Option<&str>,
shutdown_signal: Receiver<()>,
) -> NodeBuilder<SE, SM>
pub fn new( cluster_path: Option<&str>, shutdown_signal: Receiver<()>, ) -> NodeBuilder<SE, SM>
Sourcepub fn from_cluster_config(
cluster_config: ClusterConfig,
shutdown_signal: Receiver<()>,
) -> NodeBuilder<SE, SM>
pub fn from_cluster_config( cluster_config: ClusterConfig, shutdown_signal: Receiver<()>, ) -> NodeBuilder<SE, SM>
Sourcepub fn from_node_config(
node_config: RaftNodeConfig,
shutdown_signal: Receiver<()>,
) -> NodeBuilder<SE, SM>
pub fn from_node_config( node_config: RaftNodeConfig, shutdown_signal: Receiver<()>, ) -> NodeBuilder<SE, SM>
Constructs NodeBuilder from a fully-built RaftNodeConfig.
Use this when you have already assembled a complete RaftNodeConfig and
want to avoid the implicit RaftNodeConfig::new() + validate() call
that new performs internally before applying your
config. That detour can panic in environments where no default config
file or environment variables are present.
§Arguments
node_config- Fully assembled and validated node configurationshutdown_signal- Watch channel for graceful shutdown signaling
§Usage
let config: RaftNodeConfig = /* build and validate your config */;
let builder = NodeBuilder::from_node_config(config, shutdown_rx);Sourcepub fn storage_engine(self, storage_engine: Arc<SE>) -> NodeBuilder<SE, SM>
pub fn storage_engine(self, storage_engine: Arc<SE>) -> NodeBuilder<SE, SM>
Sets a custom storage engine implementation
Sourcepub fn state_machine(self, state_machine: Arc<SM>) -> NodeBuilder<SE, SM>
pub fn state_machine(self, state_machine: Arc<SM>) -> NodeBuilder<SE, SM>
Sets a custom state machine implementation
Sourcepub fn node_config(self, node_config: RaftNodeConfig) -> NodeBuilder<SE, SM>
pub fn node_config(self, node_config: RaftNodeConfig) -> NodeBuilder<SE, SM>
Replaces the entire node configuration
Sourcepub fn raft_config(self, config: RaftConfig) -> NodeBuilder<SE, SM>
pub fn raft_config(self, config: RaftConfig) -> NodeBuilder<SE, SM>
Replaces the raft configuration
Sourcepub async fn build(self) -> Result<NodeBuilder<SE, SM>, Error>
pub async fn build(self) -> Result<NodeBuilder<SE, SM>, Error>
Finalizes the builder and constructs the Raft node instance.
Initializes default implementations for any unconfigured components:
- Creates file-based databases for state machine and logs
- Sets up default gRPC transport
- Initializes commit handling subsystem
- Configures membership management
§Panics
Panics if essential components cannot be initialized
Sourcepub fn with_custom_state_machine_handler(
self,
handler: Arc<<RaftTypeConfig<SE, SM> as TypeConfig>::SMH>,
) -> NodeBuilder<SE, SM>
pub fn with_custom_state_machine_handler( self, handler: Arc<<RaftTypeConfig<SE, SM> as TypeConfig>::SMH>, ) -> NodeBuilder<SE, SM>
Sets a custom state machine handler implementation.
Allows providing a custom implementation that processes committed log entries
and applies them to the state machine. If not set, a default implementation
is used during build().
§Arguments
handler- custom handler implementing theStateMachineHandlertrait
§Notes
- The handler must be thread-safe (shared across threads via
Arc) - The handler must correctly handle snapshot creation and restoration
Sourcepub async fn start(self) -> Result<Arc<Node<RaftTypeConfig<SE, SM>>>, Error>
pub async fn start(self) -> Result<Arc<Node<RaftTypeConfig<SE, SM>>>, Error>
Builds and starts the Raft node.
This is the primary method to initialize and start a node. It performs:
- State machine initialization (including lease injection if applicable)
- Raft core construction
- Background task spawning (commit handler, replication, election)
- gRPC server startup for cluster communication
§Returns
An Arc<Node> ready for operation
§Errors
Returns an error if any initialization step fails
§Example
let node = NodeBuilder::from_node_config(config, shutdown_rx)
.storage_engine(storage)
.state_machine(state_machine)
.start().await?;Auto Trait Implementations§
impl<SE, SM> !Freeze for NodeBuilder<SE, SM>
impl<SE, SM> !RefUnwindSafe for NodeBuilder<SE, SM>
impl<SE, SM> Send for NodeBuilder<SE, SM>
impl<SE, SM> Sync for NodeBuilder<SE, SM>
impl<SE, SM> Unpin for NodeBuilder<SE, SM>
impl<SE, SM> UnsafeUnpin for NodeBuilder<SE, SM>
impl<SE, SM> !UnwindSafe for NodeBuilder<SE, SM>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request