From 142c63e487c0bc0adacf64773113272fadff1875 Mon Sep 17 00:00:00 2001 From: MovElb Date: Sat, 30 May 2020 23:02:11 +0300 Subject: [PATCH] done rebase --- programs/server/Server.cpp | 16 ++++++++++++++++ src/Core/PostgreSQLProtocol.h | 5 +++-- .../server => src/Server}/PostgreSQLHandler.cpp | 0 .../server => src/Server}/PostgreSQLHandler.h | 1 + .../Server}/PostgreSQLHandlerFactory.cpp | 5 ++--- .../Server}/PostgreSQLHandlerFactory.h | 4 +++- src/Server/ya.make | 2 ++ 7 files changed, 27 insertions(+), 6 deletions(-) rename {programs/server => src/Server}/PostgreSQLHandler.cpp (100%) rename {programs/server => src/Server}/PostgreSQLHandler.h (98%) rename {programs/server => src/Server}/PostgreSQLHandlerFactory.cpp (81%) rename {programs/server => src/Server}/PostgreSQLHandlerFactory.h (91%) diff --git a/programs/server/Server.cpp b/programs/server/Server.cpp index 04324d3457..d991c096ec 100644 --- a/programs/server/Server.cpp +++ b/programs/server/Server.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #if !defined(ARCADIA_BUILD) @@ -935,6 +936,21 @@ int Server::main(const std::vector & /*args*/) LOG_INFO(log, "Listening for MySQL compatibility protocol: {}", address.toString()); }); + create_server("postgresql_port", [&](UInt16 port) + { + Poco::Net::ServerSocket socket; + auto address = socket_bind_listen(socket, listen_host, port, /* secure = */ true); + socket.setReceiveTimeout(Poco::Timespan()); + socket.setSendTimeout(settings.send_timeout); + servers.emplace_back(std::make_unique( + new PostgreSQLHandlerFactory(*this), + server_pool, + socket, + new Poco::Net::TCPServerParams)); + + LOG_INFO(log, "Listening for PostgreSQL compatibility protocol: " + address.toString()); + }); + /// Prometheus (if defined and not setup yet with http_port) create_server("prometheus.port", [&](UInt16 port) { diff --git a/src/Core/PostgreSQLProtocol.h b/src/Core/PostgreSQLProtocol.h index b5fa67d68e..3acf0b02ce 100644 --- a/src/Core/PostgreSQLProtocol.h +++ b/src/Core/PostgreSQLProtocol.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -800,7 +801,7 @@ protected: const Poco::Net::SocketAddress & address) { try { - context.setUser(user_name, password, address, ""); + context.setUser(user_name, password, address); } catch (const Exception &) { @@ -897,7 +898,7 @@ public: { type_to_method[user_auth_type]->authenticate(user_name, context, mt, address); mt.send(Messaging::AuthenticationOk(), true); - LOG_INFO(log, "Authentication for user " << user_name << " was successful."); + LOG_INFO(log, "Authentication for user {} was successful.", user_name); return; } diff --git a/programs/server/PostgreSQLHandler.cpp b/src/Server/PostgreSQLHandler.cpp similarity index 100% rename from programs/server/PostgreSQLHandler.cpp rename to src/Server/PostgreSQLHandler.cpp diff --git a/programs/server/PostgreSQLHandler.h b/src/Server/PostgreSQLHandler.h similarity index 98% rename from programs/server/PostgreSQLHandler.h rename to src/Server/PostgreSQLHandler.h index 1062fed5cb..28b9ef9a35 100644 --- a/programs/server/PostgreSQLHandler.h +++ b/src/Server/PostgreSQLHandler.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "IServer.h" #if USE_SSL diff --git a/programs/server/PostgreSQLHandlerFactory.cpp b/src/Server/PostgreSQLHandlerFactory.cpp similarity index 81% rename from programs/server/PostgreSQLHandlerFactory.cpp rename to src/Server/PostgreSQLHandlerFactory.cpp index 210d8558bf..ce433188c0 100644 --- a/programs/server/PostgreSQLHandlerFactory.cpp +++ b/src/Server/PostgreSQLHandlerFactory.cpp @@ -1,8 +1,7 @@ #include "PostgreSQLHandlerFactory.h" -#include "IServer.h" #include #include -#include "PostgreSQLHandler.h" +#include namespace DB { @@ -21,7 +20,7 @@ PostgreSQLHandlerFactory::PostgreSQLHandlerFactory(IServer & server_) Poco::Net::TCPServerConnection * PostgreSQLHandlerFactory::createConnection(const Poco::Net::StreamSocket & socket) { Int32 connection_id = last_connection_id++; - LOG_TRACE(log, "PostgreSQL connection. Id: " << connection_id << ". Address: " << socket.peerAddress().toString()); + LOG_TRACE(log, "PostgreSQL connection. Id: {}. Address: {}", connection_id, socket.peerAddress().toString()); return new PostgreSQLHandler(socket, server, ssl_enabled, connection_id, auth_methods); } diff --git a/programs/server/PostgreSQLHandlerFactory.h b/src/Server/PostgreSQLHandlerFactory.h similarity index 91% rename from programs/server/PostgreSQLHandlerFactory.h rename to src/Server/PostgreSQLHandlerFactory.h index a95a22c162..0546b4ef8c 100644 --- a/programs/server/PostgreSQLHandlerFactory.h +++ b/src/Server/PostgreSQLHandlerFactory.h @@ -1,7 +1,9 @@ #pragma once -#include "IServer.h" #include +#include +#include +#include #include namespace DB diff --git a/src/Server/ya.make b/src/Server/ya.make index 1d689ee73b..6e01e2599e 100644 --- a/src/Server/ya.make +++ b/src/Server/ya.make @@ -11,6 +11,8 @@ SRCS( InterserverIOHTTPHandler.cpp MySQLHandler.cpp MySQLHandlerFactory.cpp + PostgreSQLHandler.cpp + PostgreSQLHandlerFactory.cpp NotFoundHandler.cpp PrometheusMetricsWriter.cpp PrometheusRequestHandler.cpp -- GitLab