Skip to content

Commit

Permalink
Merge pull request #35455 from osschar/from-CMSSW_12_1_DEVEL_X_2021-0…
Browse files Browse the repository at this point in the history
…9-26-2300

For async calls always store XrdCl::FileSystem with the response-handler.
  • Loading branch information
cmsbuild authored Sep 29, 2021
2 parents a9680d0 + 360ca4b commit 9ba0bf8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 10 additions & 5 deletions Utilities/XrdAdaptor/src/XrdRequestManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 << ".";
}
Expand Down
15 changes: 8 additions & 7 deletions Utilities/XrdAdaptor/src/XrdSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,24 @@ class QueryAttrHandler : public XrdCl::ResponseHandler {
friend std::unique_ptr<QueryAttrHandler> std::make_unique<QueryAttrHandler>();

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<QueryAttrHandler>();
auto handler = std::make_unique<QueryAttrHandler>(url);
auto l_state = std::make_shared<QueryAttrState>();
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;
}
Expand All @@ -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<XrdCl::AnyObject> response_mgr;
Expand Down Expand Up @@ -176,6 +177,7 @@ class QueryAttrHandler : public XrdCl::ResponseHandler {
std::unique_ptr<XrdCl::Buffer> m_response;
};
std::weak_ptr<QueryAttrState> m_state;
XrdCl::FileSystem m_fs;
};

Source::Source(timespec now, std::unique_ptr<XrdCl::File> fh, const std::string &exclude)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9ba0bf8

Please sign in to comment.