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 from_cluster_config(
cluster_config: ClusterConfig,
shutdown_signal: Receiver<()>,
) -> Self
pub fn from_cluster_config( cluster_config: ClusterConfig, shutdown_signal: Receiver<()>, ) -> Self
Sourcepub fn init(node_config: RaftNodeConfig, shutdown_signal: Receiver<()>) -> Self
pub fn init(node_config: RaftNodeConfig, shutdown_signal: Receiver<()>) -> Self
Core initialization logic shared by all construction paths
Sourcepub fn storage_engine(self, storage_engine: Arc<SE>) -> Self
pub fn storage_engine(self, storage_engine: Arc<SE>) -> Self
Sets a custom storage engine implementation
Sourcepub fn state_machine(self, state_machine: Arc<SM>) -> Self
pub fn state_machine(self, state_machine: Arc<SM>) -> Self
Sets a custom state machine implementation
Sourcepub fn node_config(self, node_config: RaftNodeConfig) -> Self
pub fn node_config(self, node_config: RaftNodeConfig) -> Self
Replaces the entire node configuration
Sourcepub fn raft_config(self, config: RaftConfig) -> Self
pub fn raft_config(self, config: RaftConfig) -> Self
Replaces the raft configuration
Sourcepub async fn build(self) -> Result<Self>
pub async fn build(self) -> Result<Self>
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<SMHOF<RaftTypeConfig<SE, SM>>>,
) -> Self
pub fn with_custom_state_machine_handler( self, handler: Arc<SMHOF<RaftTypeConfig<SE, SM>>>, ) -> Self
Spawn watch dispatcher as background task.
The dispatcher manages all watch streams for the lifetime of the node. Sets a custom state machine handler implementation.
This allows developers to provide their own implementation of the state machine handler which processes committed log entries and applies them to the state machine.
§Arguments
handler- custom state machine handler that must implement theStateMachineHandlertrait
§Notes
- The handler must be thread-safe as it will be shared across multiple threads
- If not set, a default implementation will be used during
build() - The handler should properly handle snapshot creation and restoration
Sourcepub async fn start(self) -> Result<Arc<Node<RaftTypeConfig<SE, SM>>>>
pub async fn start(self) -> Result<Arc<Node<RaftTypeConfig<SE, SM>>>>
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::init(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> !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