OpenCBDC Transaction Processor
|
Raft state machine for managing a replicated atomizer. More...
#include <state_machine.hpp>
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. | |
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.
using cbdc::atomizer::state_machine::blockstore_t = std::unordered_map<uint64_t, cbdc::atomizer::block> |
Maps block heights to blocks.
Definition at line 117 of file uhs/atomizer/atomizer/state_machine.hpp.
Atomizer state machine request.
Definition at line 30 of file uhs/atomizer/atomizer/state_machine.hpp.
using cbdc::atomizer::state_machine::response = std::variant<make_block_response, get_block_response, errors> |
Atomizer state machine response.
Definition at line 36 of file uhs/atomizer/atomizer/state_machine.hpp.
cbdc::atomizer::state_machine::state_machine | ( | size_t | stxo_cache_depth, |
std::string | snapshot_dir ) |
Constructor.
stxo_cache_depth | depth of the spent transaction output cache, passed to the atomizer. |
snapshot_dir | path 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().
|
nodiscardoverride |
Replaces the state of the state machine with the state stored in the snapshot referenced by the given snapshot metadata.
s | snapshot metadata. |
Definition at line 189 of file uhs/atomizer/atomizer/state_machine.cpp.
Referenced by state_machine().
|
nodiscardoverride |
Executes the committed the raft log entry at the given index and return the state machine execution result.
log_idx | index of the given log entry. |
data | serialized log entry containing state machine command and parameters. |
Definition at line 42 of file uhs/atomizer/atomizer/state_machine.cpp.
References cbdc::from_buffer(), and cbdc::make_buffer().
|
override |
Handler for the raft cluster configuration changes.
log_idx | Raft log number of the configuration change. |
Definition at line 103 of file uhs/atomizer/atomizer/state_machine.cpp.
|
override |
Creates a snapshot with the given metadata.
s | snapshot metadata. |
when_done | function to call when snapshot creation is complete. |
Definition at line 211 of file uhs/atomizer/atomizer/state_machine.cpp.
References last_commit_index().
|
nodiscardoverride |
Returns the index of the most recently committed log entry.
Definition at line 207 of file uhs/atomizer/atomizer/state_machine.cpp.
Referenced by create_snapshot().
|
nodiscardoverride |
Returns the most recent snapshot metadata.
Definition at line 199 of file uhs/atomizer/atomizer/state_machine.cpp.
Referenced by state_machine().
|
nodiscardoverride |
Read the portion of the state machine snapshot associated with the given metadata and object ID into a buffer.
s | metadata of snapshot to read. |
user_snp_ctx | pointer to a snapshot context; must be provided to all successive calls to this method for the same snapshot. |
obj_id | ID of the snapshot object to read. |
data_out | buffer in which to write the snapshot object. |
is_last_obj | set to true if this object ID is the last snapshot object. |
Definition at line 111 of file uhs/atomizer/atomizer/state_machine.cpp.
|
override |
Saves the portion of the state machine snapshot associated with the given metadata and object ID into persistent storage.
s | metadata of snapshot to save. |
obj_id | ID of the snapshot object to save. |
data | buffer from which to read the snapshot object data to save. |
is_first_obj | true if this object ID is the first snapshot object. |
is_last_obj | true if this object ID is the last snapshot object. |
Definition at line 150 of file uhs/atomizer/atomizer/state_machine.cpp.
|
nodiscard |
Returns the total number of transaction notifications which the state machine has processed.
Definition at line 266 of file uhs/atomizer/atomizer/state_machine.cpp.