diff --git a/src/Service/KeeperServer.cpp b/src/Service/KeeperServer.cpp index e8013fd75e..31b62db874 100644 --- a/src/Service/KeeperServer.cpp +++ b/src/Service/KeeperServer.cpp @@ -328,7 +328,7 @@ bool KeeperServer::isLeader() const bool KeeperServer::isObserver() const { - auto cluster_config = state_manager->get_cluster_config(); + auto cluster_config = state_manager->getClusterConfig(); return cluster_config->get_server(server_id)->is_learner(); } diff --git a/src/Service/NuRaftStateManager.cpp b/src/Service/NuRaftStateManager.cpp index 79e8e81099..23f3d6a9b1 100644 --- a/src/Service/NuRaftStateManager.cpp +++ b/src/Service/NuRaftStateManager.cpp @@ -24,18 +24,17 @@ NuRaftStateManager::NuRaftStateManager(int id_, const Poco::Util::AbstractConfig cur_cluster_config = parseClusterConfig(config_, "keeper.cluster"); } -ptr NuRaftStateManager::get_cluster_config() const +ptr NuRaftStateManager::getClusterConfig() const { - std::lock_guard l(cluster_config_lock_); + std::lock_guard lock(cluster_config_mutex); ptr ret = cur_cluster_config; return ret; } -void NuRaftStateManager::set_cluster_config(const ptr& new_config) +void NuRaftStateManager::setClusterConfig(const ptr& new_config) { - std::lock_guard l(cluster_config_lock_); + std::lock_guard lock(cluster_config_mutex); cur_cluster_config = new_config; - LOG_INFO(log, "set config with log index {}", cur_cluster_config->get_log_idx()); } ptr NuRaftStateManager::load_config() @@ -43,7 +42,7 @@ ptr NuRaftStateManager::load_config() if (!Poco::File(cluster_config_file).exists()) { LOG_INFO(log, "load config with initial cluster config."); - return get_cluster_config(); + return getClusterConfig(); } std::unique_ptr read_file_buf = std::make_unique(cluster_config_file, 4096); @@ -52,7 +51,8 @@ ptr NuRaftStateManager::load_config() ptr buf = nuraft::buffer::alloc(size); read_file_buf->readStrict(reinterpret_cast(buf->data()), size); auto new_cluster_config = nuraft::cluster_config::deserialize(*buf); - set_cluster_config(new_cluster_config); + setClusterConfig(new_cluster_config); + LOG_INFO(log, "load config with log index {}", new_cluster_config->get_log_idx()); return new_cluster_config; } @@ -65,7 +65,9 @@ void NuRaftStateManager::save_config(const cluster_config & config) out_file_buf->write(reinterpret_cast(data->data()), data->size()); out_file_buf->finalize(); out_file_buf->sync(); - set_cluster_config(cluster_config::deserialize(*data)); + auto new_cluster_config = cluster_config::deserialize(*data); + setClusterConfig(new_cluster_config); + LOG_INFO(log, "save config with log index {}", new_cluster_config->get_log_idx()); } void NuRaftStateManager::save_state(const srv_state & state) @@ -157,7 +159,7 @@ ptr NuRaftStateManager::parseClusterConfig( ConfigUpdateActions NuRaftStateManager::getConfigurationDiff(const Poco::Util::AbstractConfiguration & config) { auto new_cluster_config = parseClusterConfig(config, "keeper.cluster"); - auto old_cluster_config = get_cluster_config(); + auto old_cluster_config = getClusterConfig(); std::unordered_map new_ids, old_ids; for (const auto & new_server : new_cluster_config->get_servers()) diff --git a/src/Service/NuRaftStateManager.h b/src/Service/NuRaftStateManager.h index 7be82db490..e9ae020e8b 100644 --- a/src/Service/NuRaftStateManager.h +++ b/src/Service/NuRaftStateManager.h @@ -66,9 +66,9 @@ class NuRaftStateManager : public nuraft::state_mgr //ptr get_srv_config() const { return curr_srv_config; } - ptr get_cluster_config() const; + ptr getClusterConfig() const; - void set_cluster_config(const ptr& new_config); + void setClusterConfig(const ptr& new_config); /// Get configuration diff between proposed XML and current state in RAFT ConfigUpdateActions getConfigurationDiff(const Poco::Util::AbstractConfiguration & config); @@ -93,7 +93,7 @@ class NuRaftStateManager : public nuraft::state_mgr /** * Lock for cluster config. */ - mutable std::mutex cluster_config_lock_; + mutable std::mutex cluster_config_mutex; protected: