2012-03-09 03:06:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-05-27 17:52:52 +00:00
|
|
|
#include <Server/IServer.h>
|
2024-05-27 08:04:19 +00:00
|
|
|
|
2022-04-27 15:05:45 +00:00
|
|
|
#include <Daemon/BaseDaemon.h>
|
2024-05-27 08:04:19 +00:00
|
|
|
#include <Server/HTTP/HTTPContext.h>
|
|
|
|
#include <Server/TCPProtocolStackFactory.h>
|
|
|
|
#include <Server/ServerType.h>
|
|
|
|
#include <Poco/Net/HTTPServerParams.h>
|
2012-03-09 03:06:09 +00:00
|
|
|
|
2016-07-30 01:08:00 +00:00
|
|
|
/** Server provides three interfaces:
|
2024-05-27 08:04:19 +00:00
|
|
|
* 1. HTTP - simple interface for any applications.
|
2016-07-30 01:08:00 +00:00
|
|
|
* 2. TCP - interface for native clickhouse-client and for server to server internal communications.
|
|
|
|
* More rich and efficient, but less compatible
|
|
|
|
* - data is transferred by columns;
|
|
|
|
* - data is transferred compressed;
|
|
|
|
* Allows to get more information in response.
|
|
|
|
* 3. Interserver HTTP - for replication.
|
2012-03-09 03:06:09 +00:00
|
|
|
*/
|
|
|
|
|
2024-05-27 08:04:19 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
class ServerSocket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-09 03:06:09 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2024-05-27 08:04:19 +00:00
|
|
|
class AsynchronousMetrics;
|
|
|
|
class ProtocolServerAdapter;
|
2012-03-09 03:06:09 +00:00
|
|
|
|
2017-08-09 11:57:09 +00:00
|
|
|
class Server : public BaseDaemon, public IServer
|
2012-03-09 03:06:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-02-02 13:17:55 +00:00
|
|
|
using ServerApplication::run;
|
|
|
|
|
2024-05-27 08:04:19 +00:00
|
|
|
Poco::Util::LayeredConfiguration & config() const override
|
|
|
|
{
|
|
|
|
return BaseDaemon::config();
|
|
|
|
}
|
2017-08-09 11:57:09 +00:00
|
|
|
|
2024-05-27 08:04:19 +00:00
|
|
|
Poco::Logger & logger() const override
|
|
|
|
{
|
|
|
|
return BaseDaemon::logger();
|
|
|
|
}
|
2017-08-09 11:57:09 +00:00
|
|
|
|
2024-05-27 08:04:19 +00:00
|
|
|
ContextMutablePtr context() const override
|
|
|
|
{
|
|
|
|
return global_context;
|
|
|
|
}
|
2015-10-05 01:26:43 +00:00
|
|
|
|
2024-05-27 08:04:19 +00:00
|
|
|
bool isCancelled() const override
|
|
|
|
{
|
|
|
|
return BaseDaemon::isCancelled();
|
|
|
|
}
|
2017-08-09 14:33:07 +00:00
|
|
|
|
2019-02-02 13:17:55 +00:00
|
|
|
void defineOptions(Poco::Util::OptionSet & _options) override;
|
2021-02-19 12:51:26 +00:00
|
|
|
|
2014-07-21 11:21:09 +00:00
|
|
|
protected:
|
2019-02-02 13:17:55 +00:00
|
|
|
int run() override;
|
|
|
|
|
2018-02-08 19:12:37 +00:00
|
|
|
void initialize(Application & self) override;
|
2015-10-05 01:26:43 +00:00
|
|
|
|
2018-02-08 19:12:37 +00:00
|
|
|
void uninitialize() override;
|
2012-03-09 03:06:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
int main(const std::vector<std::string> & args) override;
|
2016-10-24 14:01:24 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getDefaultCorePath() const override;
|
2017-08-09 11:57:09 +00:00
|
|
|
|
|
|
|
private:
|
2021-05-31 14:49:02 +00:00
|
|
|
ContextMutablePtr global_context;
|
2022-09-09 20:00:27 +00:00
|
|
|
/// Updated/recent config, to compare http_handlers
|
|
|
|
ConfigurationPtr latest_config;
|
2024-05-27 08:04:19 +00:00
|
|
|
|
|
|
|
HTTPContextPtr httpContext() const;
|
|
|
|
|
|
|
|
Poco::Net::SocketAddress socketBindListen(
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
Poco::Net::ServerSocket & socket,
|
|
|
|
const std::string & host,
|
|
|
|
UInt16 port,
|
|
|
|
[[maybe_unused]] bool secure = false) const;
|
|
|
|
|
|
|
|
std::unique_ptr<TCPProtocolStackFactory> buildProtocolStackFromConfig(
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & protocol,
|
|
|
|
Poco::Net::HTTPServerParams::Ptr http_params,
|
|
|
|
AsynchronousMetrics & async_metrics,
|
|
|
|
bool & is_secure);
|
|
|
|
|
|
|
|
using CreateServerFunc = std::function<ProtocolServerAdapter(UInt16)>;
|
|
|
|
void createServer(
|
|
|
|
Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & listen_host,
|
|
|
|
const char * port_name,
|
|
|
|
bool listen_try,
|
|
|
|
bool start_server,
|
|
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
|
|
CreateServerFunc && func) const;
|
|
|
|
|
|
|
|
void createServers(
|
|
|
|
Poco::Util::AbstractConfiguration & config,
|
|
|
|
const Strings & listen_hosts,
|
|
|
|
bool listen_try,
|
|
|
|
Poco::ThreadPool & server_pool,
|
|
|
|
AsynchronousMetrics & async_metrics,
|
|
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
|
|
bool start_servers = false,
|
|
|
|
const ServerType & server_type = ServerType(ServerType::Type::QUERIES_ALL));
|
|
|
|
|
|
|
|
void createInterserverServers(
|
|
|
|
Poco::Util::AbstractConfiguration & config,
|
|
|
|
const Strings & interserver_listen_hosts,
|
|
|
|
bool listen_try,
|
|
|
|
Poco::ThreadPool & server_pool,
|
|
|
|
AsynchronousMetrics & async_metrics,
|
|
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
|
|
bool start_servers = false,
|
|
|
|
const ServerType & server_type = ServerType(ServerType::Type::QUERIES_ALL));
|
|
|
|
|
|
|
|
void updateServers(
|
|
|
|
Poco::Util::AbstractConfiguration & config,
|
|
|
|
Poco::ThreadPool & server_pool,
|
|
|
|
AsynchronousMetrics & async_metrics,
|
|
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
|
|
std::vector<ProtocolServerAdapter> & servers_to_start_before_tables);
|
|
|
|
|
|
|
|
void stopServers(
|
|
|
|
std::vector<ProtocolServerAdapter> & servers,
|
2024-07-18 01:33:36 +00:00
|
|
|
const ServerType & server_type) const;
|
2012-03-09 03:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|