OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
state_manager.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_RAFT_STATE_MANAGER_H_
7#define OPENCBDC_TX_SRC_RAFT_STATE_MANAGER_H_
8
9#include "log_store.hpp"
11
12#include <libnuraft/nuraft.hxx>
13
14namespace cbdc::raft {
16 class state_manager : public nuraft::state_mgr {
17 public:
24 state_manager(int32_t srv_id,
25 std::string log_dir,
26 std::string config_file,
27 std::string state_file,
28 std::vector<network::endpoint_t> raft_endpoints);
29 ~state_manager() override = default;
30
31 state_manager(const state_manager& other) = delete;
32 auto operator=(const state_manager& other) -> state_manager& = delete;
33
34 state_manager(state_manager&& other) noexcept;
35 auto operator=(state_manager&& other) noexcept -> state_manager&;
36
39 auto load_config() -> nuraft::ptr<nuraft::cluster_config> override;
40
43 void save_config(const nuraft::cluster_config& config) override;
44
47 void save_state(const nuraft::srv_state& state) override;
48
51 auto read_state() -> nuraft::ptr<nuraft::srv_state> override;
52
55 auto load_log_store() -> nuraft::ptr<nuraft::log_store> override;
56
59 auto server_id() -> int32_t override;
60
63 void system_exit(int exit_code) override;
64
65 private:
66 int32_t m_id;
67 std::string m_config_file;
68 std::string m_state_file;
69 std::string m_log_dir;
70 std::vector<network::endpoint_t> m_raft_endpoints;
71 };
72}
73
74#endif // OPENCBDC_TX_SRC_RAFT_STATE_MANAGER_H_
Implementation of nuraft::state_mgr using a file.
state_manager(int32_t srv_id, std::string log_dir, std::string config_file, std::string state_file, std::vector< network::endpoint_t > raft_endpoints)
Constructor.
void save_state(const nuraft::srv_state &state) override
Serialize and write the given server state.
auto operator=(state_manager &&other) noexcept -> state_manager &
void save_config(const nuraft::cluster_config &config) override
Serialize and write the given cluster configuration.
auto read_state() -> nuraft::ptr< nuraft::srv_state > override
Read and deserialize the server state.
auto operator=(const state_manager &other) -> state_manager &=delete
auto load_config() -> nuraft::ptr< nuraft::cluster_config > override
Read and deserialize the cluster configuration.
auto load_log_store() -> nuraft::ptr< nuraft::log_store > override
Load and return the log store.
state_manager(const state_manager &other)=delete
state_manager(state_manager &&other) noexcept
~state_manager() override=default
void system_exit(int exit_code) override
Terminate the application with the given exit code.
auto server_id() -> int32_t override
Return the server ID.