2019-06-02 12:11:01 +00:00
|
|
|
#include <Interpreters/IExternalLoadable.h>
|
|
|
|
|
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2019-08-30 09:50:38 +00:00
|
|
|
#include <cmath>
|
2019-06-02 12:11:01 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ExternalLoadableLifetime::ExternalLoadableLifetime(const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix)
|
|
|
|
{
|
|
|
|
const auto & lifetime_min_key = config_prefix + ".min";
|
|
|
|
const auto has_min = config.has(lifetime_min_key);
|
|
|
|
|
|
|
|
min_sec = has_min ? config.getUInt64(lifetime_min_key) : config.getUInt64(config_prefix);
|
|
|
|
max_sec = has_min ? config.getUInt64(config_prefix + ".max") : min_sec;
|
|
|
|
}
|
|
|
|
|
2019-08-30 09:50:38 +00:00
|
|
|
|
2019-09-26 10:08:38 +00:00
|
|
|
UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count)
|
2019-08-30 09:50:38 +00:00
|
|
|
{
|
2019-09-26 10:08:38 +00:00
|
|
|
constexpr UInt64 backoff_initial_sec = 5;
|
|
|
|
constexpr UInt64 backoff_max_sec = 10 * 60; /// 10 minutes
|
|
|
|
|
2019-08-30 09:50:38 +00:00
|
|
|
if (error_count < 1)
|
|
|
|
error_count = 1;
|
|
|
|
std::uniform_int_distribution<UInt64> distribution(0, static_cast<UInt64>(std::exp2(error_count - 1)));
|
|
|
|
return std::min<UInt64>(backoff_max_sec, backoff_initial_sec + distribution(rnd_engine));
|
|
|
|
}
|
|
|
|
|
2019-06-02 12:11:01 +00:00
|
|
|
}
|