#pragma once #include #include #include #include // Y_IGNORE #include namespace DB { class InMemoryStateManager : public nuraft::state_mgr { public: InMemoryStateManager( int server_id_, const std::string & config_prefix, const Poco::Util::AbstractConfiguration & config); InMemoryStateManager( int server_id_, const std::string & host, int port); nuraft::ptr load_config() override { return cluster_config; } void save_config(const nuraft::cluster_config & config) override; void save_state(const nuraft::srv_state & state) override; nuraft::ptr read_state() override { return server_state; } nuraft::ptr load_log_store() override { return log_store; } Int32 server_id() override { return my_server_id; } nuraft::ptr get_srv_config() const { return my_server_config; } void system_exit(const int /* exit_code */) override {} int getPort() const { return my_port; } bool shouldStartAsFollower() const { return start_as_follower_servers.count(my_server_id); } private: int my_server_id; int my_port; std::unordered_set start_as_follower_servers; nuraft::ptr log_store; nuraft::ptr my_server_config; nuraft::ptr cluster_config; nuraft::ptr server_state; }; }