Skip to content

Commit bcda867

Browse files
committed
try to reconnect send_retries times before throw in RetryGuard (#112)
1 parent be9bc8f commit bcda867

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

clickhouse/client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Client::Impl::Impl(const ClientOptions& opts)
160160
, buffered_output_(&socket_output_)
161161
, output_(&buffered_output_)
162162
{
163-
for (int i = 0; ; ) {
163+
for (unsigned int i = 0; ; ) {
164164
try {
165165
ResetConnection();
166166
break;
@@ -729,7 +729,7 @@ bool Client::Impl::ReceiveHello() {
729729
}
730730

731731
void Client::Impl::RetryGuard(std::function<void()> func) {
732-
for (int i = 0; i <= options_.send_retries; ++i) {
732+
for (unsigned int i = 0; ; ++i) {
733733
try {
734734
func();
735735
return;
@@ -743,7 +743,7 @@ void Client::Impl::RetryGuard(std::function<void()> func) {
743743
ok = false;
744744
}
745745

746-
if (!ok) {
746+
if (!ok && i == options_.send_retries) {
747747
throw;
748748
}
749749
}

clickhouse/client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct ClientOptions {
3939
/// Hostname of the server.
4040
DECLARE_FIELD(host, std::string, SetHost, std::string());
4141
/// Service port.
42-
DECLARE_FIELD(port, int, SetPort, 9000);
42+
DECLARE_FIELD(port, unsigned int, SetPort, 9000);
4343

4444
/// Default database.
4545
DECLARE_FIELD(default_database, std::string, SetDefaultDatabase, "default");
@@ -56,7 +56,7 @@ struct ClientOptions {
5656
/// Ping server every time before execute any query.
5757
DECLARE_FIELD(ping_before_query, bool, SetPingBeforeQuery, false);
5858
/// Count of retry to send request to server.
59-
DECLARE_FIELD(send_retries, int, SetSendRetries, 1);
59+
DECLARE_FIELD(send_retries, unsigned int, SetSendRetries, 1);
6060
/// Amount of time to wait before next retry.
6161
DECLARE_FIELD(retry_timeout, std::chrono::seconds, SetRetryTimeout, std::chrono::seconds(5));
6262

@@ -67,7 +67,7 @@ struct ClientOptions {
6767
DECLARE_FIELD(tcp_keepalive, bool, TcpKeepAlive, false);
6868
DECLARE_FIELD(tcp_keepalive_idle, std::chrono::seconds, SetTcpKeepAliveIdle, std::chrono::seconds(60));
6969
DECLARE_FIELD(tcp_keepalive_intvl, std::chrono::seconds, SetTcpKeepAliveInterval, std::chrono::seconds(5));
70-
DECLARE_FIELD(tcp_keepalive_cnt, int, SetTcpKeepAliveCount, 3);
70+
DECLARE_FIELD(tcp_keepalive_cnt, unsigned int, SetTcpKeepAliveCount, 3);
7171

7272
#undef DECLARE_FIELD
7373
};

0 commit comments

Comments
 (0)