From 4f8e8bf74be810e4a03f747b5d6a52bc2b1b701d Mon Sep 17 00:00:00 2001 From: Pavel Artemkin Date: Sun, 14 Jun 2020 08:52:57 +0500 Subject: [PATCH] try to reconnect send_retries times before throw in RetryGuard (artpaul#112) --- clickhouse/client.cpp | 6 +++--- clickhouse/client.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp index 72606376..60765408 100644 --- a/clickhouse/client.cpp +++ b/clickhouse/client.cpp @@ -173,7 +173,7 @@ Client::Impl::Impl(const ClientOptions& opts) { // TODO: throw on big-endianness of platform - for (int i = 0; ; ) { + for (unsigned int i = 0; ; ) { try { ResetConnection(); break; @@ -731,7 +731,7 @@ bool Client::Impl::ReceiveHello() { } void Client::Impl::RetryGuard(std::function func) { - for (int i = 0; i <= options_.send_retries; ++i) { + for (unsigned int i = 0; ; ++i) { try { func(); return; @@ -745,7 +745,7 @@ void Client::Impl::RetryGuard(std::function func) { ok = false; } - if (!ok) { + if (!ok && i == options_.send_retries) { throw; } } diff --git a/clickhouse/client.h b/clickhouse/client.h index 9882e768..3084a071 100644 --- a/clickhouse/client.h +++ b/clickhouse/client.h @@ -40,7 +40,7 @@ struct ClientOptions { /// Hostname of the server. DECLARE_FIELD(host, std::string, SetHost, std::string()); /// Service port. - DECLARE_FIELD(port, int, SetPort, 9000); + DECLARE_FIELD(port, unsigned int, SetPort, 9000); /// Default database. DECLARE_FIELD(default_database, std::string, SetDefaultDatabase, "default"); @@ -57,7 +57,7 @@ struct ClientOptions { /// Ping server every time before execute any query. DECLARE_FIELD(ping_before_query, bool, SetPingBeforeQuery, false); /// Count of retry to send request to server. - DECLARE_FIELD(send_retries, int, SetSendRetries, 1); + DECLARE_FIELD(send_retries, unsigned int, SetSendRetries, 1); /// Amount of time to wait before next retry. DECLARE_FIELD(retry_timeout, std::chrono::seconds, SetRetryTimeout, std::chrono::seconds(5)); @@ -68,7 +68,7 @@ struct ClientOptions { DECLARE_FIELD(tcp_keepalive, bool, TcpKeepAlive, false); DECLARE_FIELD(tcp_keepalive_idle, std::chrono::seconds, SetTcpKeepAliveIdle, std::chrono::seconds(60)); DECLARE_FIELD(tcp_keepalive_intvl, std::chrono::seconds, SetTcpKeepAliveInterval, std::chrono::seconds(5)); - DECLARE_FIELD(tcp_keepalive_cnt, int, SetTcpKeepAliveCount, 3); + DECLARE_FIELD(tcp_keepalive_cnt, unsigned int, SetTcpKeepAliveCount, 3); #undef DECLARE_FIELD };