aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MySQL/MySQLHelpers.cpp
blob: 3d9f04f65027fe6131018707c1fbad831ec122d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "MySQLHelpers.h"

#if USE_MYSQL
#error #include <mysqlxx/PoolWithFailover.h>
#include <Storages/MySQL/MySQLSettings.h>

namespace DB
{

namespace ErrorCodes
{
    extern const int BAD_ARGUMENTS;
}

mysqlxx::PoolWithFailover createMySQLPoolWithFailover(const StorageMySQL::Configuration & configuration, const MySQLSettings & mysql_settings)
{
    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)
{
    if (!mysql_settings.connection_pool_size)
        throw Exception(ErrorCodes::BAD_ARGUMENTS, "Connection pool cannot have zero size");

    return mysqlxx::PoolWithFailover(
        database, addresses, username, password,
        MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
        static_cast<unsigned>(mysql_settings.connection_pool_size),
        mysql_settings.connection_max_tries,
        mysql_settings.connection_wait_timeout,
        mysql_settings.connect_timeout,
        mysql_settings.read_write_timeout);
}

}

#endif