From 1d45654a61ca2c8305bb4cd4e63d231d0ff0c7c8 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Tue, 25 Mar 2025 13:41:39 +0100 Subject: [PATCH 1/4] Initial commit --- cpp/src/arrow/flight/CMakeLists.txt | 1 - cpp/src/arrow/flight/server_auth.h | 21 ++------------ cpp/src/arrow/flight/server_middleware.cc | 35 ----------------------- cpp/src/arrow/flight/server_middleware.h | 24 +--------------- python/pyarrow/src/arrow/python/flight.cc | 7 +++-- python/pyarrow/src/arrow/python/flight.h | 5 ++-- 6 files changed, 10 insertions(+), 83 deletions(-) delete mode 100644 cpp/src/arrow/flight/server_middleware.cc diff --git a/cpp/src/arrow/flight/CMakeLists.txt b/cpp/src/arrow/flight/CMakeLists.txt index 7f86d51e2000..818f731f1652 100644 --- a/cpp/src/arrow/flight/CMakeLists.txt +++ b/cpp/src/arrow/flight/CMakeLists.txt @@ -146,7 +146,6 @@ set(ARROW_FLIGHT_SRCS serialization_internal.cc server.cc server_auth.cc - server_middleware.cc server_tracing_middleware.cc transport.cc transport_server.cc diff --git a/cpp/src/arrow/flight/server_auth.h b/cpp/src/arrow/flight/server_auth.h index 93d3352ba200..9513a2cd1fca 100644 --- a/cpp/src/arrow/flight/server_auth.h +++ b/cpp/src/arrow/flight/server_auth.h @@ -61,25 +61,8 @@ class ARROW_FLIGHT_EXPORT ServerAuthHandler { /// \param[in] incoming The reader for messages from the client. /// \return Status OK if this authentication is succeeded. virtual Status Authenticate(const ServerCallContext& context, - ServerAuthSender* outgoing, ServerAuthReader* incoming) { - // TODO: We can make this pure virtual function when we remove - // the deprecated version. - ARROW_SUPPRESS_DEPRECATION_WARNING - return Authenticate(outgoing, incoming); - ARROW_UNSUPPRESS_DEPRECATION_WARNING - } - /// \brief Authenticate the client on initial connection. The server - /// can send and read responses from the client at any time. - /// \param[in] outgoing The writer for messages to the client. - /// \param[in] incoming The reader for messages from the client. - /// \return Status OK if this authentication is succeeded. - /// \deprecated Deprecated in 13.0.0. Implement the Authentication() - /// with ServerCallContext version instead. - ARROW_DEPRECATED("Deprecated in 13.0.0. Use ServerCallContext overload instead.") - virtual Status Authenticate(ServerAuthSender* outgoing, ServerAuthReader* incoming) { - return Status::NotImplemented(typeid(this).name(), - "::Authenticate() isn't implemented"); - } + ServerAuthSender* outgoing, + ServerAuthReader* incoming) = 0; /// \brief Validate a per-call client token. /// \param[in] context The call context. /// \param[in] token The client token. May be the empty string if diff --git a/cpp/src/arrow/flight/server_middleware.cc b/cpp/src/arrow/flight/server_middleware.cc deleted file mode 100644 index d7ace580dc67..000000000000 --- a/cpp/src/arrow/flight/server_middleware.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include "arrow/flight/server_middleware.h" -#include "arrow/flight/server.h" - -namespace arrow { -namespace flight { - -Status ServerMiddlewareFactory::StartCall(const CallInfo& info, - const ServerCallContext& context, - std::shared_ptr* middleware) { - // TODO: We can make this pure virtual function when we remove - // the deprecated version. - ARROW_SUPPRESS_DEPRECATION_WARNING - return StartCall(info, context.incoming_headers(), middleware); - ARROW_UNSUPPRESS_DEPRECATION_WARNING -} - -} // namespace flight -} // namespace arrow diff --git a/cpp/src/arrow/flight/server_middleware.h b/cpp/src/arrow/flight/server_middleware.h index 3a3e6f8616ed..3a0f3c475061 100644 --- a/cpp/src/arrow/flight/server_middleware.h +++ b/cpp/src/arrow/flight/server_middleware.h @@ -75,29 +75,7 @@ class ARROW_FLIGHT_EXPORT ServerMiddlewareFactory { /// their CallCompleted callback called. Other middleware /// factories will not be called. virtual Status StartCall(const CallInfo& info, const ServerCallContext& context, - std::shared_ptr* middleware); - - /// \brief A callback for the start of a new call. - /// - /// Return a non-OK status to reject the call with the given status. - /// - /// \param info Information about the call. - /// \param incoming_headers Headers sent by the client for this call. - /// Do not retain a reference to this object. - /// \param[out] middleware The middleware instance for this call. If - /// null, no middleware will be added to this call instance from - /// this factory. - /// \return Status A non-OK status will reject the call with the - /// given status. Middleware previously in the chain will have - /// their CallCompleted callback called. Other middleware - /// factories will not be called. - /// \deprecated Deprecated in 13.0.0. Implement the StartCall() - /// with ServerCallContext version instead. - ARROW_DEPRECATED("Deprecated in 13.0.0. Use ServerCallContext overload instead.") - virtual Status StartCall(const CallInfo& info, const CallHeaders& incoming_headers, - std::shared_ptr* middleware) { - return Status::NotImplemented(typeid(this).name(), "::StartCall() isn't implemented"); - } + std::shared_ptr* middleware) = 0; }; } // namespace flight diff --git a/python/pyarrow/src/arrow/python/flight.cc b/python/pyarrow/src/arrow/python/flight.cc index ce5e6dfa94e3..25e7c8893c81 100644 --- a/python/pyarrow/src/arrow/python/flight.cc +++ b/python/pyarrow/src/arrow/python/flight.cc @@ -37,7 +37,8 @@ PyServerAuthHandler::PyServerAuthHandler(PyObject* handler, handler_.reset(handler); } -Status PyServerAuthHandler::Authenticate(arrow::flight::ServerAuthSender* outgoing, +Status PyServerAuthHandler::Authenticate(const arrow::flight::ServerCallContext& context, + arrow::flight::ServerAuthSender* outgoing, arrow::flight::ServerAuthReader* incoming) { return SafeCallIntoPython([=] { const Status status = vtable_.authenticate(handler_.obj(), outgoing, incoming); @@ -268,10 +269,10 @@ PyServerMiddlewareFactory::PyServerMiddlewareFactory(PyObject* factory, Status PyServerMiddlewareFactory::StartCall( const arrow::flight::CallInfo& info, - const arrow::flight::CallHeaders& incoming_headers, + const arrow::flight::ServerCallContext& context, std::shared_ptr* middleware) { return SafeCallIntoPython([&] { - const Status status = start_call_(factory_.obj(), info, incoming_headers, middleware); + const Status status = start_call_(factory_.obj(), info, context.incoming_headers(), middleware); RETURN_NOT_OK(CheckPyError()); return status; }); diff --git a/python/pyarrow/src/arrow/python/flight.h b/python/pyarrow/src/arrow/python/flight.h index 57d21976bb7a..8a1f4c750aac 100644 --- a/python/pyarrow/src/arrow/python/flight.h +++ b/python/pyarrow/src/arrow/python/flight.h @@ -114,7 +114,8 @@ class ARROW_PYFLIGHT_EXPORT PyServerAuthHandler public: explicit PyServerAuthHandler(PyObject* handler, const PyServerAuthHandlerVtable& vtable); - Status Authenticate(arrow::flight::ServerAuthSender* outgoing, + Status Authenticate(const arrow::flight::ServerCallContext& context, + arrow::flight::ServerAuthSender* outgoing, arrow::flight::ServerAuthReader* incoming) override; Status IsValid(const std::string& token, std::string* peer_identity) override; @@ -225,7 +226,7 @@ class ARROW_PYFLIGHT_EXPORT PyServerMiddlewareFactory explicit PyServerMiddlewareFactory(PyObject* factory, StartCallCallback start_call); Status StartCall(const arrow::flight::CallInfo& info, - const arrow::flight::CallHeaders& incoming_headers, + const arrow::flight::ServerCallContext& context, std::shared_ptr* middleware) override; private: From bce556be156e5e35444712190e18ec142a8cd3d1 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Tue, 25 Mar 2025 14:08:49 +0100 Subject: [PATCH 2/4] Fix linter errors --- cpp/src/arrow/flight/server_auth.h | 3 +-- python/pyarrow/src/arrow/python/flight.cc | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/flight/server_auth.h b/cpp/src/arrow/flight/server_auth.h index 9513a2cd1fca..147bef68d08a 100644 --- a/cpp/src/arrow/flight/server_auth.h +++ b/cpp/src/arrow/flight/server_auth.h @@ -61,8 +61,7 @@ class ARROW_FLIGHT_EXPORT ServerAuthHandler { /// \param[in] incoming The reader for messages from the client. /// \return Status OK if this authentication is succeeded. virtual Status Authenticate(const ServerCallContext& context, - ServerAuthSender* outgoing, - ServerAuthReader* incoming) = 0; + ServerAuthSender* outgoing, ServerAuthReader* incoming) = 0; /// \brief Validate a per-call client token. /// \param[in] context The call context. /// \param[in] token The client token. May be the empty string if diff --git a/python/pyarrow/src/arrow/python/flight.cc b/python/pyarrow/src/arrow/python/flight.cc index 25e7c8893c81..7cda1ecde1cc 100644 --- a/python/pyarrow/src/arrow/python/flight.cc +++ b/python/pyarrow/src/arrow/python/flight.cc @@ -268,11 +268,11 @@ PyServerMiddlewareFactory::PyServerMiddlewareFactory(PyObject* factory, } Status PyServerMiddlewareFactory::StartCall( - const arrow::flight::CallInfo& info, - const arrow::flight::ServerCallContext& context, + const arrow::flight::CallInfo& info, const arrow::flight::ServerCallContext& context, std::shared_ptr* middleware) { return SafeCallIntoPython([&] { - const Status status = start_call_(factory_.obj(), info, context.incoming_headers(), middleware); + const Status status = + start_call_(factory_.obj(), info, context.incoming_headers(), middleware); RETURN_NOT_OK(CheckPyError()); return status; }); From 5a5684397ff32de89c50e4bab8ed9f9cad09c464 Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Tue, 25 Mar 2025 14:32:37 +0100 Subject: [PATCH 3/4] Fix usage of StartCall in FlightSQL also --- cpp/src/arrow/flight/sql/server_session_middleware.cc | 9 +++++---- .../arrow/flight/sql/server_session_middleware_factory.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/flight/sql/server_session_middleware.cc b/cpp/src/arrow/flight/sql/server_session_middleware.cc index 43609ea8cc43..e9d101c58bcc 100644 --- a/cpp/src/arrow/flight/sql/server_session_middleware.cc +++ b/cpp/src/arrow/flight/sql/server_session_middleware.cc @@ -17,6 +17,7 @@ #include +#include "arrow/flight/server.h" #include "arrow/flight/sql/server_session_middleware.h" #include "arrow/flight/sql/server_session_middleware_factory.h" @@ -134,12 +135,12 @@ ServerSessionMiddlewareFactory::ParseCookieString(const std::string_view& s) { } Status ServerSessionMiddlewareFactory::StartCall( - const CallInfo&, const CallHeaders& incoming_headers, + const CallInfo&, const const ServerCallContext& context, std::shared_ptr* middleware) { std::string session_id; const std::pair& - headers_it_pr = incoming_headers.equal_range("cookie"); + headers_it_pr = context.incoming_headers().equal_range("cookie"); for (auto itr = headers_it_pr.first; itr != headers_it_pr.second; ++itr) { const std::string_view& cookie_header = itr->second; const std::vector> cookies = @@ -158,7 +159,7 @@ Status ServerSessionMiddlewareFactory::StartCall( // No cookie was found // Temporary workaround until middleware handling fixed auto [id, s] = CreateNewSession(); - *middleware = std::make_shared(this, incoming_headers, + *middleware = std::make_shared(this, context.incoming_headers(), std::move(s), id, false); } else { const std::shared_lock l(session_store_lock_); @@ -167,7 +168,7 @@ Status ServerSessionMiddlewareFactory::StartCall( } else { auto session = it->second; *middleware = std::make_shared( - this, incoming_headers, std::move(session), session_id); + this, context.incoming_headers(), std::move(session), session_id); } } diff --git a/cpp/src/arrow/flight/sql/server_session_middleware_factory.h b/cpp/src/arrow/flight/sql/server_session_middleware_factory.h index 2613c572eefc..ef90bc876bb9 100644 --- a/cpp/src/arrow/flight/sql/server_session_middleware_factory.h +++ b/cpp/src/arrow/flight/sql/server_session_middleware_factory.h @@ -46,7 +46,7 @@ class ARROW_FLIGHT_SQL_EXPORT ServerSessionMiddlewareFactory public: explicit ServerSessionMiddlewareFactory(std::function id_gen) : id_generator_(id_gen) {} - Status StartCall(const CallInfo&, const CallHeaders& incoming_headers, + Status StartCall(const CallInfo&, const ServerCallContext& context, std::shared_ptr* middleware) override; /// \brief Get a new, empty session option map and its id key. From f1d71f486670ad939f5e3bcc3fca81bf7c4ab61d Mon Sep 17 00:00:00 2001 From: AlenkaF Date: Tue, 25 Mar 2025 15:08:07 +0100 Subject: [PATCH 4/4] Fix linter errors and typo --- cpp/src/arrow/flight/sql/server_session_middleware.cc | 6 +++--- python/pyarrow/src/arrow/python/flight.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/flight/sql/server_session_middleware.cc b/cpp/src/arrow/flight/sql/server_session_middleware.cc index e9d101c58bcc..30209c2278b9 100644 --- a/cpp/src/arrow/flight/sql/server_session_middleware.cc +++ b/cpp/src/arrow/flight/sql/server_session_middleware.cc @@ -135,7 +135,7 @@ ServerSessionMiddlewareFactory::ParseCookieString(const std::string_view& s) { } Status ServerSessionMiddlewareFactory::StartCall( - const CallInfo&, const const ServerCallContext& context, + const CallInfo&, const ServerCallContext& context, std::shared_ptr* middleware) { std::string session_id; @@ -159,8 +159,8 @@ Status ServerSessionMiddlewareFactory::StartCall( // No cookie was found // Temporary workaround until middleware handling fixed auto [id, s] = CreateNewSession(); - *middleware = std::make_shared(this, context.incoming_headers(), - std::move(s), id, false); + *middleware = std::make_shared( + this, context.incoming_headers(), std::move(s), id, false); } else { const std::shared_lock l(session_store_lock_); if (auto it = session_store_.find(session_id); it == session_store_.end()) { diff --git a/python/pyarrow/src/arrow/python/flight.cc b/python/pyarrow/src/arrow/python/flight.cc index 7cda1ecde1cc..2fda48b70b0f 100644 --- a/python/pyarrow/src/arrow/python/flight.cc +++ b/python/pyarrow/src/arrow/python/flight.cc @@ -272,7 +272,7 @@ Status PyServerMiddlewareFactory::StartCall( std::shared_ptr* middleware) { return SafeCallIntoPython([&] { const Status status = - start_call_(factory_.obj(), info, context.incoming_headers(), middleware); + start_call_(factory_.obj(), info, context.incoming_headers(), middleware); RETURN_NOT_OK(CheckPyError()); return status; });