clickhouse-cpp icon indicating copy to clipboard operation
clickhouse-cpp copied to clipboard

Add list of hosts with ports for setting connection

Open df530 opened this issue 3 years ago • 5 comments

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.

df530 avatar Jan 11 '22 17:01 df530

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 11 '22 17:01 CLAassistant

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

PolyProgrammist avatar Jan 19 '22 21:01 PolyProgrammist

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.

filimonov avatar Jan 20 '22 10:01 filimonov

@DF5HSE ping?

Enmk avatar May 03 '22 09:05 Enmk

@Enmk hi, I have just started to continue working on this pr. Hope it will be ready soon

PolyProgrammist avatar May 03 '22 10:05 PolyProgrammist

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?

MikhailBurdukov avatar May 15 '23 13:05 MikhailBurdukov

@Enmk ping?

MikhailBurdukov avatar May 23 '23 08:05 MikhailBurdukov