ClickHouse/src/Server/PostgreSQLHandler.h

77 lines
1.9 KiB
C++
Raw Normal View History

2020-05-30 17:04:02 +00:00
#pragma once
#include <Common/CurrentMetrics.h>
#include <Core/PostgreSQLProtocol.h>
#include <Poco/Net/TCPServerConnection.h>
2020-05-30 20:02:11 +00:00
#include <common/logger_useful.h>
2020-05-30 17:04:02 +00:00
#include "IServer.h"
#if USE_SSL
# include <Poco/Net/SecureStreamSocket.h>
#endif
namespace CurrentMetrics
{
extern const Metric PostgreSQLConnection;
}
namespace DB
{
/** PostgreSQL wire protocol implementation.
* For more info see https://www.postgresql.org/docs/current/protocol.html
*/
class PostgreSQLHandler : public Poco::Net::TCPServerConnection
{
public:
PostgreSQLHandler(
const Poco::Net::StreamSocket & socket_,
IServer & server_,
bool ssl_enabled_,
Int32 connection_id_,
std::vector<std::shared_ptr<PostgreSQLProtocol::PGAuthentication::AuthenticationMethod>> & auth_methods_);
void run() final;
private:
Poco::Logger * log = &Poco::Logger::get("PostgreSQLHandler");
IServer & server;
Context connection_context;
bool ssl_enabled;
Int32 connection_id;
Int32 secret_key;
std::shared_ptr<ReadBuffer> in;
std::shared_ptr<WriteBuffer> out;
std::shared_ptr<PostgreSQLProtocol::Messaging::MessageTransport> message_transport;
#if USE_SSL
std::shared_ptr<Poco::Net::SecureStreamSocket> ss;
#endif
PostgreSQLProtocol::PGAuthentication::AuthenticationManager authentication_manager;
CurrentMetrics::Increment metric_increment{CurrentMetrics::PostgreSQLConnection};
void changeIO(Poco::Net::StreamSocket & socket);
2020-06-21 12:16:08 +00:00
bool startup();
2020-05-30 17:04:02 +00:00
void establishSecureConnection(Int32 & payload_size, Int32 & info);
void makeSecureConnectionSSL();
2020-06-21 12:16:08 +00:00
void sendParameterStatusData(PostgreSQLProtocol::Messaging::StartupMessage & start_up_message);
2020-05-30 17:04:02 +00:00
void cancelRequest();
2020-06-21 12:16:08 +00:00
std::unique_ptr<PostgreSQLProtocol::Messaging::StartupMessage> receiveStartupMessage(int payload_size);
2020-05-30 17:04:02 +00:00
void processQuery();
2020-05-31 14:05:41 +00:00
static bool isEmptyQuery(const String & query);
2020-05-30 17:04:02 +00:00
};
}