mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Introduce IServer to host handlers
This commit is contained in:
parent
ce09d0b99a
commit
f1e88e074c
@ -184,7 +184,7 @@ void HTTPHandler::pushDelayedResults(Output & used_output)
|
||||
}
|
||||
|
||||
|
||||
HTTPHandler::HTTPHandler(Server & server_)
|
||||
HTTPHandler::HTTPHandler(IServer & server_)
|
||||
: server(server_)
|
||||
, log(&Logger::get("HTTPHandler"))
|
||||
{
|
||||
@ -224,8 +224,8 @@ void HTTPHandler::processQuery(
|
||||
std::string quota_key = request.get("X-ClickHouse-Quota", params.get("quota_key", ""));
|
||||
std::string query_id = params.get("query_id", "");
|
||||
|
||||
Context context = *server.global_context;
|
||||
context.setGlobalContext(*server.global_context);
|
||||
Context context = server.context();
|
||||
context.setGlobalContext(server.context());
|
||||
|
||||
context.setUser(user, password, request.clientAddress(), quota_key);
|
||||
context.setCurrentQueryId(query_id);
|
||||
|
@ -19,7 +19,7 @@ class CascadeWriteBuffer;
|
||||
class HTTPHandler : public Poco::Net::HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
explicit HTTPHandler(Server & server_);
|
||||
explicit HTTPHandler(IServer & server_);
|
||||
|
||||
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
|
||||
|
||||
@ -47,12 +47,11 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
Server & server;
|
||||
IServer & server;
|
||||
Logger * log;
|
||||
|
||||
CurrentMetrics::Increment metric_increment{CurrentMetrics::HTTPConnection};
|
||||
|
||||
Logger * log;
|
||||
|
||||
/// Also initializes 'used_output'.
|
||||
void processQuery(
|
||||
Poco::Net::HTTPServerRequest & request,
|
||||
|
26
dbms/src/Server/IServer.h
Normal file
26
dbms/src/Server/IServer.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <Interpreters/Context.h>
|
||||
|
||||
#include <Poco/Logger.h>
|
||||
#include <Poco/Util/LayeredConfiguration.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class IServer
|
||||
{
|
||||
public:
|
||||
/// Returns the application's configuration.
|
||||
virtual Poco::Util::LayeredConfiguration & config() const = 0;
|
||||
|
||||
/// Returns the application's logger.
|
||||
virtual Poco::Logger & logger() const = 0;
|
||||
|
||||
/// Returns global application's context.
|
||||
virtual Context & context() const = 0;
|
||||
|
||||
virtual ~IServer() {}
|
||||
};
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ void InterserverIOHTTPHandler::processQuery(Poco::Net::HTTPServerRequest & reque
|
||||
|
||||
WriteBufferFromHTTPServerResponse out(response);
|
||||
|
||||
auto endpoint = server.global_context->getInterserverIOHandler().getEndpoint(endpoint_name);
|
||||
auto endpoint = server.context().getInterserverIOHandler().getEndpoint(endpoint_name);
|
||||
|
||||
if (compress)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace DB
|
||||
class InterserverIOHTTPHandler : public Poco::Net::HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
InterserverIOHTTPHandler(Server & server_)
|
||||
InterserverIOHTTPHandler(IServer & server_)
|
||||
: server(server_)
|
||||
, log(&Logger::get("InterserverIOHTTPHandler"))
|
||||
{
|
||||
@ -24,11 +24,12 @@ public:
|
||||
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
|
||||
|
||||
private:
|
||||
Server & server;
|
||||
CurrentMetrics::Increment metric_increment{CurrentMetrics::InterserverConnection};
|
||||
IServer & server;
|
||||
Logger * log;
|
||||
|
||||
void processQuery(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response);
|
||||
CurrentMetrics::Increment metric_increment{CurrentMetrics::InterserverConnection};
|
||||
|
||||
void processQuery(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public:
|
||||
if (uri == "/ping")
|
||||
return new PingRequestHandler;
|
||||
else if (startsWith(uri, "/replicas_status"))
|
||||
return new ReplicasStatusHandler(*server.global_context);
|
||||
return new ReplicasStatusHandler(server.context());
|
||||
}
|
||||
|
||||
if (uri.find('?') != std::string::npos || request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST)
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "IServer.h"
|
||||
|
||||
#include <Poco/URI.h>
|
||||
|
||||
#include <Poco/Util/LayeredConfiguration.h>
|
||||
@ -37,11 +39,23 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class Server : public BaseDaemon
|
||||
class Server : public BaseDaemon, public IServer
|
||||
{
|
||||
public:
|
||||
/// Global settings of server.
|
||||
std::unique_ptr<Context> global_context;
|
||||
Poco::Util::LayeredConfiguration & config() const override
|
||||
{
|
||||
return BaseDaemon::config();
|
||||
}
|
||||
|
||||
Poco::Logger & logger() const override
|
||||
{
|
||||
return BaseDaemon::logger();
|
||||
}
|
||||
|
||||
Context & context() const override
|
||||
{
|
||||
return *global_context;
|
||||
}
|
||||
|
||||
protected:
|
||||
void initialize(Application & self) override
|
||||
@ -58,8 +72,10 @@ protected:
|
||||
|
||||
int main(const std::vector<std::string> & args) override;
|
||||
|
||||
private:
|
||||
std::string getDefaultCorePath() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Context> global_context;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -49,10 +49,10 @@ namespace ErrorCodes
|
||||
|
||||
void TCPHandler::runImpl()
|
||||
{
|
||||
connection_context = *server.global_context;
|
||||
connection_context = server.context();
|
||||
connection_context.setSessionContext(connection_context);
|
||||
|
||||
Settings global_settings = server.global_context->getSettings();
|
||||
Settings global_settings = connection_context.getSettings();
|
||||
|
||||
socket().setReceiveTimeout(global_settings.receive_timeout);
|
||||
socket().setSendTimeout(global_settings.send_timeout);
|
||||
|
@ -71,17 +71,19 @@ struct QueryState
|
||||
class TCPHandler : public Poco::Net::TCPServerConnection
|
||||
{
|
||||
public:
|
||||
TCPHandler(Server & server_, const Poco::Net::StreamSocket & socket_)
|
||||
: Poco::Net::TCPServerConnection(socket_), server(server_),
|
||||
log(&Logger::get("TCPHandler")), client_revision(0),
|
||||
connection_context(*server.global_context), query_context(connection_context)
|
||||
TCPHandler(IServer & server_, const Poco::Net::StreamSocket & socket_)
|
||||
: Poco::Net::TCPServerConnection(socket_)
|
||||
, server(server_)
|
||||
, log(&Logger::get("TCPHandler"))
|
||||
, connection_context(server.context())
|
||||
, query_context(server.context())
|
||||
{
|
||||
}
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
Server & server;
|
||||
IServer & server;
|
||||
Logger * log;
|
||||
|
||||
String client_name;
|
||||
|
Loading…
Reference in New Issue
Block a user