From 360ca4bf1e5f9ae81b2d6eee1764855f9e517004 Mon Sep 17 00:00:00 2001 From: Matevz Tadel Date: Tue, 28 Sep 2021 19:37:46 +0200 Subject: [PATCH] For async calls always store XrdCl::FileSystem with the response-handler. --- Utilities/XrdAdaptor/src/XrdRequestManager.cc | 15 ++++++++++----- Utilities/XrdAdaptor/src/XrdSource.cc | 15 ++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Utilities/XrdAdaptor/src/XrdRequestManager.cc b/Utilities/XrdAdaptor/src/XrdRequestManager.cc index 3096f14132bce..43941481550a1 100644 --- a/Utilities/XrdAdaptor/src/XrdRequestManager.cc +++ b/Utilities/XrdAdaptor/src/XrdRequestManager.cc @@ -79,15 +79,20 @@ class SendMonitoringInfoHandler : public XrdCl::ResponseHandler { // Send Info has a response object; we must delete it. delete response; delete status; + delete this; } + XrdCl::FileSystem m_fs; + public: SendMonitoringInfoHandler(const SendMonitoringInfoHandler &) = delete; SendMonitoringInfoHandler &operator=(const SendMonitoringInfoHandler &) = delete; SendMonitoringInfoHandler() = default; -}; -CMS_THREAD_SAFE SendMonitoringInfoHandler nullHandler; + SendMonitoringInfoHandler(const std::string &url) : m_fs(url) {} + + XrdCl::FileSystem& fs() { return m_fs; } +}; static void SendMonitoringInfo(XrdCl::File &file) { // Do not send this to a dCache data server as they return an error. @@ -102,11 +107,11 @@ static void SendMonitoringInfo(XrdCl::File &file) { std::string lastUrl; file.GetProperty("LastURL", lastUrl); if (jobId && !lastUrl.empty()) { - XrdCl::URL url(lastUrl); - XrdCl::FileSystem fs(url); - if (!(fs.SendInfo(jobId, &nullHandler, 30).IsOK())) { + auto sm_handler = new SendMonitoringInfoHandler(lastUrl); + if (!(sm_handler->fs().SendInfo(jobId, sm_handler, 30).IsOK())) { edm::LogWarning("XrdAdaptorInternal") << "Failed to send the monitoring information, monitoring ID is " << jobId << "."; + delete sm_handler; } edm::LogInfo("XrdAdaptorInternal") << "Set monitoring ID to " << jobId << "."; } diff --git a/Utilities/XrdAdaptor/src/XrdSource.cc b/Utilities/XrdAdaptor/src/XrdSource.cc index 9759013b4be6c..b0264c1d4b324 100644 --- a/Utilities/XrdAdaptor/src/XrdSource.cc +++ b/Utilities/XrdAdaptor/src/XrdSource.cc @@ -83,21 +83,24 @@ class QueryAttrHandler : public XrdCl::ResponseHandler { friend std::unique_ptr std::make_unique(); public: + QueryAttrHandler() = delete; ~QueryAttrHandler() override = default; QueryAttrHandler(const QueryAttrHandler &) = delete; QueryAttrHandler &operator=(const QueryAttrHandler &) = delete; - static XrdCl::XRootDStatus query(XrdCl::FileSystem &fs, + QueryAttrHandler(const std::string &url) : m_fs(url) {} + + static XrdCl::XRootDStatus query(const std::string &url, const std::string &attr, std::chrono::milliseconds timeout, std::string &result) { - auto handler = std::make_unique(); + auto handler = std::make_unique(url); auto l_state = std::make_shared(); handler->m_state = l_state; XrdCl::Buffer arg(attr.size()); arg.FromString(attr); - XrdCl::XRootDStatus st = fs.Query(XrdCl::QueryCode::Config, arg, handler.get()); + XrdCl::XRootDStatus st = handler->m_fs.Query(XrdCl::QueryCode::Config, arg, handler.get()); if (!st.IsOK()) { return st; } @@ -121,8 +124,6 @@ class QueryAttrHandler : public XrdCl::ResponseHandler { } private: - QueryAttrHandler() {} - void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override { // NOTE: we own the status and response pointers. std::unique_ptr response_mgr; @@ -176,6 +177,7 @@ class QueryAttrHandler : public XrdCl::ResponseHandler { std::unique_ptr m_response; }; std::weak_ptr m_state; + XrdCl::FileSystem m_fs; }; Source::Source(timespec now, std::unique_ptr fh, const std::string &exclude) @@ -329,9 +331,8 @@ bool Source::getXrootdSiteFromURL(std::string url, std::string &site) { XrdCl::Buffer arg(attr.size()); arg.FromString(attr); - XrdCl::FileSystem fs(url); std::string rsite; - XrdCl::XRootDStatus st = QueryAttrHandler::query(fs, "sitename", std::chrono::seconds(1), rsite); + XrdCl::XRootDStatus st = QueryAttrHandler::query(url, "sitename", std::chrono::seconds(1), rsite); if (!st.IsOK()) { XrdCl::URL xurl(url); getDomain(xurl.GetHostName(), site);