diff --git a/README.md b/README.md index 3d70ae46..ac64d979 100644 --- a/README.md +++ b/README.md @@ -76,3 +76,10 @@ client.Select("SELECT id, name FROM test.numbers", [] (const Block& block) client.Execute("DROP TABLE test.numbers"); ``` Please note that `Client` instance is NOT thread-safe. I.e. you must create a separate `Client` for each thread or utilize some synchronization techniques. + +## Retries +If you wish to implement some retry logic atop of `clickhouse::Client` there are few simple rules to make you life easier: +- If previous attempt threw an exception, then make sure to call `clickhouse::Client::ResetConnection()` before the next try. +- For `clickhouse::Client::Insert()` you can reuse a block from previous try, no need to rebuild it from scratch. + +See https://github.com/ClickHouse/clickhouse-cpp/issues/184 for details. diff --git a/clickhouse/CMakeLists.txt b/clickhouse/CMakeLists.txt index 6a851241..d96ff88a 100644 --- a/clickhouse/CMakeLists.txt +++ b/clickhouse/CMakeLists.txt @@ -84,6 +84,7 @@ INSTALL(FILES block.h DESTINATION include/clickhouse/) INSTALL(FILES client.h DESTINATION include/clickhouse/) INSTALL(FILES error_codes.h DESTINATION include/clickhouse/) INSTALL(FILES exceptions.h DESTINATION include/clickhouse/) +INSTALL(FILES server_exception.h DESTINATION include/clickhouse/) INSTALL(FILES protocol.h DESTINATION include/clickhouse/) INSTALL(FILES query.h DESTINATION include/clickhouse/) diff --git a/clickhouse/base/socket.cpp b/clickhouse/base/socket.cpp index a11cd2f8..c6dc920e 100644 --- a/clickhouse/base/socket.cpp +++ b/clickhouse/base/socket.cpp @@ -181,7 +181,9 @@ NetworkAddress::NetworkAddress(const std::string& host, const std::string& port) hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - + // using AI_ADDRCONFIG on windows will cause getaddrinfo to return WSAHOST_NOT_FOUND + // for more information, see https://github.com/ClickHouse/clickhouse-cpp/issues/195 +#if defined(_unix_) if (!Singleton()->IsLocalName(host)) { // https://linux.die.net/man/3/getaddrinfo // If hints.ai_flags includes the AI_ADDRCONFIG flag, @@ -193,6 +195,7 @@ NetworkAddress::NetworkAddress(const std::string& host, const std::string& port) // as valid as a configured address. hints.ai_flags |= AI_ADDRCONFIG; } +#endif const int error = getaddrinfo(host.c_str(), port.c_str(), &hints, &info_);