OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/twophase/locking_shard/state_machine.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_LOCKING_SHARD_STATE_MACHINE_H_
7#define OPENCBDC_TX_SRC_LOCKING_SHARD_STATE_MACHINE_H_
8
9#include "locking_shard.hpp"
12
13#include <libnuraft/nuraft.hxx>
14#include <mutex>
15
16namespace cbdc::locking_shard {
19 : public nuraft::state_machine,
20 public cbdc::rpc::blocking_server<rpc::request,
21 rpc::response,
22 nuraft::buffer&,
23 nuraft::ptr<nuraft::buffer>> {
24 public:
34 state_machine(const std::pair<uint8_t, uint8_t>& output_range,
35 std::shared_ptr<logging::log> logger,
36 size_t completed_txs_cache_size,
37 const std::string& preseed_file,
38 config::options opts);
39
46 auto commit(uint64_t log_idx, nuraft::buffer& data)
47 -> nuraft::ptr<nuraft::buffer> override;
48
51 void commit_config(
52 nuraft::ulong log_idx,
53 nuraft::ptr<nuraft::cluster_config>& /*new_conf*/) override;
54
57 auto apply_snapshot(nuraft::snapshot& /* s */) -> bool override;
58
61 auto last_snapshot() -> nuraft::ptr<nuraft::snapshot> override;
62
65 auto last_commit_index() -> uint64_t override;
66
68 void create_snapshot(
69 nuraft::snapshot& /* s */,
70 nuraft::async_result<bool>::handler_type& /* when_done */)
71 override;
72
77 -> std::shared_ptr<cbdc::locking_shard::locking_shard>;
78
79 private:
80 auto process_request(cbdc::locking_shard::rpc::request req)
82
83 std::atomic<uint64_t> m_last_committed_idx{0};
84 nuraft::ptr<nuraft::snapshot> m_snapshot{};
85 std::shared_mutex m_snapshots_mut{};
86
87 nuraft::ptr<nuraft::snapshot> m_tmp_snapshot{};
88 std::mutex m_tmp_mut{};
89
90 std::shared_ptr<cbdc::locking_shard::locking_shard> m_shard{};
91 std::pair<uint8_t, uint8_t> m_output_range{};
92 std::string m_snapshot_dir{};
93 std::string m_db_dir{};
94
95 std::shared_ptr<logging::log> m_logger;
96 };
97}
98
99#endif
Raft state machine for handling locking shard RPC requests.
void create_snapshot(nuraft::snapshot &, nuraft::async_result< bool >::handler_type &) override
Not implemented for locking shard.
void commit_config(nuraft::ulong log_idx, nuraft::ptr< nuraft::cluster_config > &) override
Handler for the raft cluster configuration changes.
auto last_snapshot() -> nuraft::ptr< nuraft::snapshot > override
Not implemented for locking shard.
state_machine(const std::pair< uint8_t, uint8_t > &output_range, std::shared_ptr< logging::log > logger, size_t completed_txs_cache_size, const std::string &preseed_file, config::options opts)
Constructor.
auto get_shard_instance() -> std::shared_ptr< cbdc::locking_shard::locking_shard >
Returns a pointer to the locking shard instance managed by this state machine.
auto last_commit_index() -> uint64_t override
Returns the most recently committed log entry index.
auto apply_snapshot(nuraft::snapshot &) -> bool override
Not implemented for locking shard.
auto commit(uint64_t log_idx, nuraft::buffer &data) -> nuraft::ptr< nuraft::buffer > override
Commit the given raft log entry at the given log index, and return the result.
Generic synchronous RPC server.
std::variant< lock_response, apply_response, discard_response > response
Response to a locking shard request.
Project-wide configuration options.
Definition config.hpp:132