OpenCBDC Transaction Processor
|
A node in a raft cluster. More...
#include <node.hpp>
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. | |
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.
|
delete |
|
delete |
|
delete |
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.
node_id | identifier of the node in the raft cluster. Must be 0 or greater. |
raft_endpoints | TCP endpoints of nodes in the cluster. |
node_type | name of the raft cluster this node will be part of. |
blocking | true if replication calls should block until the state machine makes an execution result available. |
sm | pointer to the state machine replicated by the cluster. |
asio_thread_pool_size | number of threads for processing raft messages. Set to 0 to use the number of cores on the system. |
logger | log instance NuRaft should use. |
raft_cb | NuRaft callback to report raft events. |
cbdc::raft::node::~node | ( | ) |
|
nodiscard |
auto cbdc::raft::node::init | ( | const nuraft::raft_params & | raft_params | ) | -> bool |
|
nodiscard |
|
nodiscard |
|
nodiscard |
Replicates the given log entry in the cluster.
Calls the given callback with the state machine execution result.
new_log | log entry to replicate. |
result_fn | callback function to call asynchronously with the state machine execution result. |
|
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.
new_log | raft log entry to replicate |
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().