1 | #include <Interpreters/IExternalLoadable.h> |
---|---|
2 | |
3 | #include <Poco/Util/AbstractConfiguration.h> |
4 | #include <cmath> |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | ExternalLoadableLifetime::ExternalLoadableLifetime(const Poco::Util::AbstractConfiguration & config, |
10 | const std::string & config_prefix) |
11 | { |
12 | const auto & lifetime_min_key = config_prefix + ".min"; |
13 | const auto has_min = config.has(lifetime_min_key); |
14 | |
15 | min_sec = has_min ? config.getUInt64(lifetime_min_key) : config.getUInt64(config_prefix); |
16 | max_sec = has_min ? config.getUInt64(config_prefix + ".max") : min_sec; |
17 | } |
18 | |
19 | |
20 | UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count) |
21 | { |
22 | constexpr UInt64 backoff_initial_sec = 5; |
23 | constexpr UInt64 backoff_max_sec = 10 * 60; /// 10 minutes |
24 | |
25 | if (error_count < 1) |
26 | error_count = 1; |
27 | |
28 | /// max seconds is 600 and 2 ** 10 == 1024 |
29 | if (error_count > 11) |
30 | error_count = 11; |
31 | |
32 | std::uniform_int_distribution<UInt64> distribution(0, static_cast<UInt64>(std::exp2(error_count - 1))); |
33 | return std::min<UInt64>(backoff_max_sec, backoff_initial_sec + distribution(rnd_engine)); |
34 | } |
35 | |
36 | } |
37 |