2021-01-13 10:32:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <string>
|
2021-02-16 19:02:18 +00:00
|
|
|
#include <Coordination/NuKeeperLogStore.h>
|
|
|
|
#include <Coordination/CoordinationSettings.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
|
|
|
|
{
|
|
|
|
|
2021-02-19 16:05:26 +00:00
|
|
|
class NuKeeperStateManager : public nuraft::state_mgr
|
2021-01-13 10:32:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-02-19 16:05:26 +00:00
|
|
|
NuKeeperStateManager(
|
2021-02-11 09:17:57 +00:00
|
|
|
int server_id_,
|
|
|
|
const std::string & config_prefix,
|
2021-02-16 19:02:18 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const CoordinationSettingsPtr & coordination_settings);
|
2021-01-13 10:32:20 +00:00
|
|
|
|
2021-02-19 16:05:26 +00:00
|
|
|
NuKeeperStateManager(
|
2021-02-11 12:12:01 +00:00
|
|
|
int server_id_,
|
|
|
|
const std::string & host,
|
2021-02-16 19:02:18 +00:00
|
|
|
int port,
|
|
|
|
const std::string & logs_path);
|
|
|
|
|
|
|
|
void loadLogStore(size_t start_log_index);
|
2021-02-11 12:12:01 +00:00
|
|
|
|
2021-02-17 20:36:25 +00:00
|
|
|
void flushLogStore();
|
|
|
|
|
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-02-11 10:25:10 +00:00
|
|
|
bool shouldStartAsFollower() const
|
|
|
|
{
|
|
|
|
return start_as_follower_servers.count(my_server_id);
|
|
|
|
}
|
|
|
|
|
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-02-11 10:25:10 +00:00
|
|
|
std::unordered_set<int> start_as_follower_servers;
|
2021-02-16 19:02:18 +00:00
|
|
|
nuraft::ptr<NuKeeperLogStore> 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|