From 6462d913ca127aa5fcffdc16aa288ec22f44b700 Mon Sep 17 00:00:00 2001 From: Pxl Date: Thu, 21 Mar 2024 20:10:02 +0800 Subject: [PATCH] =?UTF-8?q?[Improvement](brpc)=20log=20error=20message=20w?= =?UTF-8?q?hen=20AutoReleaseClosure=20meet=20brpc=20error=20or=20response?= =?UTF-8?q?=E2=80=A6=20(#32628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit log error message when AutoReleaseClosure meet brpc error or response with error status --- be/src/util/ref_count_closure.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/be/src/util/ref_count_closure.h b/be/src/util/ref_count_closure.h index 14a136fcfd..7bbcfb7da3 100644 --- a/be/src/util/ref_count_closure.h +++ b/be/src/util/ref_count_closure.h @@ -68,6 +68,19 @@ public: // std::unique_ptr a(b); // brpc_call(a.release()); +template +concept HasStatus = requires(T* response) { response->status(); }; + +template +void process_status(Response* response) {} + +template +void process_status(Response* response) { + if (auto status = Status::create(response->status()); !status) { + LOG(WARNING) << "RPC meet error status: " << status; + } +} + template class AutoReleaseClosure : public google::protobuf::Closure { using Weak = typename std::shared_ptr::weak_type; @@ -91,6 +104,11 @@ public: if (auto tmp = callback_.lock()) { tmp->call(); } + if (cntl_->Failed()) { + LOG(WARNING) << "RPC meet failed: " << cntl_->ErrorText(); + } else { + process_status(response_.get()); + } } // controller has to be the same lifecycle with the closure, because brpc may use