6#ifndef OPENCBDC_TX_SRC_COORDINATOR_STATE_MACHINE_H_
7#define OPENCBDC_TX_SRC_COORDINATOR_STATE_MACHINE_H_
12#include <libnuraft/nuraft.hxx>
13#include <unordered_map>
14#include <unordered_set>
45 nuraft::ptr<nuraft::buffer>,
51 nuraft::ptr<nuraft::buffer>,
55 std::unordered_set<hash_t, cbdc::hashing::const_sip_hash<hash_t>>
65 auto commit(uint64_t log_idx, nuraft::buffer& data)
66 -> nuraft::ptr<nuraft::buffer>
override;
71 nuraft::ulong log_idx,
72 nuraft::ptr<nuraft::cluster_config>& )
override;
80 auto last_snapshot() -> nuraft::ptr<nuraft::snapshot>
override;
88 nuraft::async_result<bool>::handler_type& when_done)
override;
91 std::atomic<uint64_t> m_last_committed_idx{0};
92 coordinator_state m_state{};
93 std::shared_ptr<logging::log> m_logger;
Raft state machine for managing a replicated coordinator.
auto apply_snapshot(nuraft::snapshot &) -> bool override
Not implemented for coordinators.
void commit_config(nuraft::ulong log_idx, nuraft::ptr< nuraft::cluster_config > &) override
Handler for the raft cluster configuration changes.
command
Types of command the state machine can process.
@ prepare
Stores a dtx in the prepare phase.
@ done
Clears the dtx from the coordinator state.
@ discard
Moves a dtx from commit to discard.
@ get
Retrieves all active dtxs.
@ commit
Moves a dtx from prepare to commit.
state_machine(std::shared_ptr< logging::log > logger)
Constructor.
auto last_snapshot() -> nuraft::ptr< nuraft::snapshot > override
Not implemented for coordinators.
auto last_commit_index() -> uint64_t override
Returns the index of the last-committed command.
void create_snapshot(nuraft::snapshot &, nuraft::async_result< bool >::handler_type &when_done) override
Not implemented for coordinators.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Used to store dtxs, which phase they are in and relevant data require for recovery.
std::unordered_set< hash_t, cbdc::hashing::const_sip_hash< hash_t > > m_discard_txs
Set of dtx IDs in the discard phase.
std::unordered_map< hash_t, nuraft::ptr< nuraft::buffer >, cbdc::hashing::const_sip_hash< hash_t > > m_prepare_txs
Maps dtx IDs in the prepare phase to a byte array containing relevant data for recovery.
std::unordered_map< hash_t, nuraft::ptr< nuraft::buffer >, cbdc::hashing::const_sip_hash< hash_t > > m_commit_txs
Maps dtx IDs in the commit phase to a byte array containing relevant data for recovery.
SipHash function to generate STL data structure hash keys for system IDs.