Avoid herd effect in ReplicatedMergeTreeCleanupThread [#CLICKHOUSE-2]

This commit is contained in:
Alexey Milovidov 2018-04-06 22:43:37 +03:00
parent af226d62f5
commit fa776b93c2
3 changed files with 10 additions and 1 deletions

View File

@ -104,6 +104,9 @@ struct MergeTreeSettings
\ \
/** Period to clean old queue logs, blocks hashes and parts */ \ /** Period to clean old queue logs, blocks hashes and parts */ \
M(SettingUInt64, cleanup_delay_period, 30) \ M(SettingUInt64, cleanup_delay_period, 30) \
/** Add uniformly distributed value from 0 to x seconds to cleanup_delay_period \
to avoid thundering herd effect and subsequent DoS of ZooKeeper in case of very large number of tables */ \
M(SettingUInt64, cleanup_delay_period_random_add, 10) \
\ \
/** Minimal delay from other replicas to yield leadership. Here and further 0 means unlimited. */ \ /** Minimal delay from other replicas to yield leadership. Here and further 0 means unlimited. */ \
M(SettingUInt64, min_relative_delay_to_yield_leadership, 120) \ M(SettingUInt64, min_relative_delay_to_yield_leadership, 120) \

View File

@ -3,6 +3,8 @@
#include <Common/setThreadName.h> #include <Common/setThreadName.h>
#include <Poco/Timestamp.h> #include <Poco/Timestamp.h>
#include <random>
namespace DB namespace DB
{ {
@ -25,7 +27,8 @@ void ReplicatedMergeTreeCleanupThread::run()
{ {
setThreadName("ReplMTCleanup"); setThreadName("ReplMTCleanup");
const auto CLEANUP_SLEEP_MS = storage.data.settings.cleanup_delay_period * 1000; const auto CLEANUP_SLEEP_MS = (storage.data.settings.cleanup_delay_period
+ std::uniform_int_distribution<UInt64>(0, storage.data.settings.cleanup_delay_period_random_add)(rng)) * 1000;
while (!storage.shutdown_called) while (!storage.shutdown_called)
{ {

View File

@ -7,6 +7,8 @@
#include <thread> #include <thread>
#include <map> #include <map>
#include <pcg_random.hpp>
namespace DB namespace DB
{ {
@ -27,6 +29,7 @@ private:
StorageReplicatedMergeTree & storage; StorageReplicatedMergeTree & storage;
Logger * log; Logger * log;
std::thread thread; std::thread thread;
pcg64 rng;
void run(); void run();
void iterate(); void iterate();