OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::coordinator::controller Class Reference

Replicated coordinator node. More...

#include <controller.hpp>

Inheritance diagram for cbdc::coordinator::controller:
Collaboration diagram for cbdc::coordinator::controller:

Data Structures

struct  coordinator_state
 Current state of distributed transactions managed by a coordinator. More...
 
struct  sm_command
 A full command for the state machine to process. More...
 
struct  sm_command_header
 Metadata of a command for the state machine. More...
 

Public Types

using send_fn_t
 
using prepare_tx = std::vector<transaction::compact_tx>
 List of compact transactions associated with a distributed transaction in the prepare phase.
 
using prepare_txs
 Map from distributed transaction IDs in the prepare phase to the associated compact transactions.
 
using commit_tx = std::pair<std::vector<bool>, std::vector<std::vector<uint64_t>>>
 Aggregated responses and metadata from the prepare phase.
 
using commit_txs
 Map from distributed transaction IDs in the commit phase to the associated responses and metadata from the prepare phase.
 
using discard_txs = std::unordered_set<hash_t, hashing::const_sip_hash<hash_t>>
 Set of distributed transaction IDs in the discard phase.
 
- Public Types inherited from cbdc::coordinator::interface
using callback_type = std::function<void(std::optional<bool>)>
 Signature of callback function for a transaction execution result.
 

Public Member Functions

 controller (size_t node_id, size_t coordinator_id, cbdc::config::options opts, std::shared_ptr< logging::log > logger)
 Constructs a new replicated coordinator node.
 
 controller ()=delete
 
 controller (const controller &)=delete
 
auto operator= (const controller &) -> controller &=delete
 
 controller (controller &&)=delete
 
auto operator= (controller &&) -> controller &=delete
 
 ~controller () override
 
auto init () -> bool
 Starts the replicated coordinator and associated raft server.
 
void quit ()
 Terminates the replicated coordinator instance.
 
auto execute_transaction (transaction::compact_tx tx, callback_type result_callback) -> bool override
 Coordinates a transaction among locking shards.
 
- Public Member Functions inherited from cbdc::coordinator::interface
virtual ~interface ()=default
 
 interface ()=default
 
 interface (const interface &)=delete
 
auto operator= (const interface &) -> interface &=delete
 
 interface (interface &&)=delete
 
auto operator= (interface &&) -> interface &=delete
 

Detailed Description

Replicated coordinator node.

Participates in a raft cluster with other replicated coordinators. When acting as the leader, listens on a specified endpoint and handles new transaction requests from sentinels. Recovers failed dtxs as part of its leadership transition.

Definition at line 27 of file uhs/twophase/coordinator/controller.hpp.

Member Typedef Documentation

◆ commit_tx

using cbdc::coordinator::controller::commit_tx = std::pair<std::vector<bool>, std::vector<std::vector<uint64_t>>>

Aggregated responses and metadata from the prepare phase.

First is a vector of bools, true if the transaction at the same index in the batch should be completed, false if it should be aborted. Second is a vector, one element for each shard ID, specifying which transaction indexes in the batch are revelant to the shard.

Definition at line 72 of file uhs/twophase/coordinator/controller.hpp.

◆ commit_txs

Initial value:
std::
unordered_map<hash_t, commit_tx, hashing::const_sip_hash<hash_t>>

Map from distributed transaction IDs in the commit phase to the associated responses and metadata from the prepare phase.

Definition at line 76 of file uhs/twophase/coordinator/controller.hpp.

◆ discard_txs

Set of distributed transaction IDs in the discard phase.

Definition at line 80 of file uhs/twophase/coordinator/controller.hpp.

◆ prepare_tx

List of compact transactions associated with a distributed transaction in the prepare phase.

Definition at line 60 of file uhs/twophase/coordinator/controller.hpp.

◆ prepare_txs

Initial value:
std::
unordered_map<hash_t, prepare_tx, hashing::const_sip_hash<hash_t>>

Map from distributed transaction IDs in the prepare phase to the associated compact transactions.

Definition at line 64 of file uhs/twophase/coordinator/controller.hpp.

◆ send_fn_t

Initial value:
std::function<void(const std::shared_ptr<buffer>&,
size_t peer_id_t
Peer IDs within a connection_manager.

Definition at line 29 of file uhs/twophase/coordinator/controller.hpp.

Constructor & Destructor Documentation

◆ controller() [1/4]

cbdc::coordinator::controller::controller ( size_t node_id,
size_t coordinator_id,
cbdc::config::options opts,
std::shared_ptr< logging::log > logger )

Constructs a new replicated coordinator node.

Parameters
node_idraft node ID in the coordinator cluster.
coordinator_idID to determine which coordinator cluster this node is part of.
optsconfiguration options.
loggerpointer to shared logger.

Definition at line 18 of file uhs/twophase/coordinator/controller.cpp.

References cbdc::config::options::m_election_timeout_lower, cbdc::config::options::m_election_timeout_upper, cbdc::config::options::m_heartbeat, and cbdc::config::options::m_raft_max_batch.

◆ controller() [2/4]

cbdc::coordinator::controller::controller ( )
delete

◆ controller() [3/4]

cbdc::coordinator::controller::controller ( const controller & )
delete

◆ controller() [4/4]

cbdc::coordinator::controller::controller ( controller && )
delete

◆ ~controller()

cbdc::coordinator::controller::~controller ( )
override

Definition at line 42 of file uhs/twophase/coordinator/controller.cpp.

References quit().

Here is the call graph for this function:

Member Function Documentation

◆ execute_transaction()

auto cbdc::coordinator::controller::execute_transaction ( transaction::compact_tx tx,
callback_type result_callback ) -> bool
overridevirtual

Coordinates a transaction among locking shards.

Adds a transaction to the current batch. Registers a callback function to return the transaction execution result once the shards completely process the batch.

Parameters
txtransaction to execute.
result_callbackfunction to call with the result once execution is complete.
Returns
true if the current batch now contains the transaction. false if the current batch already contained the transaction or if the controller shut down before the operation could finish.

Implements cbdc::coordinator::interface.

Definition at line 684 of file uhs/twophase/coordinator/controller.cpp.

References cbdc::transaction::validation::check_attestations(), and cbdc::to_string().

Here is the call graph for this function:

◆ init()

auto cbdc::coordinator::controller::init ( ) -> bool

Starts the replicated coordinator and associated raft server.

Returns
true if the initialization succeeded.

Definition at line 46 of file uhs/twophase/coordinator/controller.cpp.

◆ operator=() [1/2]

auto cbdc::coordinator::controller::operator= ( const controller & ) -> controller &=delete
delete

◆ operator=() [2/2]

auto cbdc::coordinator::controller::operator= ( controller && ) -> controller &=delete
delete

◆ quit()

void cbdc::coordinator::controller::quit ( )

Terminates the replicated coordinator instance.

Definition at line 656 of file uhs/twophase/coordinator/controller.cpp.

Referenced by ~controller().


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