diff --git a/src/Coordination/InMemoryStateManager.cpp b/src/Coordination/InMemoryStateManager.cpp index a6db3271bc1..69e93578cc1 100644 --- a/src/Coordination/InMemoryStateManager.cpp +++ b/src/Coordination/InMemoryStateManager.cpp @@ -9,6 +9,16 @@ namespace ErrorCodes extern const int RAFT_ERROR; } +InMemoryStateManager::InMemoryStateManager(int server_id_, const std::string & host, int port) + : my_server_id(server_id_) + , my_port(port) + , log_store(nuraft::cs_new()) + , cluster_config(nuraft::cs_new()) +{ + auto peer_config = nuraft::cs_new(my_server_id, host + ":" + std::to_string(port)); + cluster_config->get_servers().push_back(peer_config); +} + InMemoryStateManager::InMemoryStateManager( int my_server_id_, const std::string & config_prefix, diff --git a/src/Coordination/InMemoryStateManager.h b/src/Coordination/InMemoryStateManager.h index a4537602b36..2a5c2f00dba 100644 --- a/src/Coordination/InMemoryStateManager.h +++ b/src/Coordination/InMemoryStateManager.h @@ -17,6 +17,11 @@ public: 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; diff --git a/src/Coordination/tests/gtest_for_build.cpp b/src/Coordination/tests/gtest_for_build.cpp index c6f29831618..ed9777350c5 100644 --- a/src/Coordination/tests/gtest_for_build.cpp +++ b/src/Coordination/tests/gtest_for_build.cpp @@ -27,7 +27,6 @@ TEST(CoordinationTest, BuildTest) { DB::InMemoryLogStore store; - DB::InMemoryStateManager state_manager(1, "localhost:12345"); DB::SummingStateMachine machine; EXPECT_EQ(1, 1); } @@ -74,7 +73,7 @@ struct SimpliestRaftServer , port(port_) , endpoint(hostname + ":" + std::to_string(port)) , state_machine(nuraft::cs_new()) - , state_manager(nuraft::cs_new(server_id, endpoint)) + , state_manager(nuraft::cs_new(server_id, hostname, port)) { nuraft::raft_params params; params.heart_beat_interval_ = 100;