Skip to main content

NodeBuilder

Struct NodeBuilder 

Source
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>

Source

pub fn new( cluster_path: Option<&str>, shutdown_signal: Receiver<()>, ) -> NodeBuilder<SE, SM>

Creates a new NodeBuilder with cluster configuration loaded from file

§Arguments
  • cluster_path - Optional path to node-specific cluster configuration
  • shutdown_signal - Watch channel for graceful shutdown signaling
§Panics

Will panic if configuration loading fails (consider returning Result instead)

Source

pub fn from_cluster_config( cluster_config: ClusterConfig, shutdown_signal: Receiver<()>, ) -> NodeBuilder<SE, SM>

Constructs NodeBuilder from in-memory cluster configuration

§Arguments
  • cluster_config - Pre-built cluster configuration
  • shutdown_signal - Graceful shutdown notification channel
§Usage
let builder = NodeBuilder::from_cluster_config(my_config, shutdown_rx);
Source

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 configuration
  • shutdown_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);
Source

pub fn storage_engine(self, storage_engine: Arc<SE>) -> NodeBuilder<SE, SM>

Sets a custom storage engine implementation

Source

pub fn state_machine(self, state_machine: Arc<SM>) -> NodeBuilder<SE, SM>

Sets a custom state machine implementation

Source

pub fn node_config(self, node_config: RaftNodeConfig) -> NodeBuilder<SE, SM>

Replaces the entire node configuration

Source

pub fn raft_config(self, config: RaftConfig) -> NodeBuilder<SE, SM>

Replaces the raft configuration

Source

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

Source

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 the StateMachineHandler trait
§Notes
  • The handler must be thread-safe (shared across threads via Arc)
  • The handler must correctly handle snapshot creation and restoration
Source

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:

  1. State machine initialization (including lease injection if applicable)
  2. Raft core construction
  3. Background task spawning (commit handler, replication, election)
  4. 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>
where SE: Unpin, SM: Unpin,

§

impl<SE, SM> UnsafeUnpin for NodeBuilder<SE, SM>

§

impl<SE, SM> !UnwindSafe for NodeBuilder<SE, SM>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more