2017-01-21 04:24:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2019-01-11 19:12:36 +00:00
|
|
|
#include <Common/MultiVersion.h>
|
2019-01-14 19:22:09 +00:00
|
|
|
#include <Common/ThreadPool.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
#include <Poco/Event.h>
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <functional>
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-12-27 19:26:18 +00:00
|
|
|
namespace Poco { class Logger; namespace Util { class AbstractConfiguration; } }
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2023-12-29 06:36:24 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
class RegionsHierarchies;
|
|
|
|
class RegionsNames;
|
2019-09-26 16:12:15 +00:00
|
|
|
class GeoDictionariesLoader;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
/// Metrica's Dictionaries which can be used in functions.
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
class EmbeddedDictionaries : WithContext
|
2017-01-21 04:24:28 +00:00
|
|
|
{
|
|
|
|
private:
|
2024-01-23 17:04:50 +00:00
|
|
|
LoggerPtr log;
|
2017-08-24 14:51:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MultiVersion<RegionsHierarchies> regions_hierarchies;
|
|
|
|
MultiVersion<RegionsNames> regions_names;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2019-09-26 16:12:15 +00:00
|
|
|
std::unique_ptr<GeoDictionariesLoader> geo_dictionaries_loader;
|
2017-11-28 22:15:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Directories' updating periodicity (in seconds).
|
|
|
|
int reload_period;
|
|
|
|
int cur_reload_period = 1;
|
|
|
|
bool is_fast_start_stage = true;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-08-24 18:19:06 +00:00
|
|
|
mutable std::mutex mutex;
|
|
|
|
|
2019-01-14 19:22:09 +00:00
|
|
|
ThreadFromGlobalPool reloading_thread;
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Event destroy;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void handleException(bool throw_on_error) const;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/** Updates directories (dictionaries) every reload_period seconds.
|
|
|
|
* If all dictionaries are not loaded at least once, try reload them with exponential delay (1, 2, ... reload_period).
|
|
|
|
* If all dictionaries are loaded, update them using constant reload_period delay.
|
|
|
|
*/
|
|
|
|
void reloadPeriodically();
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-08-24 18:19:06 +00:00
|
|
|
/// Updates dictionaries.
|
2021-04-10 23:33:54 +00:00
|
|
|
bool reloadImpl(bool throw_on_error, bool force_reload = false);
|
2017-08-24 18:19:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
template <typename Dictionary>
|
2017-11-28 22:15:06 +00:00
|
|
|
using DictionaryReloader = std::function<std::unique_ptr<Dictionary>(const Poco::Util::AbstractConfiguration & config)>;
|
|
|
|
|
|
|
|
template <typename Dictionary>
|
|
|
|
bool reloadDictionary(
|
|
|
|
MultiVersion<Dictionary> & dictionary,
|
|
|
|
DictionaryReloader<Dictionary> reload_dictionary,
|
2021-04-10 23:33:54 +00:00
|
|
|
bool throw_on_error,
|
|
|
|
bool force_reload);
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Every reload_period seconds directories are updated inside a separate thread.
|
2017-11-28 22:15:06 +00:00
|
|
|
EmbeddedDictionaries(
|
2019-09-26 16:12:15 +00:00
|
|
|
std::unique_ptr<GeoDictionariesLoader> geo_dictionaries_loader,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
|
|
|
bool throw_on_error);
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-08-24 18:19:06 +00:00
|
|
|
/// Forcibly reloads all dictionaries.
|
|
|
|
void reload();
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~EmbeddedDictionaries();
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MultiVersion<RegionsHierarchies>::Version getRegionsHierarchies() const
|
|
|
|
{
|
|
|
|
return regions_hierarchies.get();
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MultiVersion<RegionsNames>::Version getRegionsNames() const
|
|
|
|
{
|
|
|
|
return regions_names.get();
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|