-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list of hosts with ports for setting connection #1
base: master
Are you sure you want to change the base?
Conversation
if (!Handshake()) { | ||
throw std::runtime_error("fail to connect to " + host_port.host); | ||
} | ||
} catch (...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to catch specific error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it better? We can't predict what type of object will be thrown. Yea, in this function we throw only runtime_error
, but we don't exactly know what could be thrown from functions, that are used in ResetConnection
.
Moreover, in RetryGuard
previous developers don't catch specific error -- they also use ...
. It is partly confirms hypothesis, that any object can be thrown from subfunctions of ResetConnetction
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't predict the type of exception, we don't know the code. But we should do.
It is better because when you read the code, you understand what you throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can catch runtime_error and other exceptions and then use the ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/simple/main.cpp
Outdated
@@ -510,6 +510,67 @@ int main() { | |||
.SetCompressionMethod(CompressionMethod::LZ4)); | |||
RunTests(client); | |||
} | |||
|
|||
{ | |||
std::cout << "test 1" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give names to tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oo, I deleted this line before review, but fogot to commit it. I think I would better to leave tests without names, because previous tests don't have names.
@@ -481,7 +481,7 @@ static void RunTests(Client& client) { | |||
ArrayExample(client); | |||
CancelableExample(client); | |||
DateExample(client); | |||
DateTime64Example(client); | |||
// DateTime64Example(client); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't delete tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also forgot to commit uncommented line.
I had commented it because this example always fails there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, you are right, but I am not sure it's your problem, so you can keep it unchanged for now
tests/simple/main.cpp
Outdated
ClientOptions::HostPort("1127.91.2.2"), // wrong host | ||
ClientOptions::HostPort("notlocalwronghost"), // wrong host | ||
ClientOptions::HostPort("another_notlocalwronghost"), // wrong host | ||
ClientOptions::HostPort("localhost", 9000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you assert somehow that you have connected to exactly this host? And please add some more hosts after this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clickhouse/client.h
Outdated
std::string host = std::string(); | ||
inline ClientOptions& SetHost(const std::string& value) { | ||
hosts_ports.emplace_back(value, std::nullopt); | ||
host = hosts_ports.back().host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so you keep host and HostPort. So host is duplicated. Can it be kept just one time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be kept just one time, I made relevant changes.
clickhouse/client.cpp
Outdated
<< " ping_before_query:" << opt.ping_before_query | ||
os << "Client(" << opt.user << '@' << "{ "; | ||
for (const ClientOptions::HostPort& hp : opt.hosts_ports) { | ||
os << hp.host << ":" << opt.port << ","; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to make output so that if you have just one host it is the same as before your changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and also fixed other errors (like forgotten }
, etc)
clickhouse/client.h
Outdated
/// Hostname of the server. | ||
DECLARE_FIELD(host, std::string, SetHost, std::string()); | ||
std::string host = std::string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to remove it so not to duplicate. If you don't remove it somehow, you need to declare this field with DECLARE_FIELD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remove host
because it is a public field.
I returned declaration by DECLARE_FIELD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, ok, leave it as is for now. But it would be great to write it in the pull request description that the host field is "duplicated"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this host is duplicated? Now host in host
field isn't stored in hosts_ports
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
SetHost
can takestd::vector
ofClientOptions::HostPort
structures, that contains host name and optionally port number. IfHostPort.port
isnullopt
, then port fromSetPort
(or default port ifSetPort
wasn't called) is used.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. If list ends up,ResetConnection
throws exception of last host.