Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
lzydmxy committed Nov 17, 2023
1 parent d6fc654 commit 4a8e6df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Service/KeeperServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
20 changes: 11 additions & 9 deletions src/Service/NuRaftStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ NuRaftStateManager::NuRaftStateManager(int id_, const Poco::Util::AbstractConfig
cur_cluster_config = parseClusterConfig(config_, "keeper.cluster");
}

ptr<cluster_config> NuRaftStateManager::get_cluster_config() const
ptr<cluster_config> NuRaftStateManager::getClusterConfig() const
{
std::lock_guard<std::mutex> l(cluster_config_lock_);
std::lock_guard<std::mutex> lock(cluster_config_mutex);
ptr<cluster_config> ret = cur_cluster_config;
return ret;
}

void NuRaftStateManager::set_cluster_config(const ptr<cluster_config>& new_config)
void NuRaftStateManager::setClusterConfig(const ptr<cluster_config>& new_config)
{
std::lock_guard<std::mutex> l(cluster_config_lock_);
std::lock_guard<std::mutex> lock(cluster_config_mutex);
cur_cluster_config = new_config;
LOG_INFO(log, "set config with log index {}", cur_cluster_config->get_log_idx());
}

ptr<cluster_config> 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<ReadBufferFromFile> read_file_buf = std::make_unique<ReadBufferFromFile>(cluster_config_file, 4096);
Expand All @@ -52,7 +51,8 @@ ptr<cluster_config> NuRaftStateManager::load_config()
ptr<nuraft::buffer> buf = nuraft::buffer::alloc(size);
read_file_buf->readStrict(reinterpret_cast<char *>(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;
}

Expand All @@ -65,7 +65,9 @@ void NuRaftStateManager::save_config(const cluster_config & config)
out_file_buf->write(reinterpret_cast<char *>(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)
Expand Down Expand Up @@ -157,7 +159,7 @@ ptr<cluster_config> 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<int, KeeperServerConfigPtr> new_ids, old_ids;
for (const auto & new_server : new_cluster_config->get_servers())
Expand Down
6 changes: 3 additions & 3 deletions src/Service/NuRaftStateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class NuRaftStateManager : public nuraft::state_mgr

//ptr<srv_config> get_srv_config() const { return curr_srv_config; }

ptr<cluster_config> get_cluster_config() const;
ptr<cluster_config> getClusterConfig() const;

void set_cluster_config(const ptr<cluster_config>& new_config);
void setClusterConfig(const ptr<cluster_config>& new_config);

/// Get configuration diff between proposed XML and current state in RAFT
ConfigUpdateActions getConfigurationDiff(const Poco::Util::AbstractConfiguration & config);
Expand All @@ -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:
Expand Down

0 comments on commit 4a8e6df

Please sign in to comment.