2021-12-13 22:06:46 +00:00
|
|
|
#include "MySQLHelpers.h"
|
|
|
|
|
|
|
|
#if USE_MYSQL
|
|
|
|
#include <mysqlxx/PoolWithFailover.h>
|
|
|
|
#include <Storages/MySQL/MySQLSettings.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-12-27 14:41:37 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
2023-02-20 20:37:38 +00:00
|
|
|
mysqlxx::PoolWithFailover createMySQLPoolWithFailover(const StorageMySQL::Configuration & configuration, const MySQLSettings & mysql_settings)
|
2023-04-13 17:33:58 +00:00
|
|
|
{
|
|
|
|
return createMySQLPoolWithFailover(
|
|
|
|
configuration.database, configuration.addresses,
|
|
|
|
configuration.username, configuration.password, mysql_settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
mysqlxx::PoolWithFailover createMySQLPoolWithFailover(
|
|
|
|
const std::string & database,
|
|
|
|
const StorageMySQL::Configuration::Addresses & addresses,
|
|
|
|
const std::string & username,
|
|
|
|
const std::string & password,
|
|
|
|
const MySQLSettings & mysql_settings)
|
2021-12-13 22:06:46 +00:00
|
|
|
{
|
2021-12-27 14:41:37 +00:00
|
|
|
if (!mysql_settings.connection_pool_size)
|
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Connection pool cannot have zero size");
|
|
|
|
|
2021-12-13 22:06:46 +00:00
|
|
|
return mysqlxx::PoolWithFailover(
|
2023-04-13 17:33:58 +00:00
|
|
|
database, addresses, username, password,
|
2021-12-13 22:06:46 +00:00
|
|
|
MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
|
2022-10-07 10:46:45 +00:00
|
|
|
static_cast<unsigned>(mysql_settings.connection_pool_size),
|
2021-12-13 22:06:46 +00:00
|
|
|
mysql_settings.connection_max_tries,
|
|
|
|
mysql_settings.connection_wait_timeout,
|
|
|
|
mysql_settings.connect_timeout,
|
|
|
|
mysql_settings.read_write_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|