OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::atomizer::state_machine Class Reference

Raft state machine for managing a replicated atomizer. More...

#include <state_machine.hpp>

Inheritance diagram for cbdc::atomizer::state_machine:
Collaboration diagram for cbdc::atomizer::state_machine:

Data Structures

struct  snapshot
 Represents a snapshot of the state machine with associated metadata. More...
 

Public Types

using request
 Atomizer state machine request.
 
using response = std::variant<make_block_response, get_block_response, errors>
 Atomizer state machine response.
 
using blockstore_t = std::unordered_map<uint64_t, cbdc::atomizer::block>
 Maps block heights to blocks.
 

Public Member Functions

 state_machine (size_t stxo_cache_depth, std::string snapshot_dir)
 Constructor.
 
auto commit (nuraft::ulong log_idx, nuraft::buffer &data) -> nuraft::ptr< nuraft::buffer > override
 Executes the committed the raft log entry at the given index and return the state machine execution result.
 
void commit_config (nuraft::ulong log_idx, nuraft::ptr< nuraft::cluster_config > &) override
 Handler for the raft cluster configuration changes.
 
auto read_logical_snp_obj (nuraft::snapshot &s, void *&user_snp_ctx, nuraft::ulong obj_id, nuraft::ptr< nuraft::buffer > &data_out, bool &is_last_obj) -> int override
 Read the portion of the state machine snapshot associated with the given metadata and object ID into a buffer.
 
void save_logical_snp_obj (nuraft::snapshot &s, nuraft::ulong &obj_id, nuraft::buffer &data, bool is_first_obj, bool is_last_obj) override
 Saves the portion of the state machine snapshot associated with the given metadata and object ID into persistent storage.
 
auto apply_snapshot (nuraft::snapshot &s) -> bool override
 Replaces the state of the state machine with the state stored in the snapshot referenced by the given snapshot metadata.
 
auto last_snapshot () -> nuraft::ptr< nuraft::snapshot > override
 Returns the most recent snapshot metadata.
 
auto last_commit_index () -> nuraft::ulong override
 Returns the index of the most recently committed log entry.
 
void create_snapshot (nuraft::snapshot &s, nuraft::async_result< bool >::handler_type &when_done) override
 Creates a snapshot with the given metadata.
 
auto tx_notify_count () -> uint64_t
 Returns the total number of transaction notifications which the state machine has processed.
 

Detailed Description

Raft state machine for managing a replicated atomizer.

Contains a atomizer and a cache of recently created blocks. Accepts requests to retrieve and prune recent blocks from the cache.

Definition at line 20 of file uhs/atomizer/atomizer/state_machine.hpp.

Member Typedef Documentation

◆ blockstore_t

Maps block heights to blocks.

Definition at line 117 of file uhs/atomizer/atomizer/state_machine.hpp.

◆ request

Initial value:
std::variant<aggregate_tx_notify_request,
make_block_request,
get_block_request,
prune_request>

Atomizer state machine request.

Definition at line 30 of file uhs/atomizer/atomizer/state_machine.hpp.

◆ response

Atomizer state machine response.

Definition at line 36 of file uhs/atomizer/atomizer/state_machine.hpp.

Constructor & Destructor Documentation

◆ state_machine()

cbdc::atomizer::state_machine::state_machine ( size_t stxo_cache_depth,
std::string snapshot_dir )

Constructor.

Parameters
stxo_cache_depthdepth of the spent transaction output cache, passed to the atomizer.
snapshot_dirpath to directory in which to store snapshots. Will create the directory if it doesn't exist.

Definition at line 23 of file uhs/atomizer/atomizer/state_machine.cpp.

References apply_snapshot(), and last_snapshot().

Here is the call graph for this function:

Member Function Documentation

◆ apply_snapshot()

auto cbdc::atomizer::state_machine::apply_snapshot ( nuraft::snapshot & s) -> bool
nodiscardoverride

Replaces the state of the state machine with the state stored in the snapshot referenced by the given snapshot metadata.

Parameters
ssnapshot metadata.
Returns
true if the operation successfully applied the snapshot.

Definition at line 189 of file uhs/atomizer/atomizer/state_machine.cpp.

Referenced by state_machine().

◆ commit()

auto cbdc::atomizer::state_machine::commit ( nuraft::ulong log_idx,
nuraft::buffer & data ) -> nuraft::ptr<nuraft::buffer>
nodiscardoverride

Executes the committed the raft log entry at the given index and return the state machine execution result.

Parameters
log_idxindex of the given log entry.
dataserialized log entry containing state machine command and parameters.
Returns
serialized execution result.

Definition at line 42 of file uhs/atomizer/atomizer/state_machine.cpp.

References cbdc::from_buffer(), and cbdc::make_buffer().

Here is the call graph for this function:

◆ commit_config()

void cbdc::atomizer::state_machine::commit_config ( nuraft::ulong log_idx,
nuraft::ptr< nuraft::cluster_config > &  )
override

Handler for the raft cluster configuration changes.

Parameters
log_idxRaft log number of the configuration change.

Definition at line 103 of file uhs/atomizer/atomizer/state_machine.cpp.

◆ create_snapshot()

void cbdc::atomizer::state_machine::create_snapshot ( nuraft::snapshot & s,
nuraft::async_result< bool >::handler_type & when_done )
override

Creates a snapshot with the given metadata.

Parameters
ssnapshot metadata.
when_donefunction to call when snapshot creation is complete.

Definition at line 211 of file uhs/atomizer/atomizer/state_machine.cpp.

References last_commit_index().

Here is the call graph for this function:

◆ last_commit_index()

auto cbdc::atomizer::state_machine::last_commit_index ( ) -> nuraft::ulong
nodiscardoverride

Returns the index of the most recently committed log entry.

Returns
log index.

Definition at line 207 of file uhs/atomizer/atomizer/state_machine.cpp.

Referenced by create_snapshot().

◆ last_snapshot()

auto cbdc::atomizer::state_machine::last_snapshot ( ) -> nuraft::ptr<nuraft::snapshot>
nodiscardoverride

Returns the most recent snapshot metadata.

Returns
snapshot metadata, or nullptr if there is no snapshot.

Definition at line 199 of file uhs/atomizer/atomizer/state_machine.cpp.

Referenced by state_machine().

◆ read_logical_snp_obj()

auto cbdc::atomizer::state_machine::read_logical_snp_obj ( nuraft::snapshot & s,
void *& user_snp_ctx,
nuraft::ulong obj_id,
nuraft::ptr< nuraft::buffer > & data_out,
bool & is_last_obj ) -> int
nodiscardoverride

Read the portion of the state machine snapshot associated with the given metadata and object ID into a buffer.

Parameters
smetadata of snapshot to read.
user_snp_ctxpointer to a snapshot context; must be provided to all successive calls to this method for the same snapshot.
obj_idID of the snapshot object to read.
data_outbuffer in which to write the snapshot object.
is_last_objset to true if this object ID is the last snapshot object.
Returns
0 if the object was read successfully.

Definition at line 111 of file uhs/atomizer/atomizer/state_machine.cpp.

◆ save_logical_snp_obj()

void cbdc::atomizer::state_machine::save_logical_snp_obj ( nuraft::snapshot & s,
nuraft::ulong & obj_id,
nuraft::buffer & data,
bool is_first_obj,
bool is_last_obj )
override

Saves the portion of the state machine snapshot associated with the given metadata and object ID into persistent storage.

Parameters
smetadata of snapshot to save.
obj_idID of the snapshot object to save.
databuffer from which to read the snapshot object data to save.
is_first_objtrue if this object ID is the first snapshot object.
is_last_objtrue if this object ID is the last snapshot object.

Definition at line 150 of file uhs/atomizer/atomizer/state_machine.cpp.

◆ tx_notify_count()

auto cbdc::atomizer::state_machine::tx_notify_count ( ) -> uint64_t
nodiscard

Returns the total number of transaction notifications which the state machine has processed.

Returns
transaction notification count.

Definition at line 266 of file uhs/atomizer/atomizer/state_machine.cpp.


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