mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 19:02:04 +00:00
ffc1fca296
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.
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <Poco/Net/TCPServer.h>
|
|
|
|
#include <base/types.h>
|
|
#include <Server/TCPServerConnectionFactory.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
class Context;
|
|
|
|
class TCPServer : public Poco::Net::TCPServer
|
|
{
|
|
public:
|
|
explicit TCPServer(
|
|
TCPServerConnectionFactory::Ptr factory,
|
|
Poco::ThreadPool & thread_pool,
|
|
Poco::Net::ServerSocket & socket,
|
|
Poco::Net::TCPServerParams::Ptr params = new Poco::Net::TCPServerParams);
|
|
|
|
/// Close the socket and ask existing connections to stop serving queries
|
|
void stop()
|
|
{
|
|
Poco::Net::TCPServer::stop();
|
|
// This notifies already established connections that they should stop serving
|
|
// queries and close their socket as soon as they can.
|
|
is_open = false;
|
|
// Poco's stop() stops listening on the socket but leaves it open.
|
|
// To be able to hand over control of the listening port to a new server, and
|
|
// to get fast connection refusal instead of timeouts, we also need to close
|
|
// the listening socket.
|
|
socket.close();
|
|
}
|
|
|
|
bool isOpen() const { return is_open; }
|
|
|
|
UInt16 portNumber() const { return port_number; }
|
|
|
|
private:
|
|
TCPServerConnectionFactory::Ptr factory;
|
|
Poco::Net::ServerSocket socket;
|
|
std::atomic<bool> is_open;
|
|
UInt16 port_number;
|
|
};
|
|
|
|
}
|