From 903f826640e3bc1a2ba834aaba571e22b2320086 Mon Sep 17 00:00:00 2001 From: alesapin Date: Thu, 26 Sep 2019 13:08:38 +0300 Subject: [PATCH] Remove runtime factory and remove one redundant object --- dbms/src/Dictionaries/CacheDictionary.inc.h | 2 +- dbms/src/Interpreters/Context.cpp | 6 ++-- dbms/src/Interpreters/Context.h | 4 +-- dbms/src/Interpreters/ExternalLoader.cpp | 2 +- dbms/src/Interpreters/ExternalLoader.h | 2 +- dbms/src/Interpreters/IExternalLoadable.cpp | 5 ++- dbms/src/Interpreters/IExternalLoadable.h | 13 ++------ .../Interpreters/IRuntimeComponentsFactory.h | 31 ------------------- .../Interpreters/RuntimeComponentsFactory.h | 11 +++---- 9 files changed, 19 insertions(+), 57 deletions(-) delete mode 100644 dbms/src/Interpreters/IRuntimeComponentsFactory.h diff --git a/dbms/src/Dictionaries/CacheDictionary.inc.h b/dbms/src/Dictionaries/CacheDictionary.inc.h index 51d515a63dd..c10cde8c4fd 100644 --- a/dbms/src/Dictionaries/CacheDictionary.inc.h +++ b/dbms/src/Dictionaries/CacheDictionary.inc.h @@ -331,7 +331,7 @@ void CacheDictionary::update( { ++error_count; last_exception = std::current_exception(); - backoff_end_time = now + std::chrono::seconds(ExternalLoadableBackoff{}.calculateDuration(rnd_engine, error_count)); + backoff_end_time = now + std::chrono::seconds(calculateDurationWithBackoff(rnd_engine, error_count)); tryLogException(last_exception, log, "Could not update cache dictionary '" + getName() + "', next update is scheduled at " + DateLUT::instance().timeToString(std::chrono::system_clock::to_time_t(backoff_end_time))); diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index 086d060c171..df04f0f56f5 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -97,7 +97,7 @@ struct ContextShared { Logger * log = &Logger::get("Context"); - std::unique_ptr runtime_components_factory; + std::unique_ptr runtime_components_factory; /// For access of most of shared objects. Recursive mutex. mutable std::recursive_mutex mutex; @@ -210,7 +210,7 @@ struct ContextShared Context::ConfigReloadCallback config_reload_callback; - ContextShared(std::unique_ptr runtime_components_factory_) + ContextShared(std::unique_ptr runtime_components_factory_) : runtime_components_factory(std::move(runtime_components_factory_)), macros(std::make_unique()) { /// TODO: make it singleton (?) @@ -318,7 +318,7 @@ Context::Context(const Context &) = default; Context & Context::operator=(const Context &) = default; -Context Context::createGlobal(std::unique_ptr runtime_components_factory) +Context Context::createGlobal(std::unique_ptr runtime_components_factory) { Context res; res.shared = std::make_shared(std::move(runtime_components_factory)); diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index 9c001916347..6b074acf056 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -43,7 +43,7 @@ namespace DB struct ContextShared; class Context; -class IRuntimeComponentsFactory; +class RuntimeComponentsFactory; class QuotaForIntervals; class EmbeddedDictionaries; class ExternalDictionaries; @@ -174,7 +174,7 @@ private: public: /// Create initial Context with ContextShared and etc. - static Context createGlobal(std::unique_ptr runtime_components_factory); + static Context createGlobal(std::unique_ptr runtime_components_factory); static Context createGlobal(); Context(const Context &); diff --git a/dbms/src/Interpreters/ExternalLoader.cpp b/dbms/src/Interpreters/ExternalLoader.cpp index 6e16fd37cba..fb6464fb217 100644 --- a/dbms/src/Interpreters/ExternalLoader.cpp +++ b/dbms/src/Interpreters/ExternalLoader.cpp @@ -985,7 +985,7 @@ public: return std::chrono::system_clock::now() + std::chrono::seconds{distribution(rnd_engine)}; } - return std::chrono::system_clock::now() + std::chrono::seconds(ExternalLoadableBackoff{}.calculateDuration(rnd_engine, error_count)); + return std::chrono::system_clock::now() + std::chrono::seconds(calculateDurationWithBackoff(rnd_engine, error_count)); } private: diff --git a/dbms/src/Interpreters/ExternalLoader.h b/dbms/src/Interpreters/ExternalLoader.h index ecfc43c2dd9..4976c28d8e6 100644 --- a/dbms/src/Interpreters/ExternalLoader.h +++ b/dbms/src/Interpreters/ExternalLoader.h @@ -29,7 +29,7 @@ struct ExternalLoaderConfigSettings }; -/** Manages user-defined objects. +/** Iterface for manage user-defined objects. * Monitors configuration file and automatically reloads objects in separate threads. * The monitoring thread wakes up every 'check_period_sec' seconds and checks * modification time of objects' configuration file. If said time is greater than diff --git a/dbms/src/Interpreters/IExternalLoadable.cpp b/dbms/src/Interpreters/IExternalLoadable.cpp index e8bf8cbaf3c..18439cf999f 100644 --- a/dbms/src/Interpreters/IExternalLoadable.cpp +++ b/dbms/src/Interpreters/IExternalLoadable.cpp @@ -17,8 +17,11 @@ ExternalLoadableLifetime::ExternalLoadableLifetime(const Poco::Util::AbstractCon } -UInt64 ExternalLoadableBackoff::calculateDuration(pcg64 & rnd_engine, size_t error_count) const +UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count) { + constexpr UInt64 backoff_initial_sec = 5; + constexpr UInt64 backoff_max_sec = 10 * 60; /// 10 minutes + if (error_count < 1) error_count = 1; std::uniform_int_distribution distribution(0, static_cast(std::exp2(error_count - 1))); diff --git a/dbms/src/Interpreters/IExternalLoadable.h b/dbms/src/Interpreters/IExternalLoadable.h index e842fdb8573..d4b93c56d2a 100644 --- a/dbms/src/Interpreters/IExternalLoadable.h +++ b/dbms/src/Interpreters/IExternalLoadable.h @@ -25,17 +25,8 @@ struct ExternalLoadableLifetime ExternalLoadableLifetime(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix); }; - -/// Delay before trying to load again after error. -struct ExternalLoadableBackoff -{ - UInt64 backoff_initial_sec = 5; - UInt64 backoff_max_sec = 10 * 60; /// 10 minutes - - /// Calculates time to try loading again after error. - UInt64 calculateDuration(pcg64 & rnd_engine, size_t error_count = 1) const; -}; - +/// Get delay before trying to load again after error. +UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count = 1); /// Basic interface for external loadable objects. Is used in ExternalLoader. class IExternalLoadable : public std::enable_shared_from_this, private boost::noncopyable diff --git a/dbms/src/Interpreters/IRuntimeComponentsFactory.h b/dbms/src/Interpreters/IRuntimeComponentsFactory.h deleted file mode 100644 index 1577b6b691d..00000000000 --- a/dbms/src/Interpreters/IRuntimeComponentsFactory.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -namespace DB -{ - -/** Factory of query engine runtime components / services. - * Helps to host query engine in external applications - * by replacing or reconfiguring its components. - */ -class IRuntimeComponentsFactory -{ -public: - virtual ~IRuntimeComponentsFactory() = default; - - virtual std::unique_ptr createUsersManager() = 0; - - virtual std::unique_ptr createGeoDictionariesLoader() = 0; - - // Repositories with configurations of user-defined objects (dictionaries, models) - virtual std::unique_ptr createExternalDictionariesConfigRepository() = 0; - - virtual std::unique_ptr createExternalModelsConfigRepository() = 0; -}; - -} diff --git a/dbms/src/Interpreters/RuntimeComponentsFactory.h b/dbms/src/Interpreters/RuntimeComponentsFactory.h index 4c319911b39..e2b8310dd8c 100644 --- a/dbms/src/Interpreters/RuntimeComponentsFactory.h +++ b/dbms/src/Interpreters/RuntimeComponentsFactory.h @@ -2,7 +2,6 @@ #include #include -#include #include namespace DB @@ -11,25 +10,25 @@ namespace DB /** Default implementation of runtime components factory * used by native server application. */ -class RuntimeComponentsFactory : public IRuntimeComponentsFactory +class RuntimeComponentsFactory { public: - std::unique_ptr createUsersManager() override + std::unique_ptr createUsersManager() { return std::make_unique(); } - std::unique_ptr createGeoDictionariesLoader() override + std::unique_ptr createGeoDictionariesLoader() { return std::make_unique(); } - std::unique_ptr createExternalDictionariesConfigRepository() override + std::unique_ptr createExternalDictionariesConfigRepository() { return std::make_unique(); } - std::unique_ptr createExternalModelsConfigRepository() override + std::unique_ptr createExternalModelsConfigRepository() { return std::make_unique(); }