Skip to content
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

Client fault tolerant connection #12

Open
wants to merge 8,045 commits into
base: managed-feature/automatic-server-choosing
Choose a base branch
from

Conversation

DeKinci
Copy link
Collaborator

@DeKinci DeKinci commented Dec 13, 2021

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
...
Parameter host can accept multiple hosts. In case of unavailability of one of them, the client will try to connect to the next one.

Detailed description / Documentation draft:
...
When multiple addresses are passed to the host argument and the first one is unavailable, the console client will try to connect to the next one.

By adding documentation, you'll allow users to try your new feature immediately, not when someone else will have time to document it later. Documentation is necessary for all features that affect user experience in any way. You can add brief documentation draft above, or add documentation right into your patch as Markdown files in docs folder.

If you are doing this for the first time, it's recommended to read the lightweight Contributing to ClickHouse Documentation guide first.

Information about CI checks: https://clickhouse.tech/docs/en/development/continuous-integration/

String host;
std::optional<int> port{};
friend std::istream & operator>>(std::istream & in, HostPort & hostPort) {
String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use more common way:

String host_with_port;
String delimiter = ":";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

in >> host_with_port;
size_t delimiter_pos = host_with_port.find(delimiter);
hostPort.host = host_with_port.substr(0, delimiter_pos);
if (delimiter_pos < host_with_port.length())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delimiter_pos != std::string::npos

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

delimiter = ":";
in >> host_with_port;
size_t delimiter_pos = host_with_port.find(delimiter);
hostPort.host = host_with_port.substr(0, delimiter_pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move it also inside if and separately assign hostPort.host to host_with_port in else branch so that not to mess with host_with_port.substr(0, std::string::npos)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return in;
}
};
std::vector<HostPort> hosts_ports{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to delete the old host field

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no host field in ClientBase. The reason why I add this field in ClientBase, you can read our discussion in old PR: #4 (comment)

config().setString("host", options["host"].as<std::string>());
{
hosts_ports = options["host"].as<std::vector<HostPort>>();
config().setString("host", hosts_ports[0].host);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to set all the hosts and ports instead of just one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config can't store std::vector , only String, Int and other simple types. I wrote about this in this PR: #4 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

String server_name;
UInt64 server_version_major = 0;
UInt64 server_version_minor = 0;
UInt64 server_version_patch = 0;

try
String tcp_port_config_key = is_secure ? "tcp_port_secure" : "tcp_port";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be easier to read with if instead of ternary operator

@@ -512,48 +512,73 @@ catch (...)

void Client::connect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need rebase on new master and tests

@df530 df530 force-pushed the client-fault-tolerant-connection branch 9 times, most recently from 94e48b0 to 962d851 Compare January 20, 2022 09:54
andycol and others added 17 commits February 2, 2022 14:32
fix the run command and add example
Before this patch current_user/current_address will be preserved from
the previous query.

Signed-off-by: Azat Khuzhin <[email protected]>
Update list-versions.sh, update version_date.tsv
…-for-show-grants

Fix checking grants for SHOW GRANTS
…ssword

Add 'clickhouse-client --password' comment to the scripts used in Qui…
Disable data skipping indexes by default for queries with FINAL
@df530 df530 force-pushed the client-fault-tolerant-connection branch from 3253ae1 to c1df291 Compare February 7, 2022 23:04
alexey-milovidov and others added 26 commits February 8, 2022 02:27
…rays

Fix consecutive backward seeks in seekable read buffers
…database-memory

Fix wrong engine in SHOW CREATE DATABASE with engine Memory ClickHouse#34225
Add table function format(format_name, data)
Add composability to casting and index operators
…temp-tables-via-grpc

Fix inserting to temporary tables via gRPC.
…metadata

Better local metadata comparison with ZooKeeper metadata
Fix segfault in schema inference from url
Fix various issues when projection is enabled by default
Revert "Merge pull request ClickHouse#34373 from ClickHouse/docker-tz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.