2016-01-17 13:34:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ConfigProcessor.h>
|
2017-06-19 20:06:35 +00:00
|
|
|
#include <Common/ZooKeeper/Common.h>
|
|
|
|
#include <Common/ZooKeeper/ZooKeeperNodeCache.h>
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2016-01-17 13:34:36 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
2016-10-23 10:52:32 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
2016-10-10 08:44:52 +00:00
|
|
|
#include <list>
|
2016-01-17 13:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
2016-10-14 15:06:46 +00:00
|
|
|
/** Every two seconds checks configuration files for update.
|
|
|
|
* If configuration is changed, then config will be reloaded by ConfigProcessor
|
2017-03-17 00:44:00 +00:00
|
|
|
* and the reloaded config will be applied via Updater functor.
|
|
|
|
* It doesn't take into account changes of --config-file, <users_config> and <include_from> parameters.
|
2016-01-17 13:34:36 +00:00
|
|
|
*/
|
2016-10-11 14:37:27 +00:00
|
|
|
class ConfigReloader
|
2016-01-17 13:34:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Updater = std::function<void(ConfigurationPtr)>;
|
2017-03-17 00:44:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/** include_from_path is usually /etc/metrika.xml (i.e. value of <include_from> tag)
|
|
|
|
*/
|
|
|
|
ConfigReloader(
|
|
|
|
const std::string & path,
|
|
|
|
const std::string & include_from_path,
|
|
|
|
zkutil::ZooKeeperNodeCache && zk_node_cache,
|
|
|
|
Updater && updater,
|
|
|
|
bool already_loaded);
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~ConfigReloader();
|
2016-01-17 13:34:36 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void run();
|
2016-01-17 13:34:36 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void reloadIfNewer(bool force, bool throw_on_error, bool fallback_to_preprocessed);
|
2016-01-17 13:34:36 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
struct FileWithTimestamp;
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
struct FilesChangesTracker
|
|
|
|
{
|
|
|
|
std::set<FileWithTimestamp> files;
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void addIfExists(const std::string & path);
|
|
|
|
bool isDifferOrNewerThan(const FilesChangesTracker & rhs);
|
|
|
|
};
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
FilesChangesTracker getNewFileList() const;
|
2016-10-10 08:44:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto reload_interval = std::chrono::seconds(2);
|
2016-10-14 15:06:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Logger * log = &Logger::get("ConfigReloader");
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string path;
|
|
|
|
std::string include_from_path;
|
|
|
|
FilesChangesTracker files;
|
|
|
|
zkutil::ZooKeeperNodeCache zk_node_cache;
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Updater updater;
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::atomic<bool> quit{false};
|
|
|
|
std::thread thread;
|
2016-01-17 13:34:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|