ClickHouse/src/Interpreters/ClusterDiscovery.h

56 lines
1.2 KiB
C++
Raw Normal View History

2021-11-11 09:03:53 +00:00
#pragma once
2021-11-15 14:52:52 +00:00
#include <Common/ConcurrentBoundedQueue.h>
#include <Common/ThreadPool.h>
2021-11-11 09:03:53 +00:00
#include <Common/ZooKeeper/Common.h>
2021-11-15 14:52:52 +00:00
#include <Poco/Logger.h>
#include <base/defines.h>
#include <unordered_map>
2021-11-11 09:03:53 +00:00
namespace DB
{
class ClusterDiscovery
{
public:
ClusterDiscovery(
const Poco::Util::AbstractConfiguration & config,
ContextMutablePtr context_,
const String & config_prefix = "remote_servers_discovery");
void start();
2021-11-15 14:52:52 +00:00
~ClusterDiscovery();
2021-11-11 09:03:53 +00:00
private:
2021-11-15 14:52:52 +00:00
Strings getNodeNames(zkutil::ZooKeeperPtr & zk, const String & zk_root, const String & cluster_name);
2021-11-11 09:03:53 +00:00
Strings getNodes(zkutil::ZooKeeperPtr & zk, const String & zk_root, const Strings & nodes);
2021-11-15 14:52:52 +00:00
void updateCluster(const String & cluster_name);
2021-11-11 09:03:53 +00:00
void updateCluster(const String & cluster_name, const String & zk_root);
2021-11-15 14:52:52 +00:00
void runMainThread();
void shutdown();
2021-11-11 09:03:53 +00:00
/// cluster name -> path in zk
std::unordered_map<String, String> clusters;
ContextMutablePtr context;
String node_name;
UInt16 server_port;
2021-11-15 14:52:52 +00:00
using UpdateQueue = ConcurrentBoundedQueue<std::string>;
std::shared_ptr<UpdateQueue> queue;
std::atomic<bool> stop_flag = false;
ThreadFromGlobalPool main_thread;
2021-11-11 09:03:53 +00:00
Poco::Logger * log;
};
}