Skip to content

Start/stop servers when listen_host/*_port changes#30549

Merged
vitlibar merged 1 commit intoClickHouse:masterfrom
aiven:kmichel-server-reload
Dec 27, 2021
Merged

Start/stop servers when listen_host/*_port changes#30549
vitlibar merged 1 commit intoClickHouse:masterfrom
aiven:kmichel-server-reload

Conversation

@kmichel-aiven
Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Start and stop servers when hosts and ports configuration changes

Detailed description / Documentation draft:
Start and stop each protocol server without restarting ClickHouse.

This also allows adding or removing listen_host entries, which start and stops servers for all enabled ports.

When stopping a server, the listening socket is immediately closed (and available for another server).

Protocols with persistent connections try to wait for any currently running query to finish before closing the connection, but idle connection are closed quickly (depending on how often the protocol is polled).

An extra ProfileEvent is added, MainConfigLoads, it is incremented every time the configuration is reloaded.
This helps when trying to assess whether the new configuration was applied.

@robot-clickhouse robot-clickhouse added doc-alert pr-feature Pull request with new product feature labels Oct 22, 2021
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 22, 2021

CLA assistant check
All committers have signed the CLA.

@kmichel-aiven kmichel-aiven changed the title Start/stop servers when listen_host/*_port changes Start/stop servers when listen_host/*_port changes Oct 22, 2021
@kmichel-aiven kmichel-aiven force-pushed the kmichel-server-reload branch 5 times, most recently from 76ab2ef to d65b9ce Compare October 26, 2021 07:31
@kmichel-aiven kmichel-aiven marked this pull request as ready for review October 26, 2021 20:29
@vitlibar vitlibar self-assigned this Nov 15, 2021
@vitlibar
Copy link
Copy Markdown
Member

Sorry for the delay

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tests look great, thank you!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Poco::Net::TCPServer already has the function stop(). It looks misleading to have both stop() and close() functions in TCPServer. Can we rename close() -> stop() and also call Poco::Net::TCPServer::stop() in this function?

Copy link
Copy Markdown
Member

@vitlibar vitlibar Dec 17, 2021

Choose a reason for hiding this comment

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

So the only difference between TCPServer and Poco::Net::TCPServer is that TCPServer closes the socket. Can you please add a comment why Poco::Net::TCPServer::stop() is not enough and we also need to close the socker?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems it would be clearer to define a constant instead of using the magic number:

constexpr size_t connection_check_timeout = 1; /// 1 second
while (!in->poll(1000000 * connection_check_timeout))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can probably make the code clearer if we add a new function named like updateServers(), and move the following code in there.

Copy link
Copy Markdown
Member

@vitlibar vitlibar Dec 17, 2021

Choose a reason for hiding this comment

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

Sharing of a mutex doesn't look very nice to me. Maybe it's better to change something. For example, it seems instead of passing servers_to_start_before_tables_, servers_lock_, servers_ we can pass a function of type std::function<std::vector<ProtocolServerMetrics>()>, where ProtocolServerMetrics is defined as following

struct ProtocolServerMetrics
{
  String port_name;
  size_t current_threads;
};

Thus we will able to turn both the mutex and the lists of servers back to simple local variables in Server.cpp, without necessity to share them with another module.

@vitlibar vitlibar added the can be tested Allows running workflows for external contributors label Dec 21, 2021
@vitlibar
Copy link
Copy Markdown
Member

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Dec 22, 2021

update

❌ Pull request can't be updated with latest base branch changes

Details

Mergify needs the author permission to update the base branch of the pull request.
aiven needs to authorize modification on its head branch.
err-code: D2723

@kmichel-aiven kmichel-aiven force-pushed the kmichel-server-reload branch 2 times, most recently from 9191242 to 79a0df0 Compare December 23, 2021 23:27
This allows starting and stopping separately each protocol server
without restarting ClickHouse.

This also allows adding or removing `listen_host` entries, which
start and stops servers for all enabled ports.

When stopping a server, the listening socket is immediately closed
(and available for another server).

Protocols with persistent connections try to wait for any currently
running query to finish before closing the connection, but idle
connection are closed quickly (depending on how often the protocol
is polled).

An extra ProfileEvent is added, `MainConfigLoads`, it is
incremented every time the configuration is reloaded. This helps
when trying to assess whether the new configuration was applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants