OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::raft::node Class Reference

A node in a raft cluster. More...

#include <node.hpp>

Inheritance diagram for cbdc::raft::node:

Public Member Functions

 node ()=delete
 
 node (const node &)=delete
 
auto operator= (const node &) -> node &=delete
 
 node (node &&)=delete
 
auto operator= (node &&) -> node &=delete
 
 node (int node_id, std::vector< network::endpoint_t > raft_endpoints, const std::string &node_type, bool blocking, nuraft::ptr< nuraft::state_machine > sm, size_t asio_thread_pool_size, std::shared_ptr< logging::log > logger, nuraft::cb_func::func_type raft_cb)
 Constructor.
 
 ~node ()
 
auto init (const nuraft::raft_params &raft_params) -> bool
 Initializes the NuRaft instance with the given state machine and raft parameters.
 
auto is_leader () const -> bool
 Indicates whether this node is the current raft leader.
 
auto replicate (nuraft::ptr< nuraft::buffer > new_log, const callback_type &result_fn) const -> bool
 Replicates the given log entry in the cluster.
 
auto replicate_sync (const nuraft::ptr< nuraft::buffer > &new_log) const -> std::optional< nuraft::ptr< nuraft::buffer > >
 Replicates the provided log entry and returns the results from the state machine if the replication was successful.
 
auto last_log_idx () const -> uint64_t
 Returns the last replicated log index.
 
auto get_sm () const -> nuraft::state_machine *
 Returns a pointer to the state machine replicated by this raft node.
 
void stop ()
 Shut down the NuRaft instance.
 

Detailed Description

A node in a raft cluster.

Wrapper for replicated state machine functionality using raft from the external library NuRaft. Builds a cluster with other raft nodes. Uses NuRaft to durably replicate log entries between a quorum of raft nodes. Callers provide a state machine to execute the log entries and return the execution result.

Definition at line 31 of file node.hpp.

Constructor & Destructor Documentation

◆ node() [1/4]

cbdc::raft::node::node ( )
delete

◆ node() [2/4]

cbdc::raft::node::node ( const node & )
delete

◆ node() [3/4]

cbdc::raft::node::node ( node && )
delete

◆ node() [4/4]

cbdc::raft::node::node ( int node_id,
std::vector< network::endpoint_t > raft_endpoints,
const std::string & node_type,
bool blocking,
nuraft::ptr< nuraft::state_machine > sm,
size_t asio_thread_pool_size,
std::shared_ptr< logging::log > logger,
nuraft::cb_func::func_type raft_cb )

Constructor.

Parameters
node_ididentifier of the node in the raft cluster. Must be 0 or greater.
raft_endpointsTCP endpoints of nodes in the cluster.
node_typename of the raft cluster this node will be part of.
blockingtrue if replication calls should block until the state machine makes an execution result available.
smpointer to the state machine replicated by the cluster.
asio_thread_pool_sizenumber of threads for processing raft messages. Set to 0 to use the number of cores on the system.
loggerlog instance NuRaft should use.
raft_cbNuRaft callback to report raft events.

Definition at line 11 of file node.cpp.

◆ ~node()

cbdc::raft::node::~node ( )

Definition at line 127 of file node.cpp.

References stop().

Here is the call graph for this function:

Member Function Documentation

◆ get_sm()

auto cbdc::raft::node::get_sm ( ) const -> nuraft::state_machine*
nodiscard

Returns a pointer to the state machine replicated by this raft node.

Returns
pointer to the state machine.

Definition at line 135 of file node.cpp.

◆ init()

auto cbdc::raft::node::init ( const nuraft::raft_params & raft_params) -> bool

Initializes the NuRaft instance with the given state machine and raft parameters.

Parameters
raft_paramsNuRaft-specific parameters for the raft node.
Returns
true if the raft node initialized successfully.

Definition at line 38 of file node.cpp.

◆ is_leader()

auto cbdc::raft::node::is_leader ( ) const -> bool
nodiscard

Indicates whether this node is the current raft leader.

Returns
true if this node is the leader.

Definition at line 83 of file node.cpp.

◆ last_log_idx()

auto cbdc::raft::node::last_log_idx ( ) const -> uint64_t
nodiscard

Returns the last replicated log index.

Returns
log index.

Definition at line 131 of file node.cpp.

◆ operator=() [1/2]

auto cbdc::raft::node::operator= ( const node & ) -> node &=delete
delete

◆ operator=() [2/2]

auto cbdc::raft::node::operator= ( node && ) -> node &=delete
delete

◆ replicate()

auto cbdc::raft::node::replicate ( nuraft::ptr< nuraft::buffer > new_log,
const callback_type & result_fn ) const -> bool
nodiscard

Replicates the given log entry in the cluster.

Calls the given callback with the state machine execution result.

Parameters
new_loglog entry to replicate.
result_fncallback function to call asynchronously with the state machine execution result.
Returns
true if the log entry was accepted for replication.

Definition at line 87 of file node.cpp.

◆ replicate_sync()

auto cbdc::raft::node::replicate_sync ( const nuraft::ptr< nuraft::buffer > & new_log) const -> std::optional<nuraft::ptr<nuraft::buffer>>
nodiscard

Replicates the provided log entry and returns the results from the state machine if the replication was successful.

The method will block until the result is available or replication has failed.

Parameters
new_lograft log entry to replicate
Returns
result from state machine or empty optional if replication failed

Definition at line 101 of file node.cpp.

◆ stop()

void cbdc::raft::node::stop ( )

Shut down the NuRaft instance.

Definition at line 139 of file node.cpp.

Referenced by cbdc::atomizer::controller::~controller(), and ~node().


The documentation for this class was generated from the following files: