Skip to content

Add list of hosts reading #4

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

Conversation

df530
Copy link
Collaborator

@df530 df530 commented Nov 1, 2021

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
The param --host can receive some hosts. In the future client will use it to choose host for connection. Choise will be depend on availability and workload of hosts.

Detailed description / Documentation draft:
...

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/

@@ -29,6 +29,7 @@ class Client : public ClientBase
const std::vector<Arguments> & external_tables_arguments) override;
void processConfig() override;

std::vector<String> hosts{};
Copy link
Member

Choose a reason for hiding this comment

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

Where is a single host keeped? You need to find it and keep vector of hosts instead of one host

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A single host is kept originally in configuration object with type Poco::Util:AbstactConfiguration, which pointer you can get from method config(). Configuration is usually setting in method Client::init, and other methods, which are called in init.
To set field in config() you shoud call config().set<String | Int | ...>(<key>, <value>). But there are setting methods only for simple types: int, string, bool, etc. You can't set key with std::vector value.

I watched, how vectors are saved in other situations (when other vector parametrs are set). I found param --query-files in class ClientBase: https://github.com/ManagedDatabases/ClickHouse/blob/managed-feature/choose-server-from-list/src/Client/ClientBase.cpp#L1536

And the values are saving in special field of class ClientBase (while other simple string or int params are saved in config()): https://github.com/ManagedDatabases/ClickHouse/blob/managed-feature/choose-server-from-list/src/Client/ClientBase.cpp#L1600

That is why I've made an similar field for hosts in Client class.

Copy link
Member

Choose a reason for hiding this comment

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

Well so you can add it to ClientBase as it is done for query-files

@@ -512,6 +512,7 @@ catch (...)

void Client::connect()
{
config().setString("host", hosts[0]);
Copy link
Member

Choose a reason for hiding this comment

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

This line shouldn't be here as soon as you remove field hosts from Client class

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a crutch, which I will move to initialization (more you can see in conversation below #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.

Well, so as soon as you don't want to add hosts to config, you just don't need to set it in the beginning. You should either set it in config or don't set at all. I see you want to save hosts anywhere, but please write clean code

@@ -998,7 +999,7 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va
/// Main commandline options related to client functionality and all parameters from Settings.
options_description.main_description->add_options()
("config,c", po::value<std::string>(), "config-file path (another shorthand)")
("host,h", po::value<std::string>()->default_value("localhost"), "server host")
("host,h", po::value<std::vector<std::string>>()->multitoken()->default_value({"localhost"}, "localhost"), "list of server hosts")
Copy link
Member

Choose a reason for hiding this comment

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

Please add more detailed description. For example, like in interleave-queries-file option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will make it when add parsing hosts with port (to call clickhouse client --host localhost:9000)

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 add it now and when you will change for port, you can also modify description

@@ -1120,7 +1121,7 @@ void Client::processOptions(const OptionsDescription & options_description,
if (options.count("config"))
config().setString("config-file", options["config"].as<std::string>());
if (options.count("host") && !options["host"].defaulted())
config().setString("host", options["host"].as<std::string>());
hosts = options["host"].as<std::vector<std::string>>();
Copy link
Member

Choose a reason for hiding this comment

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

Seems like you need to set config here, but not in the beginning of Client::connect

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Setting config() is a crutch. My purpose is to save hosts anywhere, after that collegue can use this vector to make connection. But you are right, it would be better, if this crutch will be there, not in beginnin of connect.

Copy link
Member

Choose a reason for hiding this comment

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

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.

2 participants