clickhouse-cpp
clickhouse-cpp copied to clipboard
Add list of hosts with ports for setting connection
It is possible to specify multiple hosts to connect to. It approves fault tolerance of connection because when one host isn't alive client can try to connect to another one. The connection will be set to the first available host.
Client client(ClientOptions()
.SetHost({
ClientOptions::HostPort("host1.com", 8000),
ClientOptions::HostPort("host2.com"), /// port is ClientOptions.port
}));
When ResetConnection is called, it tries to connect to the first host. If connection failed, then it tries to connect to the next host in list, while list doesn't end up (round-robin approach). If list ends up, ResetConnection throws exception of last host.
Looks good to me. I think it's better to merge commits in one. And providing more information about the reasons for commit (fault tolerance) and about the implementation (round robin) in pull request description would be great
The idea/motivation is clean. Maybe it would be clearer to push that logic a bit deeper?
Here we have iteration through different IPs which can be extracted from the same domain name: https://github.com/ClickHouse/clickhouse-cpp/blob/b36c87fb6f09376f71fbda671cae4c754afc7ea4/clickhouse/base/socket.cpp#L87-L88
Maybe we can generalize that code a bit for multiple hosts/ports cases instead of creating one more retry loop outside?
In that case, connect timeouts should work better.
@DF5HSE ping?
@Enmk hi, I have just started to continue working on this pr. Hope it will be ready soon
Hi! We think this feature will be very useful for us, so I would like to complete it. Can we reopen PR or is it better to open a new one?
@Enmk ping?