Remove runtime factory and remove one redundant object

This commit is contained in:
alesapin 2019-09-26 13:08:38 +03:00
parent df8cb4b619
commit 903f826640
9 changed files with 19 additions and 57 deletions

View File

@ -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)));

View File

@ -97,7 +97,7 @@ struct ContextShared
{
Logger * log = &Logger::get("Context");
std::unique_ptr<IRuntimeComponentsFactory> runtime_components_factory;
std::unique_ptr<RuntimeComponentsFactory> 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<IRuntimeComponentsFactory> runtime_components_factory_)
ContextShared(std::unique_ptr<RuntimeComponentsFactory> runtime_components_factory_)
: runtime_components_factory(std::move(runtime_components_factory_)), macros(std::make_unique<Macros>())
{
/// 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<IRuntimeComponentsFactory> runtime_components_factory)
Context Context::createGlobal(std::unique_ptr<RuntimeComponentsFactory> runtime_components_factory)
{
Context res;
res.shared = std::make_shared<ContextShared>(std::move(runtime_components_factory));

View File

@ -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<IRuntimeComponentsFactory> runtime_components_factory);
static Context createGlobal(std::unique_ptr<RuntimeComponentsFactory> runtime_components_factory);
static Context createGlobal();
Context(const Context &);

View File

@ -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:

View File

@ -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

View File

@ -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<UInt64> distribution(0, static_cast<UInt64>(std::exp2(error_count - 1)));

View File

@ -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<IExternalLoadable>, private boost::noncopyable

View File

@ -1,31 +0,0 @@
#pragma once
#include <Dictionaries/Embedded/IGeoDictionariesLoader.h>
#include <Interpreters/IExternalLoaderConfigRepository.h>
#include <Interpreters/IUsersManager.h>
#include <memory>
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<IUsersManager> createUsersManager() = 0;
virtual std::unique_ptr<IGeoDictionariesLoader> createGeoDictionariesLoader() = 0;
// Repositories with configurations of user-defined objects (dictionaries, models)
virtual std::unique_ptr<IExternalLoaderConfigRepository> createExternalDictionariesConfigRepository() = 0;
virtual std::unique_ptr<IExternalLoaderConfigRepository> createExternalModelsConfigRepository() = 0;
};
}

View File

@ -2,7 +2,6 @@
#include <Dictionaries/Embedded/GeoDictionariesLoader.h>
#include <Interpreters/ExternalLoaderConfigRepository.h>
#include <Interpreters/IRuntimeComponentsFactory.h>
#include <Interpreters/UsersManager.h>
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<IUsersManager> createUsersManager() override
std::unique_ptr<IUsersManager> createUsersManager()
{
return std::make_unique<UsersManager>();
}
std::unique_ptr<IGeoDictionariesLoader> createGeoDictionariesLoader() override
std::unique_ptr<IGeoDictionariesLoader> createGeoDictionariesLoader()
{
return std::make_unique<GeoDictionariesLoader>();
}
std::unique_ptr<IExternalLoaderConfigRepository> createExternalDictionariesConfigRepository() override
std::unique_ptr<IExternalLoaderConfigRepository> createExternalDictionariesConfigRepository()
{
return std::make_unique<ExternalLoaderConfigRepository>();
}
std::unique_ptr<IExternalLoaderConfigRepository> createExternalModelsConfigRepository() override
std::unique_ptr<IExternalLoaderConfigRepository> createExternalModelsConfigRepository()
{
return std::make_unique<ExternalLoaderConfigRepository>();
}