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<()>) -> Self

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<()>, ) -> Self

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 init(node_config: RaftNodeConfig, shutdown_signal: Receiver<()>) -> Self

Core initialization logic shared by all construction paths

Source

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

Sets a custom storage engine implementation

Source

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

Sets a custom state machine implementation

Source

pub fn node_config(self, node_config: RaftNodeConfig) -> Self

Replaces the entire node configuration

Source

pub fn raft_config(self, config: RaftConfig) -> Self

Replaces the raft configuration

Source

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

Source

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 the StateMachineHandler trait
§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
Source

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:

  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::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>
where SE: Unpin, SM: Unpin,

§

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