mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Translated comments [#CLICKHOUSE-2].
This commit is contained in:
parent
9bb647d5d5
commit
c477c7e1cb
@ -3,18 +3,19 @@
|
||||
#include "Pool.h"
|
||||
|
||||
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS 1
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS 16
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES 3
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS 1
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS 16
|
||||
#define MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES 3
|
||||
|
||||
|
||||
namespace mysqlxx
|
||||
{
|
||||
/** Пул соединений с MySQL.
|
||||
* Знает о наборе реплик с приоритетами.
|
||||
* Пробует соединяться с репликами в порядке приоритета. При равном приоритете предпочитается реплика, к которой дольше всего не было попытки подключения.
|
||||
/** MySQL connection pool with support of failover.
|
||||
* Have information about replicas and their priorities.
|
||||
* Tries to connect to replica in an order of priority. When equal priority, choose replica with maximum time without connections.
|
||||
*
|
||||
* It could be configured without replicas, exactly as ordinary Pool:
|
||||
*
|
||||
* Использование аналогично mysqlxx::Pool. В конфиге задание сервера может выглядеть так же, как для Pool:
|
||||
* <mysql_metrica>
|
||||
* <host>mtstat01c*</host>
|
||||
* <port>3306</port>
|
||||
@ -23,7 +24,7 @@ namespace mysqlxx
|
||||
* <db>Metrica</db>
|
||||
* </mysql_metrica>
|
||||
*
|
||||
* или так:
|
||||
* Or like this:
|
||||
*
|
||||
* <mysql_metrica>
|
||||
* <replica>
|
||||
@ -44,14 +45,14 @@ namespace mysqlxx
|
||||
* </replica>
|
||||
* </mysql_metrica>
|
||||
*
|
||||
* или так:
|
||||
* Or like this:
|
||||
*
|
||||
* <mysql_metrica>
|
||||
* <port>3306</port>
|
||||
* <port>3306</port>
|
||||
* <user>metrica</user>
|
||||
* <password></password>
|
||||
* <db>Metrica</db>
|
||||
* <replica>
|
||||
* <replica>
|
||||
* <host>mtstat01c</host>
|
||||
* <priority>0</priority>
|
||||
* </replica>
|
||||
@ -78,24 +79,24 @@ namespace mysqlxx
|
||||
};
|
||||
|
||||
using Replicas = std::vector<Replica>;
|
||||
/// [приоритет][номер] -> реплика.
|
||||
/// [priority][index] -> replica.
|
||||
using ReplicasByPriority = std::map<int, Replicas>;
|
||||
|
||||
ReplicasByPriority replicas_by_priority;
|
||||
|
||||
/// Количество попыток подключения.
|
||||
/// Number of connection tries.
|
||||
size_t max_tries;
|
||||
/// Mutex для доступа к списку реплик.
|
||||
/// Mutex for set of replicas.
|
||||
std::mutex mutex;
|
||||
|
||||
public:
|
||||
using Entry = Pool::Entry;
|
||||
|
||||
/**
|
||||
* @param config_name Имя параметра в конфигурационном файле.
|
||||
* @param default_connections Количество подключений по умолчанию к какждой реплике.
|
||||
* @param max_connections Максимальное количество подключений к какждой реплике.
|
||||
* @param max_tries_ Количество попыток подключения.
|
||||
* config_name Name of parameter in configuration file.
|
||||
* default_connections Number of connection in pool to each replica at start.
|
||||
* max_connections Maximum number of connections in pool to each replica.
|
||||
* max_tries_ Max number of connection tries.
|
||||
*/
|
||||
PoolWithFailover(const std::string & config_name,
|
||||
unsigned default_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
|
||||
@ -112,7 +113,7 @@ namespace mysqlxx
|
||||
|
||||
PoolWithFailover & operator=(const PoolWithFailover &) = delete;
|
||||
|
||||
/** Выделяет соединение для работы. */
|
||||
/** Allocates a connection to use. */
|
||||
Entry Get();
|
||||
};
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & cfg
|
||||
{
|
||||
Poco::Util::AbstractConfiguration::Keys replica_keys;
|
||||
cfg.keys(config_name, replica_keys);
|
||||
for (Poco::Util::AbstractConfiguration::Keys::const_iterator it = replica_keys.begin(); it != replica_keys.end(); ++it)
|
||||
for (const auto & replica_config_key : replica_keys)
|
||||
{
|
||||
if (*it == "replica") /// На том же уровне могут быть другие параметры.
|
||||
if (replica_config_key == "replica") /// There could be another elements in the same level in configuration file.
|
||||
{
|
||||
std::string replica_name = config_name + "." + *it;
|
||||
std::string replica_name = config_name + "." + replica_config_key;
|
||||
Replica replica(std::make_shared<Pool>(cfg, replica_name, default_connections, max_connections, config_name.c_str()),
|
||||
cfg.getInt(replica_name + ".priority", 0));
|
||||
replicas_by_priority[replica.priority].push_back(replica);
|
||||
@ -34,8 +34,7 @@ PoolWithFailover::PoolWithFailover(const std::string & config_name, const unsign
|
||||
const unsigned max_connections, const size_t max_tries)
|
||||
: PoolWithFailover{
|
||||
Poco::Util::Application::instance().config(), config_name,
|
||||
default_connections, max_connections, max_tries
|
||||
}
|
||||
default_connections, max_connections, max_tries}
|
||||
{}
|
||||
|
||||
PoolWithFailover::PoolWithFailover(const PoolWithFailover & other)
|
||||
@ -56,7 +55,7 @@ PoolWithFailover::Entry PoolWithFailover::Get()
|
||||
std::lock_guard<std::mutex> locker(mutex);
|
||||
Poco::Util::Application & app = Poco::Util::Application::instance();
|
||||
|
||||
/// Если к какой-то реплике не подключились, потому что исчерпан лимит соединений, можно подождать и подключиться к ней.
|
||||
/// If we cannot connect to some replica due to pool overflow, than we will wait and connect.
|
||||
Replica * full_pool = nullptr;
|
||||
|
||||
for (size_t try_no = 0; try_no < max_tries; ++try_no)
|
||||
@ -76,8 +75,8 @@ PoolWithFailover::Entry PoolWithFailover::Get()
|
||||
|
||||
if (!entry.isNull())
|
||||
{
|
||||
/// Переместим все пройденные реплики в конец очереди.
|
||||
/// Пройденные реплики с другим приоритетом перемещать незачем.
|
||||
/// Move all traversed replicas to the end of queue.
|
||||
/// (No need to move replicas with another priority)
|
||||
std::rotate(replicas.begin(), replicas.begin() + i + 1, replicas.end());
|
||||
|
||||
return entry;
|
||||
|
Loading…
Reference in New Issue
Block a user