Added some explanations on randomization

This commit is contained in:
Alexander Kazakov 2021-02-17 21:51:05 +03:00
parent acb5fb8179
commit 0296d7d026

View File

@ -10,7 +10,7 @@ static bool startsWith(const std::string & s, const char * prefix)
return s.size() >= strlen(prefix) && 0 == memcmp(s.data(), prefix, strlen(prefix));
}
/// This is thread-safe
/// This reads from "/dev/urandom" and thus is thread-safe
std::random_device rd;
using namespace mysqlxx;
@ -39,6 +39,11 @@ PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & con
}
}
/// PoolWithFailover objects are stored in a cache inside PoolFactory.
/// This cache is reset by ExternalDictionariesLoader after every SYSTEM RELOAD DICTIONAR{Y|IES}
/// which triggers massive re-constructing of connection pools.
/// The state of PRNDGs like std::mt19937 is considered to be quite heavy
/// thus here we attempt to optimize its construction.
static thread_local std::mt19937 rnd_generator(rd());
for (auto & [_, replicas] : replicas_by_priority)
{