2017-01-21 04:24:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <common/MultiVersion.h>
|
|
|
|
#include <Poco/Event.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
|
|
|
class RegionsHierarchies;
|
|
|
|
class TechDataHierarchy;
|
|
|
|
class RegionsNames;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
|
|
|
/// Metrica's Dictionaries which can be used in functions.
|
|
|
|
|
|
|
|
class EmbeddedDictionaries
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MultiVersion<RegionsHierarchies> regions_hierarchies;
|
|
|
|
MultiVersion<TechDataHierarchy> tech_data_hierarchy;
|
|
|
|
MultiVersion<RegionsNames> regions_names;
|
2017-01-21 04:24:28 +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-04-01 07:20:54 +00:00
|
|
|
std::thread reloading_thread;
|
|
|
|
Poco::Event destroy;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Logger * log;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void handleException(const bool throw_on_error) const;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Updates dictionaries.
|
|
|
|
bool reloadImpl(const bool throw_on_error);
|
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-04-01 07:20:54 +00:00
|
|
|
template <typename Dictionary>
|
|
|
|
bool reloadDictionary(MultiVersion<Dictionary> & dictionary, const bool throw_on_error);
|
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.
|
|
|
|
EmbeddedDictionaries(const bool throw_on_error, const int reload_period_);
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
EmbeddedDictionaries(const bool throw_on_error);
|
2017-01-21 04:24:28 +00:00
|
|
|
|
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<TechDataHierarchy>::Version getTechDataHierarchy() const
|
|
|
|
{
|
|
|
|
return tech_data_hierarchy.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
|
|
|
};
|
|
|
|
|
|
|
|
}
|