From c477c7e1cb5ecb91cc8440e5d70c137fed37392b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 27 Jul 2017 23:22:53 +0300 Subject: [PATCH] Translated comments [#CLICKHOUSE-2]. --- .../include/mysqlxx/PoolWithFailover.h | 39 ++++++++++--------- libs/libmysqlxx/src/PoolWithFailover.cpp | 15 ++++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libs/libmysqlxx/include/mysqlxx/PoolWithFailover.h b/libs/libmysqlxx/include/mysqlxx/PoolWithFailover.h index 6020f984ca6..18f656bfd9f 100644 --- a/libs/libmysqlxx/include/mysqlxx/PoolWithFailover.h +++ b/libs/libmysqlxx/include/mysqlxx/PoolWithFailover.h @@ -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: * * mtstat01c* * 3306 @@ -23,7 +24,7 @@ namespace mysqlxx * Metrica * * - * или так: + * Or like this: * * * @@ -44,14 +45,14 @@ namespace mysqlxx * * * - * или так: + * Or like this: * * - * 3306 + * 3306 * metrica * * Metrica - * + * * mtstat01c * 0 * @@ -78,24 +79,24 @@ namespace mysqlxx }; using Replicas = std::vector; - /// [приоритет][номер] -> реплика. + /// [priority][index] -> replica. using ReplicasByPriority = std::map; 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(); }; } diff --git a/libs/libmysqlxx/src/PoolWithFailover.cpp b/libs/libmysqlxx/src/PoolWithFailover.cpp index 6fe994a4fbc..1e2e8001931 100644 --- a/libs/libmysqlxx/src/PoolWithFailover.cpp +++ b/libs/libmysqlxx/src/PoolWithFailover.cpp @@ -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(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 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;