lidavidm commented on code in PR #12442: URL: https://github.com/apache/arrow/pull/12442#discussion_r841658890
########## cpp/src/arrow/flight/transport/ucx/ucx_server.cc: ########## @@ -0,0 +1,646 @@ +// 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/transport/ucx/ucx_internal.h" + +#include <atomic> +#include <mutex> +#include <queue> +#include <thread> +#include <unordered_map> + +#include <arpa/inet.h> +#include <ucp/api/ucp.h> + +#include "arrow/buffer.h" +#include "arrow/flight/server.h" +#include "arrow/flight/transport.h" +#include "arrow/flight/transport/ucx/util_internal.h" +#include "arrow/flight/transport_server.h" +#include "arrow/result.h" +#include "arrow/status.h" +#include "arrow/util/io_util.h" +#include "arrow/util/logging.h" +#include "arrow/util/make_unique.h" +#include "arrow/util/thread_pool.h" +#include "arrow/util/uri.h" + +namespace arrow { +namespace flight { +namespace transport { +namespace ucx { + +// Send an error to the client and return OK. +// Statuses returned up to the main server loop trigger a kReset instead. +#define SERVER_RETURN_NOT_OK(driver, status) \ + do { \ + ::arrow::Status s = (status); \ + if (!s.ok()) { \ + ARROW_ASSIGN_OR_RAISE(auto headers, HeadersFrame::Make(s, {})); \ + auto payload = std::move(headers).GetBuffer(); \ + RETURN_NOT_OK( \ + driver->SendFrame(FrameType::kHeaders, payload->data(), payload->size())); \ + return ::arrow::Status::OK(); \ + } \ + } while (false) + +#define FLIGHT_LOG(LEVEL) (ARROW_LOG(LEVEL) << "[server] ") +#define FLIGHT_LOG_PEER(LEVEL, PEER) \ + (ARROW_LOG(LEVEL) << "[server]" \ + << "[peer=" << (PEER) << "] ") + +namespace { +class UcxServerCallContext : public flight::ServerCallContext { + public: + const std::string& peer_identity() const override { return peer_; } + const std::string& peer() const override { return peer_; } + ServerMiddleware* GetMiddleware(const std::string& key) const override { + return nullptr; + } + bool is_cancelled() const override { return false; } + + private: + std::string peer_; +}; + +class UcxServerStream : public internal::ServerDataStream { + public: + // TODO(lidavidm): backpressure threshold should be dynamic (ideally + // auto-adjusted, or at least configurable) + constexpr static size_t kBackpressureThreshold = 8; + + explicit UcxServerStream(UcpCallDriver* driver) + : peer_(driver->peer()), driver_(driver), writes_done_(false) {} + + Status WritesDone() override { + RETURN_NOT_OK(CheckBackpressure(0)); + writes_done_ = true; + return Status::OK(); + } + + protected: + Status CheckBackpressure(size_t limit = kBackpressureThreshold - 1) { Review Comment: I'm not actually sure how much of an effect this has since UCX doesn't do any work anyways until we call ucp_worker_progress -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
