mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Randomly shuffle replicas withing the same priority
This commit is contained in:
parent
42c22475e3
commit
acb5fb8179
@ -1,3 +1,6 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include <mysqlxx/PoolWithFailover.h>
|
#include <mysqlxx/PoolWithFailover.h>
|
||||||
|
|
||||||
|
|
||||||
@ -7,6 +10,8 @@ static bool startsWith(const std::string & s, const char * prefix)
|
|||||||
return s.size() >= strlen(prefix) && 0 == memcmp(s.data(), prefix, strlen(prefix));
|
return s.size() >= strlen(prefix) && 0 == memcmp(s.data(), prefix, strlen(prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is thread-safe
|
||||||
|
std::random_device rd;
|
||||||
|
|
||||||
using namespace mysqlxx;
|
using namespace mysqlxx;
|
||||||
|
|
||||||
@ -33,6 +38,13 @@ PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & con
|
|||||||
std::make_shared<Pool>(config_, replica_name, default_connections_, max_connections_, config_name_.c_str()));
|
std::make_shared<Pool>(config_, replica_name, default_connections_, max_connections_, config_name_.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static thread_local std::mt19937 rnd_generator(rd());
|
||||||
|
for (auto & [_, replicas] : replicas_by_priority)
|
||||||
|
{
|
||||||
|
if (replicas.size() > 1)
|
||||||
|
std::shuffle(replicas.begin(), replicas.end(), rnd_generator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user