2021-01-13 10:32:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <string>
|
|
|
|
#include <Coordination/InMemoryLogStore.h>
|
2021-02-08 13:50:03 +00:00
|
|
|
#include <libnuraft/nuraft.hxx> // Y_IGNORE
|
2021-02-11 09:17:57 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class InMemoryStateManager : public nuraft::state_mgr
|
|
|
|
{
|
|
|
|
public:
|
2021-02-11 09:17:57 +00:00
|
|
|
InMemoryStateManager(
|
|
|
|
int server_id_,
|
|
|
|
const std::string & config_prefix,
|
|
|
|
const Poco::Util::AbstractConfiguration & config);
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
nuraft::ptr<nuraft::cluster_config> 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<nuraft::srv_state> read_state() override { return server_state; }
|
|
|
|
|
|
|
|
nuraft::ptr<nuraft::log_store> load_log_store() override { return log_store; }
|
|
|
|
|
|
|
|
Int32 server_id() override { return my_server_id; }
|
|
|
|
|
2021-02-11 09:17:57 +00:00
|
|
|
nuraft::ptr<nuraft::srv_config> get_srv_config() const { return my_server_config; }
|
2021-01-13 10:32:20 +00:00
|
|
|
|
|
|
|
void system_exit(const int /* exit_code */) override {}
|
|
|
|
|
2021-02-11 09:17:57 +00:00
|
|
|
int getPort() const { return my_port; }
|
|
|
|
|
2021-01-13 10:32:20 +00:00
|
|
|
private:
|
|
|
|
int my_server_id;
|
2021-02-11 09:17:57 +00:00
|
|
|
int my_port;
|
2021-01-13 10:32:20 +00:00
|
|
|
nuraft::ptr<InMemoryLogStore> log_store;
|
2021-02-11 09:17:57 +00:00
|
|
|
nuraft::ptr<nuraft::srv_config> my_server_config;
|
2021-01-13 10:32:20 +00:00
|
|
|
nuraft::ptr<nuraft::cluster_config> cluster_config;
|
|
|
|
nuraft::ptr<nuraft::srv_state> server_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|