CMS 3D CMS Logo

XrdRequestManager.cc
Go to the documentation of this file.
1 
2 #include <cassert>
3 #include <iostream>
4 #include <algorithm>
5 #include <netdb.h>
6 
7 #include "XrdCl/XrdClFile.hh"
8 #include "XrdCl/XrdClDefaultEnv.hh"
9 #include "XrdCl/XrdClFileSystem.hh"
10 
18 
19 #include "XrdStatistics.h"
21 #include "Utilities/XrdAdaptor/src/XrdHostHandler.hh"
22 
23 #define XRD_CL_MAX_CHUNK 512 * 1024
24 
25 #define XRD_ADAPTOR_SHORT_OPEN_DELAY 5
26 
27 #ifdef XRD_FAKE_OPEN_PROBE
28 #define XRD_ADAPTOR_OPEN_PROBE_PERCENT 100
29 #define XRD_ADAPTOR_LONG_OPEN_DELAY 20
30 // This is the minimal difference in quality required to swap an active and inactive source
31 #define XRD_ADAPTOR_SOURCE_QUALITY_FUDGE 0
32 #else
33 #define XRD_ADAPTOR_OPEN_PROBE_PERCENT 10
34 #define XRD_ADAPTOR_LONG_OPEN_DELAY 2 * 60
35 #define XRD_ADAPTOR_SOURCE_QUALITY_FUDGE 100
36 #endif
37 
38 #define XRD_ADAPTOR_CHUNK_THRESHOLD 1000
39 
40 #ifdef __MACH__
41 #include <mach/clock.h>
42 #include <mach/mach.h>
43 #define GET_CLOCK_MONOTONIC(ts) \
44  { \
45  clock_serv_t cclock; \
46  mach_timespec_t mts; \
47  host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); \
48  clock_get_time(cclock, &mts); \
49  mach_port_deallocate(mach_task_self(), cclock); \
50  ts.tv_sec = mts.tv_sec; \
51  ts.tv_nsec = mts.tv_nsec; \
52  }
53 #else
54 #define GET_CLOCK_MONOTONIC(ts) clock_gettime(CLOCK_MONOTONIC, &ts);
55 #endif
56 
57 using namespace XrdAdaptor;
58 
59 long long timeDiffMS(const timespec &a, const timespec &b) {
60  long long diff = (a.tv_sec - b.tv_sec) * 1000;
61  diff += (a.tv_nsec - b.tv_nsec) / 1e6;
62  return diff;
63 }
64 
65 /*
66  * We do not care about the response of sending the monitoring information;
67  * this handler class simply frees any returned buffer to prevent memory leaks.
68  */
69 class SendMonitoringInfoHandler : boost::noncopyable, public XrdCl::ResponseHandler {
70  void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override {
71  if (response) {
72  XrdCl::Buffer *buffer = nullptr;
73  response->Get(buffer);
74  response->Set(static_cast<int *>(nullptr));
75  delete buffer;
76  }
77  // Send Info has a response object; we must delete it.
78  delete response;
79  delete status;
80  }
81 };
82 
84 
86  // Do not send this to a dCache data server as they return an error.
87  // In some versions of dCache, sending the monitoring information causes
88  // the server to close the connection - resulting in failures.
90  return;
91  }
92 
93  // Send the monitoring info, if available.
95  std::string lastUrl;
96  file.GetProperty("LastURL", lastUrl);
97  if (jobId && !lastUrl.empty()) {
98  XrdCl::URL url(lastUrl);
99  XrdCl::FileSystem fs(url);
100  if (!(fs.SendInfo(jobId, &nullHandler, 30).IsOK())) {
101  edm::LogWarning("XrdAdaptorInternal")
102  << "Failed to send the monitoring information, monitoring ID is " << jobId << ".";
103  }
104  edm::LogInfo("XrdAdaptorInternal") << "Set monitoring ID to " << jobId << ".";
105  }
106 }
107 
109  : m_serverToAdvertise(nullptr),
110  m_timeout(XRD_DEFAULT_TIMEOUT),
111  m_nextInitialSourceToggle(false),
112  m_name(filename),
113  m_flags(flags),
114  m_perms(perms),
115  m_distribution(0, 100),
116  m_excluded_active_count(0) {}
117 
118 void RequestManager::initialize(std::weak_ptr<RequestManager> self) {
120 
121  XrdCl::Env *env = XrdCl::DefaultEnv::GetEnv();
122  if (env) {
123  env->GetInt("StreamErrorWindow", m_timeout);
124  }
125 
126  std::string orig_site;
127  if (!Source::getXrootdSiteFromURL(m_name, orig_site) && (orig_site.find(".") == std::string::npos)) {
128  std::string hostname;
129  if (Source::getHostname(orig_site, hostname)) {
130  Source::getDomain(hostname, orig_site);
131  }
132  }
133 
134  std::unique_ptr<XrdCl::File> file;
136  bool validFile = false;
137  const int retries = 5;
138  std::string excludeString;
139  for (int idx = 0; idx < retries; idx++) {
140  file.reset(new XrdCl::File());
141  auto opaque = prepareOpaqueString();
142  std::string new_filename =
143  m_name + (!opaque.empty() ? ((m_name.find("?") == m_name.npos) ? "?" : "&") + opaque : "");
144  SyncHostResponseHandler handler;
145  XrdCl::XRootDStatus openStatus = file->Open(new_filename, m_flags, m_perms, &handler);
146  if (!openStatus
147  .IsOK()) { // In this case, we failed immediately - this indicates we have previously tried to talk to this
148  // server and it was marked bad - xrootd couldn't even queue up the request internally!
149  // In practice, we obsere this happening when the call to getXrootdSiteFromURL fails due to the
150  // redirector being down or authentication failures.
151  ex.clearMessage();
152  ex.clearContext();
153  ex.clearAdditionalInfo();
154  ex << "XrdCl::File::Open(name='" << m_name << "', flags=0x" << std::hex << m_flags << ", permissions=0"
155  << std::oct << m_perms << std::dec << ") => error '" << openStatus.ToStr() << "' (errno=" << openStatus.errNo
156  << ", code=" << openStatus.code << ")";
157  ex.addContext("Calling XrdFile::open()");
158  ex.addAdditionalInfo("Remote server already encountered a fatal error; no redirections were performed.");
159  throw ex;
160  }
161  handler.WaitForResponse();
162  std::unique_ptr<XrdCl::XRootDStatus> status = handler.GetStatus();
163  std::unique_ptr<XrdCl::HostList> hostList = handler.GetHosts();
164  Source::determineHostExcludeString(*file, hostList.get(), excludeString);
165  assert(status);
166  if (status->IsOK()) {
167  validFile = true;
168  break;
169  } else {
170  ex.clearMessage();
171  ex.clearContext();
172  ex.clearAdditionalInfo();
173  ex << "XrdCl::File::Open(name='" << m_name << "', flags=0x" << std::hex << m_flags << ", permissions=0"
174  << std::oct << m_perms << std::dec << ") => error '" << status->ToStr() << "' (errno=" << status->errNo
175  << ", code=" << status->code << ")";
176  ex.addContext("Calling XrdFile::open()");
177  addConnections(ex);
178  std::string dataServer, lastUrl;
179  file->GetProperty("DataServer", dataServer);
180  file->GetProperty("LastURL", lastUrl);
181  if (!dataServer.empty()) {
182  ex.addAdditionalInfo("Problematic data server: " + dataServer);
183  }
184  if (!lastUrl.empty()) {
185  ex.addAdditionalInfo("Last URL tried: " + lastUrl);
186  edm::LogWarning("XrdAdaptorInternal") << "Failed to open file at URL " << lastUrl << ".";
187  }
188  if (std::find(m_disabledSourceStrings.begin(), m_disabledSourceStrings.end(), dataServer) !=
189  m_disabledSourceStrings.end()) {
190  ex << ". No additional data servers were found.";
191  throw ex;
192  }
193  if (!dataServer.empty()) {
194  m_disabledSourceStrings.insert(dataServer);
195  m_disabledExcludeStrings.insert(excludeString);
196  }
197  // In this case, we didn't go anywhere - we stayed at the redirector and it gave us a file-not-found.
198  if (lastUrl == new_filename) {
199  edm::LogWarning("XrdAdaptorInternal") << lastUrl << ", " << new_filename;
200  throw ex;
201  }
202  }
203  }
204  if (!validFile) {
205  throw ex;
206  }
208 
209  timespec ts;
211 
212  auto source = std::make_shared<Source>(ts, std::move(file), excludeString);
213  {
214  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
215  auto oldList = m_activeSources;
216  m_activeSources.push_back(source);
218  }
221 
222  m_lastSourceCheck = ts;
223  ts.tv_sec += XRD_ADAPTOR_SHORT_OPEN_DELAY;
225 }
226 
235  // NOTE: we use memory_order_relaxed here, meaning that we may actually miss
236  // a pending update. *However*, since we call this for every read, we'll get it
237  // eventually.
238  if (LIKELY(!m_serverToAdvertise.load(std::memory_order_relaxed))) {
239  return;
240  }
241  std::string *hostname_ptr;
242  if ((hostname_ptr = m_serverToAdvertise.exchange(nullptr))) {
243  std::unique_ptr<std::string> hostname(hostname_ptr);
245  if (statsService.isAvailable()) {
246  statsService->setCurrentServer(*hostname_ptr);
247  }
248  }
249 }
250 
252  auto hostname = std::make_unique<std::string>(id);
253  if (Source::getHostname(id, *hostname)) {
254  std::string *null_hostname = nullptr;
255  if (m_serverToAdvertise.compare_exchange_strong(null_hostname, hostname.get())) {
256  hostname.release();
257  }
258  }
259 }
260 
261 namespace {
262  std::string formatSites(std::vector<std::shared_ptr<Source>> const &iSources) {
263  std::string siteA, siteB;
264  if (!iSources.empty()) {
265  siteA = iSources[0]->Site();
266  }
267  if (iSources.size() == 2) {
268  siteB = iSources[1]->Site();
269  }
270  std::string siteList = siteA;
271  if (!siteB.empty() && (siteB != siteA)) {
272  siteList = siteA + ", " + siteB;
273  }
274  return siteList;
275  }
276 } // namespace
277 
278 void RequestManager::reportSiteChange(std::vector<std::shared_ptr<Source>> const &iOld,
279  std::vector<std::shared_ptr<Source>> const &iNew,
280  std::string orig_site) const {
281  auto siteList = formatSites(iNew);
282  if (!orig_site.empty() && (orig_site != siteList)) {
283  edm::LogWarning("XrdAdaptor") << "Data is served from " << siteList << " instead of original site " << orig_site;
284  } else {
285  auto oldSites = formatSites(iOld);
286  if (orig_site.empty() && (siteList != oldSites)) {
287  if (!oldSites.empty())
288  edm::LogWarning("XrdAdaptor") << "Data is now served from " << siteList << " instead of previous " << oldSites;
289  }
290  }
291 }
292 
294  IOSize requestSize,
295  std::vector<std::shared_ptr<Source>> &activeSources,
296  std::vector<std::shared_ptr<Source>> &inactiveSources) {
297  edm::LogVerbatim("XrdAdaptorInternal") << "Time since last check " << timeDiffMS(now, m_lastSourceCheck)
298  << "; last check " << m_lastSourceCheck.tv_sec << "; now " << now.tv_sec
299  << "; next check " << m_nextActiveSourceCheck.tv_sec << std::endl;
300  if (timeDiffMS(now, m_lastSourceCheck) > 1000) {
301  { // Be more aggressive about getting rid of very bad sources.
302  compareSources(now, 0, 1, activeSources, inactiveSources);
303  compareSources(now, 1, 0, activeSources, inactiveSources);
304  }
306  checkSourcesImpl(now, requestSize, activeSources, inactiveSources);
307  }
308  }
309 }
310 
311 bool RequestManager::compareSources(const timespec &now,
312  unsigned a,
313  unsigned b,
314  std::vector<std::shared_ptr<Source>> &activeSources,
315  std::vector<std::shared_ptr<Source>> &inactiveSources) const {
316  if (activeSources.size() < std::max(a, b) + 1) {
317  return false;
318  }
319 
320  bool findNewSource = false;
321  if ((activeSources[a]->getQuality() > 5130) ||
322  ((activeSources[a]->getQuality() > 260) &&
323  (activeSources[b]->getQuality() * 4 < activeSources[a]->getQuality()))) {
324  edm::LogVerbatim("XrdAdaptorInternal")
325  << "Removing " << activeSources[a]->PrettyID() << " from active sources due to poor quality ("
326  << activeSources[a]->getQuality() << " vs " << activeSources[b]->getQuality() << ")" << std::endl;
327  if (activeSources[a]->getLastDowngrade().tv_sec != 0) {
328  findNewSource = true;
329  }
330  activeSources[a]->setLastDowngrade(now);
331  inactiveSources.emplace_back(activeSources[a]);
332  auto oldSources = activeSources;
333  activeSources.erase(activeSources.begin() + a);
334  reportSiteChange(oldSources, activeSources);
335  }
336  return findNewSource;
337 }
338 
340  IOSize requestSize,
341  std::vector<std::shared_ptr<Source>> &activeSources,
342  std::vector<std::shared_ptr<Source>> &inactiveSources) {
343  bool findNewSource = false;
344  if (activeSources.size() <= 1) {
345  findNewSource = true;
346  } else if (activeSources.size() > 1) {
347  edm::LogVerbatim("XrdAdaptorInternal") << "Source 0 quality " << activeSources[0]->getQuality()
348  << ", source 1 quality " << activeSources[1]->getQuality() << std::endl;
349  findNewSource |= compareSources(now, 0, 1, activeSources, inactiveSources);
350  findNewSource |= compareSources(now, 1, 0, activeSources, inactiveSources);
351 
352  // NOTE: We could probably replace the copy with a better sort function.
353  // However, there are typically very few sources and the correctness is more obvious right now.
354  std::vector<std::shared_ptr<Source>> eligibleInactiveSources;
355  eligibleInactiveSources.reserve(inactiveSources.size());
356  for (const auto &source : inactiveSources) {
357  if (timeDiffMS(now, source->getLastDowngrade()) > (XRD_ADAPTOR_SHORT_OPEN_DELAY - 1) * 1000) {
358  eligibleInactiveSources.push_back(source);
359  }
360  }
361  auto bestInactiveSource =
362  std::min_element(eligibleInactiveSources.begin(),
363  eligibleInactiveSources.end(),
364  [](const std::shared_ptr<Source> &s1, const std::shared_ptr<Source> &s2) {
365  return s1->getQuality() < s2->getQuality();
366  });
367  auto worstActiveSource = std::max_element(activeSources.cbegin(),
368  activeSources.cend(),
369  [](const std::shared_ptr<Source> &s1, const std::shared_ptr<Source> &s2) {
370  return s1->getQuality() < s2->getQuality();
371  });
372  if (bestInactiveSource != eligibleInactiveSources.end() && bestInactiveSource->get()) {
373  edm::LogVerbatim("XrdAdaptorInternal") << "Best inactive source: " << (*bestInactiveSource)->PrettyID()
374  << ", quality " << (*bestInactiveSource)->getQuality();
375  }
376  edm::LogVerbatim("XrdAdaptorInternal") << "Worst active source: " << (*worstActiveSource)->PrettyID()
377  << ", quality " << (*worstActiveSource)->getQuality();
378  // Only upgrade the source if we only have one source and the best inactive one isn't too horrible.
379  // Regardless, we will want to re-evaluate the new source quickly (within 5s).
380  if ((bestInactiveSource != eligibleInactiveSources.end()) && activeSources.size() == 1 &&
381  ((*bestInactiveSource)->getQuality() < 4 * activeSources[0]->getQuality())) {
382  auto oldSources = activeSources;
383  activeSources.push_back(*bestInactiveSource);
384  reportSiteChange(oldSources, activeSources);
385  for (auto it = inactiveSources.begin(); it != inactiveSources.end(); it++)
386  if (it->get() == bestInactiveSource->get()) {
387  inactiveSources.erase(it);
388  break;
389  }
390  } else
391  while ((bestInactiveSource != eligibleInactiveSources.end()) &&
392  (*worstActiveSource)->getQuality() >
393  (*bestInactiveSource)->getQuality() + XRD_ADAPTOR_SOURCE_QUALITY_FUDGE) {
394  edm::LogVerbatim("XrdAdaptorInternal")
395  << "Removing " << (*worstActiveSource)->PrettyID() << " from active sources due to quality ("
396  << (*worstActiveSource)->getQuality() << ") and promoting " << (*bestInactiveSource)->PrettyID()
397  << " (quality: " << (*bestInactiveSource)->getQuality() << ")" << std::endl;
398  (*worstActiveSource)->setLastDowngrade(now);
399  for (auto it = inactiveSources.begin(); it != inactiveSources.end(); it++)
400  if (it->get() == bestInactiveSource->get()) {
401  inactiveSources.erase(it);
402  break;
403  }
404  inactiveSources.emplace_back(std::move(*worstActiveSource));
405  auto oldSources = activeSources;
406  activeSources.erase(worstActiveSource);
407  activeSources.emplace_back(std::move(*bestInactiveSource));
408  reportSiteChange(oldSources, activeSources);
409  eligibleInactiveSources.clear();
410  for (const auto &source : inactiveSources)
411  if (timeDiffMS(now, source->getLastDowngrade()) > (XRD_ADAPTOR_LONG_OPEN_DELAY - 1) * 1000)
412  eligibleInactiveSources.push_back(source);
413  bestInactiveSource = std::min_element(eligibleInactiveSources.begin(),
414  eligibleInactiveSources.end(),
415  [](const std::shared_ptr<Source> &s1, const std::shared_ptr<Source> &s2) {
416  return s1->getQuality() < s2->getQuality();
417  });
418  worstActiveSource = std::max_element(activeSources.begin(),
419  activeSources.end(),
420  [](const std::shared_ptr<Source> &s1, const std::shared_ptr<Source> &s2) {
421  return s1->getQuality() < s2->getQuality();
422  });
423  }
424  if (!findNewSource && (timeDiffMS(now, m_lastSourceCheck) > 1000 * XRD_ADAPTOR_LONG_OPEN_DELAY)) {
425  float r = m_distribution(m_generator);
427  findNewSource = true;
428  }
429  }
430  }
431  if (findNewSource) {
432  m_open_handler->open();
434  }
435 
436  // Only aggressively look for new sources if we don't have two.
437  if (activeSources.size() == 2) {
439  } else {
441  }
443 }
444 
445 std::shared_ptr<XrdCl::File> RequestManager::getActiveFile() const {
446  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
447  if (m_activeSources.empty()) {
449  ex << "XrdAdaptor::RequestManager::getActiveFile(name='" << m_name << "', flags=0x" << std::hex << m_flags
450  << ", permissions=0" << std::oct << m_perms << std::dec << ") => Source used after fatal exception.";
451  ex.addContext("In XrdAdaptor::RequestManager::handle()");
452  addConnections(ex);
453  throw ex;
454  }
455  return m_activeSources[0]->getFileHandle();
456 }
457 
458 void RequestManager::getActiveSourceNames(std::vector<std::string> &sources) const {
459  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
460  sources.reserve(m_activeSources.size());
461  for (auto const &source : m_activeSources) {
462  sources.push_back(source->ID());
463  }
464 }
465 
466 void RequestManager::getPrettyActiveSourceNames(std::vector<std::string> &sources) const {
467  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
468  sources.reserve(m_activeSources.size());
469  for (auto const &source : m_activeSources) {
470  sources.push_back(source->PrettyID());
471  }
472 }
473 
474 void RequestManager::getDisabledSourceNames(std::vector<std::string> &sources) const {
475  sources.reserve(m_disabledSourceStrings.size());
476  for (auto const &source : m_disabledSourceStrings) {
477  sources.push_back(source);
478  }
479 }
480 
482  std::vector<std::string> sources;
484  for (auto const &source : sources) {
485  ex.addAdditionalInfo("Active source: " + source);
486  }
487  sources.clear();
489  for (auto const &source : sources) {
490  ex.addAdditionalInfo("Disabled source: " + source);
491  }
492 }
493 
494 std::shared_ptr<Source> RequestManager::pickSingleSource() {
495  std::shared_ptr<Source> source = nullptr;
496  {
497  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
498  if (m_activeSources.size() == 2) {
500  source = m_activeSources[0];
502  } else {
503  source = m_activeSources[1];
505  }
506  } else if (m_activeSources.empty()) {
508  ex << "XrdAdaptor::RequestManager::handle read(name='" << m_name << "', flags=0x" << std::hex << m_flags
509  << ", permissions=0" << std::oct << m_perms << std::dec << ") => Source used after fatal exception.";
510  ex.addContext("In XrdAdaptor::RequestManager::handle()");
511  addConnections(ex);
512  throw ex;
513  } else {
514  source = m_activeSources[0];
515  }
516  }
517  return source;
518 }
519 
520 std::future<IOSize> RequestManager::handle(std::shared_ptr<XrdAdaptor::ClientRequest> c_ptr) {
521  assert(c_ptr.get());
522  timespec now;
524  //NOTE: can't hold lock while calling checkSources since can lead to lock inversion
525  std::vector<std::shared_ptr<Source>> activeSources, inactiveSources;
526  {
527  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
529  inactiveSources = m_inactiveSources;
530  }
531  {
532  //make sure we update values before calling pickSingelSource
533  std::shared_ptr<void *> guard(nullptr, [this, &activeSources, &inactiveSources](void *) {
534  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
536  m_inactiveSources = std::move(inactiveSources);
537  });
538 
539  checkSources(now, c_ptr->getSize(), activeSources, inactiveSources);
540  }
541 
542  std::shared_ptr<Source> source = pickSingleSource();
543  source->handle(c_ptr);
544  return c_ptr->get_future();
545 }
546 
548  std::stringstream ss;
549  ss << "tried=";
550  size_t count = 0;
551  {
552  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
553 
554  for (const auto &it : m_activeSources) {
555  count++;
556  ss << it->ExcludeID().substr(0, it->ExcludeID().find(":")) << ",";
557  }
558  for (const auto &it : m_inactiveSources) {
559  count++;
560  ss << it->ExcludeID().substr(0, it->ExcludeID().find(":")) << ",";
561  }
562  }
563  for (const auto &it : m_disabledExcludeStrings) {
564  count++;
565  ss << it.substr(0, it.find(":")) << ",";
566  }
567  if (count) {
568  std::string tmp_str = ss.str();
569  return tmp_str.substr(0, tmp_str.size() - 1);
570  }
571  return "";
572 }
573 
574 void XrdAdaptor::RequestManager::handleOpen(XrdCl::XRootDStatus &status, std::shared_ptr<Source> source) {
575  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
576  if (status.IsOK()) {
577  edm::LogVerbatim("XrdAdaptorInternal") << "Successfully opened new source: " << source->PrettyID() << std::endl;
578  for (const auto &s : m_activeSources) {
579  if (source->ID() == s->ID()) {
580  edm::LogVerbatim("XrdAdaptorInternal")
581  << "Xrootd server returned excluded source " << source->PrettyID() << "; ignoring" << std::endl;
582  unsigned returned_count = ++m_excluded_active_count;
583  m_nextActiveSourceCheck.tv_sec += XRD_ADAPTOR_SHORT_OPEN_DELAY;
584  if (returned_count >= 3) {
585  m_nextActiveSourceCheck.tv_sec += XRD_ADAPTOR_LONG_OPEN_DELAY - 2 * XRD_ADAPTOR_SHORT_OPEN_DELAY;
586  }
587  return;
588  }
589  }
590  for (const auto &s : m_inactiveSources) {
591  if (source->ID() == s->ID()) {
592  edm::LogVerbatim("XrdAdaptorInternal")
593  << "Xrootd server returned excluded inactive source " << source->PrettyID() << "; ignoring" << std::endl;
594  m_nextActiveSourceCheck.tv_sec += XRD_ADAPTOR_LONG_OPEN_DELAY - XRD_ADAPTOR_SHORT_OPEN_DELAY;
595  return;
596  }
597  }
598  if (m_activeSources.size() < 2) {
599  auto oldSources = m_activeSources;
600  m_activeSources.push_back(source);
601  reportSiteChange(oldSources, m_activeSources);
602  queueUpdateCurrentServer(source->ID());
603  } else {
604  m_inactiveSources.push_back(source);
605  }
606  } else { // File-open failure - wait at least 120s before next attempt.
607  edm::LogVerbatim("XrdAdaptorInternal") << "Got failure when trying to open a new source" << std::endl;
608  m_nextActiveSourceCheck.tv_sec += XRD_ADAPTOR_LONG_OPEN_DELAY - XRD_ADAPTOR_SHORT_OPEN_DELAY;
609  }
610 }
611 
612 std::future<IOSize> XrdAdaptor::RequestManager::handle(std::shared_ptr<std::vector<IOPosBuffer>> iolist) {
613  //Use a copy of m_activeSources and m_inactiveSources throughout this function
614  // in order to avoid holding the lock a long time and causing a deadlock.
615  // When the function is over we will update the values of the containers
616  std::vector<std::shared_ptr<Source>> activeSources, inactiveSources;
617  {
618  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
619  activeSources = m_activeSources;
620  inactiveSources = m_inactiveSources;
621  }
622  //Make sure we update changes when we leave the function
623  std::shared_ptr<void *> guard(nullptr, [this, &activeSources, &inactiveSources](void *) {
624  std::lock_guard<std::recursive_mutex> sentry(m_source_mutex);
625  m_activeSources = std::move(activeSources);
626  m_inactiveSources = std::move(inactiveSources);
627  });
628 
629  updateCurrentServer();
630 
631  timespec now;
633 
634  edm::CPUTimer timer;
635  timer.start();
636 
637  if (activeSources.size() == 1) {
638  auto c_ptr = std::make_shared<XrdAdaptor::ClientRequest>(*this, iolist);
639  checkSources(now, c_ptr->getSize(), activeSources, inactiveSources);
640  activeSources[0]->handle(c_ptr);
641  return c_ptr->get_future();
642  }
643  // Make sure active
644  else if (activeSources.empty()) {
646  ex << "XrdAdaptor::RequestManager::handle readv(name='" << m_name << "', flags=0x" << std::hex << m_flags
647  << ", permissions=0" << std::oct << m_perms << std::dec << ") => Source used after fatal exception.";
648  ex.addContext("In XrdAdaptor::RequestManager::handle()");
649  addConnections(ex);
650  throw ex;
651  }
652 
653  assert(iolist.get());
654  auto req1 = std::make_shared<std::vector<IOPosBuffer>>();
655  auto req2 = std::make_shared<std::vector<IOPosBuffer>>();
656  splitClientRequest(*iolist, *req1, *req2, activeSources);
657 
658  checkSources(now, req1->size() + req2->size(), activeSources, inactiveSources);
659  // CheckSources may have removed a source
660  if (activeSources.size() == 1) {
661  auto c_ptr = std::make_shared<XrdAdaptor::ClientRequest>(*this, iolist);
662  activeSources[0]->handle(c_ptr);
663  return c_ptr->get_future();
664  }
665 
666  std::shared_ptr<XrdAdaptor::ClientRequest> c_ptr1, c_ptr2;
667  std::future<IOSize> future1, future2;
668  if (!req1->empty()) {
669  c_ptr1.reset(new XrdAdaptor::ClientRequest(*this, req1));
670  activeSources[0]->handle(c_ptr1);
671  future1 = c_ptr1->get_future();
672  }
673  if (!req2->empty()) {
674  c_ptr2.reset(new XrdAdaptor::ClientRequest(*this, req2));
675  activeSources[1]->handle(c_ptr2);
676  future2 = c_ptr2->get_future();
677  }
678  if (!req1->empty() && !req2->empty()) {
679  std::future<IOSize> task = std::async(
680  std::launch::deferred,
681  [](std::future<IOSize> a, std::future<IOSize> b) {
682  // Wait until *both* results are available. This is essential
683  // as the callback may try referencing the RequestManager. If one
684  // throws an exception (causing the RequestManager to be destroyed by
685  // XrdFile) and the other has a failure, then the recovery code will
686  // reference the destroyed RequestManager.
687  //
688  // Unlike other places where we use shared/weak ptrs to maintain object
689  // lifetime and destruction asynchronously, we *cannot* destroy the request
690  // asynchronously as it is associated with a ROOT buffer. We must wait until we
691  // are guaranteed that XrdCl will not write into the ROOT buffer before we
692  // can return.
693  b.wait();
694  a.wait();
695  return b.get() + a.get();
696  },
697  std::move(future1),
698  std::move(future2));
699  timer.stop();
700  //edm::LogVerbatim("XrdAdaptorInternal") << "Total time to create requests " << static_cast<int>(1000*timer.realTime()) << std::endl;
701  return task;
702  } else if (!req1->empty()) {
703  return future1;
704  } else if (!req2->empty()) {
705  return future2;
706  } else { // Degenerate case - no bytes to read.
707  std::promise<IOSize> p;
708  p.set_value(0);
709  return p.get_future();
710  }
711 }
712 
713 void RequestManager::requestFailure(std::shared_ptr<XrdAdaptor::ClientRequest> c_ptr, XrdCl::Status &c_status) {
714  std::shared_ptr<Source> source_ptr = c_ptr->getCurrentSource();
715 
716  // Fail early for invalid responses - XrdFile has a separate path for handling this.
717  if (c_status.code == XrdCl::errInvalidResponse) {
718  edm::LogWarning("XrdAdaptorInternal") << "Invalid response when reading from " << source_ptr->PrettyID();
720  ex << "XrdAdaptor::RequestManager::requestFailure readv(name='" << m_name << "', flags=0x" << std::hex << m_flags
721  << ", permissions=0" << std::oct << m_perms << std::dec << ", old source=" << source_ptr->PrettyID()
722  << ") => Invalid ReadV response from server";
723  ex.addContext("In XrdAdaptor::RequestManager::requestFailure()");
724  addConnections(ex);
725  throw ex;
726  }
727  edm::LogWarning("XrdAdaptorInternal") << "Request failure when reading from " << source_ptr->PrettyID();
728 
729  // Note that we do not delete the Source itself. That is because this
730  // function may be called from within XrdCl::ResponseHandler::HandleResponseWithHosts
731  // In such a case, if you close a file in the handler, it will deadlock
732  m_disabledSourceStrings.insert(source_ptr->ID());
733  m_disabledExcludeStrings.insert(source_ptr->ExcludeID());
734  m_disabledSources.insert(source_ptr);
735 
736  std::unique_lock<std::recursive_mutex> sentry(m_source_mutex);
737  if ((!m_activeSources.empty()) && (m_activeSources[0].get() == source_ptr.get())) {
738  auto oldSources = m_activeSources;
739  m_activeSources.erase(m_activeSources.begin());
740  reportSiteChange(oldSources, m_activeSources);
741  } else if ((m_activeSources.size() > 1) && (m_activeSources[1].get() == source_ptr.get())) {
742  auto oldSources = m_activeSources;
743  m_activeSources.erase(m_activeSources.begin() + 1);
744  reportSiteChange(oldSources, m_activeSources);
745  }
746  std::shared_ptr<Source> new_source;
747  if (m_activeSources.empty()) {
748  std::shared_future<std::shared_ptr<Source>> future = m_open_handler->open();
749  timespec now;
752  // Note we only wait for 180 seconds here. This is because we've already failed
753  // once and the likelihood the program has some inconsistent state is decent.
754  // We'd much rather fail hard than deadlock!
755  sentry.unlock();
756  std::future_status status = future.wait_for(std::chrono::seconds(m_timeout + 10));
759  ex << "XrdAdaptor::RequestManager::requestFailure Open(name='" << m_name << "', flags=0x" << std::hex << m_flags
760  << ", permissions=0" << std::oct << m_perms << std::dec << ", old source=" << source_ptr->PrettyID()
761  << ") => timeout when waiting for file open";
762  ex.addContext("In XrdAdaptor::RequestManager::requestFailure()");
763  addConnections(ex);
764  throw ex;
765  } else {
766  try {
767  new_source = future.get();
768  } catch (edm::Exception &ex) {
769  ex.addContext("Handling XrdAdaptor::RequestManager::requestFailure()");
770  ex.addAdditionalInfo("Original failed source is " + source_ptr->PrettyID());
771  throw;
772  }
773  }
774 
775  if (std::find(m_disabledSourceStrings.begin(), m_disabledSourceStrings.end(), new_source->ID()) !=
776  m_disabledSourceStrings.end()) {
777  // The server gave us back a data node we requested excluded. Fatal!
779  ex << "XrdAdaptor::RequestManager::requestFailure Open(name='" << m_name << "', flags=0x" << std::hex << m_flags
780  << ", permissions=0" << std::oct << m_perms << std::dec << ", old source=" << source_ptr->PrettyID()
781  << ", new source=" << new_source->PrettyID() << ") => Xrootd server returned an excluded source";
782  ex.addContext("In XrdAdaptor::RequestManager::requestFailure()");
783  addConnections(ex);
784  throw ex;
785  }
786  sentry.lock();
787 
788  auto oldSources = m_activeSources;
789  m_activeSources.push_back(new_source);
790  reportSiteChange(oldSources, m_activeSources);
791  } else {
792  new_source = m_activeSources[0];
793  }
794  new_source->handle(c_ptr);
795 }
796 
797 static void consumeChunkFront(size_t &front,
798  std::vector<IOPosBuffer> &input,
799  std::vector<IOPosBuffer> &output,
800  IOSize chunksize) {
801  while ((chunksize > 0) && (front < input.size()) && (output.size() <= XRD_ADAPTOR_CHUNK_THRESHOLD)) {
802  IOPosBuffer &io = input[front];
803  IOPosBuffer &outio = output.back();
804  if (io.size() > chunksize) {
805  IOSize consumed;
806  if (!output.empty() && (outio.size() < XRD_CL_MAX_CHUNK) &&
807  (outio.offset() + static_cast<IOOffset>(outio.size()) == io.offset())) {
808  if (outio.size() + chunksize > XRD_CL_MAX_CHUNK) {
809  consumed = (XRD_CL_MAX_CHUNK - outio.size());
810  outio.set_size(XRD_CL_MAX_CHUNK);
811  } else {
812  consumed = chunksize;
813  outio.set_size(outio.size() + consumed);
814  }
815  } else {
816  consumed = chunksize;
817  output.emplace_back(IOPosBuffer(io.offset(), io.data(), chunksize));
818  }
819  chunksize -= consumed;
820  IOSize newsize = io.size() - consumed;
821  IOOffset newoffset = io.offset() + consumed;
822  void *newdata = static_cast<char *>(io.data()) + consumed;
823  io.set_offset(newoffset);
824  io.set_data(newdata);
825  io.set_size(newsize);
826  } else if (io.size() == 0) {
827  front++;
828  } else {
829  output.push_back(io);
830  chunksize -= io.size();
831  front++;
832  }
833  }
834 }
835 
836 static void consumeChunkBack(size_t front,
837  std::vector<IOPosBuffer> &input,
838  std::vector<IOPosBuffer> &output,
839  IOSize chunksize) {
840  while ((chunksize > 0) && (front < input.size()) && (output.size() <= XRD_ADAPTOR_CHUNK_THRESHOLD)) {
841  IOPosBuffer &io = input.back();
842  IOPosBuffer &outio = output.back();
843  if (io.size() > chunksize) {
844  IOSize consumed;
845  if (!output.empty() && (outio.size() < XRD_CL_MAX_CHUNK) &&
846  (outio.offset() + static_cast<IOOffset>(outio.size()) == io.offset())) {
847  if (outio.size() + chunksize > XRD_CL_MAX_CHUNK) {
848  consumed = (XRD_CL_MAX_CHUNK - outio.size());
849  outio.set_size(XRD_CL_MAX_CHUNK);
850  } else {
851  consumed = chunksize;
852  outio.set_size(outio.size() + consumed);
853  }
854  } else {
855  consumed = chunksize;
856  output.emplace_back(IOPosBuffer(io.offset(), io.data(), chunksize));
857  }
858  chunksize -= consumed;
859  IOSize newsize = io.size() - consumed;
860  IOOffset newoffset = io.offset() + consumed;
861  void *newdata = static_cast<char *>(io.data()) + consumed;
862  io.set_offset(newoffset);
863  io.set_data(newdata);
864  io.set_size(newsize);
865  } else if (io.size() == 0) {
866  input.pop_back();
867  } else {
868  output.push_back(io);
869  chunksize -= io.size();
870  input.pop_back();
871  }
872  }
873 }
874 
875 static IOSize validateList(const std::vector<IOPosBuffer> req) {
876  IOSize total = 0;
877  off_t last_offset = -1;
878  for (const auto &it : req) {
879  total += it.size();
880  assert(it.offset() > last_offset);
881  last_offset = it.offset();
882  assert(it.size() <= XRD_CL_MAX_CHUNK);
883  assert(it.offset() < 0x1ffffffffff);
884  }
885  assert(req.size() <= 1024);
886  return total;
887 }
888 
889 void XrdAdaptor::RequestManager::splitClientRequest(const std::vector<IOPosBuffer> &iolist,
890  std::vector<IOPosBuffer> &req1,
891  std::vector<IOPosBuffer> &req2,
892  std::vector<std::shared_ptr<Source>> const &activeSources) const {
893  if (iolist.empty())
894  return;
895  std::vector<IOPosBuffer> tmp_iolist(iolist.begin(), iolist.end());
896  req1.reserve(iolist.size() / 2 + 1);
897  req2.reserve(iolist.size() / 2 + 1);
898  size_t front = 0;
899 
900  // The quality of both is increased by 5 to prevent strange effects if quality is 0 for one source.
901  float q1 = static_cast<float>(activeSources[0]->getQuality()) + 5;
902  float q2 = static_cast<float>(activeSources[1]->getQuality()) + 5;
903  IOSize chunk1, chunk2;
904  // Make sure the chunk size is at least 1024; little point to reads less than that size.
905  chunk1 = std::max(static_cast<IOSize>(static_cast<float>(XRD_CL_MAX_CHUNK) * (q2 * q2 / (q1 * q1 + q2 * q2))),
906  static_cast<IOSize>(1024));
907  chunk2 = std::max(static_cast<IOSize>(static_cast<float>(XRD_CL_MAX_CHUNK) * (q1 * q1 / (q1 * q1 + q2 * q2))),
908  static_cast<IOSize>(1024));
909 
910  IOSize size_orig = 0;
911  for (const auto &it : iolist)
912  size_orig += it.size();
913 
914  while (tmp_iolist.size() - front > 0) {
915  if ((req1.size() >= XRD_ADAPTOR_CHUNK_THRESHOLD) &&
916  (req2.size() >=
917  XRD_ADAPTOR_CHUNK_THRESHOLD)) { // The XrdFile::readv implementation should guarantee that no more than approximately 1024 chunks
918  // are passed to the request manager. However, because we have a max chunk size, we increase
919  // the total number slightly. Theoretically, it's possible an individual readv of total size >2GB where
920  // each individual chunk is >1MB could result in this firing. However, within the context of CMSSW,
921  // this cannot happen (ROOT uses readv for TTreeCache; TTreeCache size is 20MB).
923  ex << "XrdAdaptor::RequestManager::splitClientRequest(name='" << m_name << "', flags=0x" << std::hex << m_flags
924  << ", permissions=0" << std::oct << m_perms << std::dec
925  << ") => Unable to split request between active servers. This is an unexpected internal error and should be "
926  "reported to CMSSW developers.";
927  ex.addContext("In XrdAdaptor::RequestManager::requestFailure()");
928  addConnections(ex);
929  std::stringstream ss;
930  ss << "Original request size " << iolist.size() << "(" << size_orig << " bytes)";
931  ex.addAdditionalInfo(ss.str());
932  std::stringstream ss2;
933  ss2 << "Quality source 1 " << q1 - 5 << ", quality source 2: " << q2 - 5;
934  ex.addAdditionalInfo(ss2.str());
935  throw ex;
936  }
937  if (req1.size() < XRD_ADAPTOR_CHUNK_THRESHOLD) {
938  consumeChunkFront(front, tmp_iolist, req1, chunk1);
939  }
940  if (req2.size() < XRD_ADAPTOR_CHUNK_THRESHOLD) {
941  consumeChunkBack(front, tmp_iolist, req2, chunk2);
942  }
943  }
944  std::sort(req1.begin(), req1.end(), [](const IOPosBuffer &left, const IOPosBuffer &right) {
945  return left.offset() < right.offset();
946  });
947  std::sort(req2.begin(), req2.end(), [](const IOPosBuffer &left, const IOPosBuffer &right) {
948  return left.offset() < right.offset();
949  });
950 
951  IOSize size1 = validateList(req1);
952  IOSize size2 = validateList(req2);
953 
954  assert(size_orig == size1 + size2);
955 
956  edm::LogVerbatim("XrdAdaptorInternal") << "Original request size " << iolist.size() << " (" << size_orig
957  << " bytes) split into requests size " << req1.size() << " (" << size1
958  << " bytes) and " << req2.size() << " (" << size2 << " bytes)" << std::endl;
959 }
960 
961 XrdAdaptor::RequestManager::OpenHandler::OpenHandler(std::weak_ptr<RequestManager> manager) : m_manager(manager) {}
962 
963 // Cannot use ~OpenHandler=default as XrdCl::File is not fully
964 // defined in the header.
966 
968  XrdCl::AnyObject *,
969  XrdCl::HostList *hostList_ptr) {
970  // Make sure we get rid of the strong self-reference when the callback finishes.
971  std::shared_ptr<OpenHandler> self = m_self;
972  m_self.reset();
973 
974  // NOTE: as in XrdCl::File (synchronous), we ignore the response object.
975  // Make sure that we set m_outstanding_open to false on exit from this function.
976  // NOTE: we need to pass non-nullptr to unique_ptr in order for the guard to run
977  std::unique_ptr<OpenHandler, std::function<void(OpenHandler *)>> outstanding_guard(
978  this, [&](OpenHandler *) { m_outstanding_open = false; });
979 
980  std::shared_ptr<Source> source;
981  std::unique_ptr<XrdCl::XRootDStatus> status(status_ptr);
982  std::unique_ptr<XrdCl::HostList> hostList(hostList_ptr);
983 
984  auto manager = m_manager.lock();
985  // Manager object has already been deleted. Cleanup the
986  // response objects, remove our self-reference, and ignore the response.
987  if (!manager) {
988  return;
989  }
990  //if we need to delete the File object we must do it outside
991  // of the lock to avoid a potential deadlock
992  std::unique_ptr<XrdCl::File> releaseFile;
993  {
994  std::lock_guard<std::recursive_mutex> sentry(m_mutex);
995 
996  if (status->IsOK()) {
997  SendMonitoringInfo(*m_file);
998  timespec now;
1000 
1001  std::string excludeString;
1002  Source::determineHostExcludeString(*m_file, hostList.get(), excludeString);
1003 
1004  source.reset(new Source(now, std::move(m_file), excludeString));
1005  m_promise.set_value(source);
1006  } else {
1007  releaseFile = std::move(m_file);
1009  ex << "XrdCl::File::Open(name='" << manager->m_name << "', flags=0x" << std::hex << manager->m_flags
1010  << ", permissions=0" << std::oct << manager->m_perms << std::dec << ") => error '" << status->ToStr()
1011  << "' (errno=" << status->errNo << ", code=" << status->code << ")";
1012  ex.addContext("In XrdAdaptor::RequestManager::OpenHandler::HandleResponseWithHosts()");
1013  manager->addConnections(ex);
1014 
1015  m_promise.set_exception(std::make_exception_ptr(ex));
1016  }
1017  }
1018  manager->handleOpen(*status, source);
1019 }
1020 
1022  std::lock_guard<std::recursive_mutex> sentry(m_mutex);
1023 
1024  if (!m_file.get()) {
1025  return "(no open in progress)";
1026  }
1027  std::string dataServer;
1028  m_file->GetProperty("DataServer", dataServer);
1029  if (dataServer.empty()) {
1030  return "(unknown source)";
1031  }
1032  return dataServer;
1033 }
1034 
1035 std::shared_future<std::shared_ptr<Source>> XrdAdaptor::RequestManager::OpenHandler::open() {
1036  auto manager_ptr = m_manager.lock();
1037  if (!manager_ptr) {
1039  ex << "XrdCl::File::Open() =>"
1040  << " error: OpenHandler called within an invalid RequestManager context."
1041  << " This is a logic error and should be reported to the CMSSW developers.";
1042  ex.addContext("Calling XrdAdaptor::RequestManager::OpenHandler::open()");
1043  throw ex;
1044  }
1045  RequestManager &manager = *manager_ptr;
1046  auto self_ptr = m_self_weak.lock();
1047  if (!self_ptr) {
1049  ex << "XrdCl::File::Open() => error: "
1050  << "OpenHandler called after it was deleted. This is a logic error "
1051  << "and should be reported to the CMSSW developers.";
1052  ex.addContext("Calling XrdAdapter::RequestManager::OpenHandler::open()");
1053  throw ex;
1054  }
1055 
1056  // NOTE NOTE: we look at this variable *without* the lock. This means the method
1057  // is not thread-safe; the caller is responsible to verify it is not called from
1058  // multiple threads simultaneously.
1059  //
1060  // This is done because ::open may be called from a Xrootd callback; if we
1061  // tried to hold m_mutex here, this object's callback may also be active, hold m_mutex,
1062  // and make a call into xrootd (when it invokes m_file.reset()). Hence, our callback
1063  // holds our mutex and attempts to grab an Xrootd mutex; RequestManager::requestFailure holds
1064  // an Xrootd mutex and tries to hold m_mutex. This is a classic deadlock.
1065  if (m_outstanding_open) {
1066  return m_shared_future;
1067  }
1068  std::lock_guard<std::recursive_mutex> sentry(m_mutex);
1069  std::promise<std::shared_ptr<Source>> new_promise;
1070  m_promise.swap(new_promise);
1071  m_shared_future = m_promise.get_future().share();
1072 
1073  auto opaque = manager.prepareOpaqueString();
1074  std::string new_name = manager.m_name + ((manager.m_name.find("?") == manager.m_name.npos) ? "?" : "&") + opaque;
1075  edm::LogVerbatim("XrdAdaptorInternal") << "Trying to open URL: " << new_name;
1076  m_file.reset(new XrdCl::File());
1077  m_outstanding_open = true;
1078 
1079  // Always make sure we release m_file and set m_outstanding_open to false on error.
1080  std::unique_ptr<OpenHandler, std::function<void(OpenHandler *)>> exit_guard(this, [&](OpenHandler *) {
1081  m_outstanding_open = false;
1082  m_file.reset();
1083  });
1084 
1085  XrdCl::XRootDStatus status;
1086  if (!(status = m_file->Open(new_name, manager.m_flags, manager.m_perms, this)).IsOK()) {
1088  ex << "XrdCl::File::Open(name='" << new_name << "', flags=0x" << std::hex << manager.m_flags << ", permissions=0"
1089  << std::oct << manager.m_perms << std::dec << ") => error '" << status.ToStr() << "' (errno=" << status.errNo
1090  << ", code=" << status.code << ")";
1091  ex.addContext("Calling XrdAdaptor::RequestManager::OpenHandler::open()");
1092  manager.addConnections(ex);
1093  throw ex;
1094  }
1095  exit_guard.release();
1096  // Have a strong self-reference for as long as the callback is in-progress.
1097  m_self = self_ptr;
1098  return m_shared_future;
1099 }
IOPosBuffer::set_offset
void set_offset(IOOffset new_offset)
Definition: IOPosBuffer.h:48
Likely.h
change_name.diff
diff
Definition: change_name.py:13
XRD_ADAPTOR_SHORT_OPEN_DELAY
#define XRD_ADAPTOR_SHORT_OPEN_DELAY
Definition: XrdRequestManager.cc:25
XrdAdaptor::RequestManager::m_flags
XrdCl::OpenFlags::Flags m_flags
Definition: XrdRequestManager.h:226
XrdAdaptor::Source::determineHostExcludeString
static void determineHostExcludeString(XrdCl::File &file, const XrdCl::HostList *hostList, std::string &exclude)
Definition: XrdSource.cc:283
XrdAdaptor::RequestManager::getActiveFile
std::shared_ptr< XrdCl::File > getActiveFile() const
Definition: XrdRequestManager.cc:445
XrdAdaptor::RequestManager::queueUpdateCurrentServer
void queueUpdateCurrentServer(const std::string &)
Definition: XrdRequestManager.cc:251
relmon_authenticated_wget.url
url
Definition: relmon_authenticated_wget.py:22
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
XrdAdaptor::RequestManager::m_generator
std::mt19937 m_generator
Definition: XrdRequestManager.h:230
XrdStatistics.h
funct::false
false
Definition: Factorize.h:34
HcalTopologyMode::Mode
Mode
Definition: HcalTopologyMode.h:26
XrdAdaptor::RequestManager::m_nextActiveSourceCheck
timespec m_nextActiveSourceCheck
Definition: XrdRequestManager.h:222
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
XrdAdaptor::RequestManager::addConnections
void addConnections(cms::Exception &) const
Definition: XrdRequestManager.cc:481
XRD_ADAPTOR_SOURCE_QUALITY_FUDGE
#define XRD_ADAPTOR_SOURCE_QUALITY_FUDGE
Definition: XrdRequestManager.cc:35
XrdAdaptor::RequestManager::m_disabledExcludeStrings
tbb::concurrent_unordered_set< std::string > m_disabledExcludeStrings
Definition: XrdRequestManager.h:210
edm::errors::LogicError
Definition: EDMException.h:37
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
mps_update.status
status
Definition: mps_update.py:69
XrdAdaptor::RequestManager::m_inactiveSources
std::vector< std::shared_ptr< Source > > m_inactiveSources
Definition: XrdRequestManager.h:207
XrdAdaptor::RequestManager::OpenHandler
Definition: XrdRequestManager.h:235
XrdAdaptor::RequestManager::m_open_handler
std::shared_ptr< OpenHandler > m_open_handler
Definition: XrdRequestManager.h:289
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
XrdAdaptor::RequestManager::getDisabledSourceNames
void getDisabledSourceNames(std::vector< std::string > &sources) const
Definition: XrdRequestManager.cc:474
edm::CPUTimer
Definition: CPUTimer.h:37
edm::LogInfo
Definition: MessageLogger.h:254
XrdAdaptor::RequestManager::m_activeSources
std::vector< std::shared_ptr< Source > > m_activeSources
Definition: XrdRequestManager.h:206
XrdAdaptor::RequestManager::OpenHandler::open
std::shared_future< std::shared_ptr< Source > > open()
Definition: XrdRequestManager.cc:1035
XRD_ADAPTOR_CHUNK_THRESHOLD
#define XRD_ADAPTOR_CHUNK_THRESHOLD
Definition: XrdRequestManager.cc:38
XrdAdaptor::RequestManager::m_perms
XrdCl::Access::Mode m_perms
Definition: XrdRequestManager.h:227
pileupDistInMC.oldList
oldList
Definition: pileupDistInMC.py:39
IOPosBuffer::set_data
void set_data(void *new_buffer)
Definition: IOPosBuffer.h:51
cms::cuda::assert
assert(be >=bs)
CalibrationSummaryClient_cfi.sources
sources
Definition: CalibrationSummaryClient_cfi.py:23
XrdAdaptor::RequestManager::m_disabledSources
tbb::concurrent_unordered_set< std::shared_ptr< Source >, SourceHash > m_disabledSources
Definition: XrdRequestManager.h:211
indexGen.s2
s2
Definition: indexGen.py:107
XrdAdaptor::RequestManager::m_serverToAdvertise
std::atomic< std::string * > m_serverToAdvertise
Definition: XrdRequestManager.h:215
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
btagGenBb_cfi.Status
Status
Definition: btagGenBb_cfi.py:4
training_settings.idx
idx
Definition: training_settings.py:16
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
XrdAdaptor::RequestManager::updateCurrentServer
void updateCurrentServer()
Definition: XrdRequestManager.cc:234
edm::errors::FileOpenError
Definition: EDMException.h:49
GET_CLOCK_MONOTONIC
#define GET_CLOCK_MONOTONIC(ts)
Definition: XrdRequestManager.cc:54
XrdAdaptor::RequestManager::OpenHandler::HandleResponseWithHosts
void HandleResponseWithHosts(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response, XrdCl::HostList *hostList) override
Definition: XrdRequestManager.cc:967
edm::Exception
Definition: EDMException.h:77
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
EDMException.h
SendMonitoringInfoHandler
Definition: XrdRequestManager.cc:69
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
fileCollector.now
now
Definition: fileCollector.py:207
consumeChunkBack
static void consumeChunkBack(size_t front, std::vector< IOPosBuffer > &input, std::vector< IOPosBuffer > &output, IOSize chunksize)
Definition: XrdRequestManager.cc:836
XrdAdaptor::RequestManager::getPrettyActiveSourceNames
void getPrettyActiveSourceNames(std::vector< std::string > &sources) const
Definition: XrdRequestManager.cc:466
XrdAdaptor::RequestManager::m_lastSourceCheck
timespec m_lastSourceCheck
Definition: XrdRequestManager.h:217
alignCSCRings.s
s
Definition: alignCSCRings.py:92
XrdAdaptor::RequestManager::pickSingleSource
std::shared_ptr< Source > pickSingleSource()
Definition: XrdRequestManager.cc:494
XrdAdaptor::RequestManager::compareSources
bool compareSources(const timespec &now, unsigned a, unsigned b, std::vector< std::shared_ptr< Source >> &activeSources, std::vector< std::shared_ptr< Source >> &inactiveSources) const
Definition: XrdRequestManager.cc:311
XrdAdaptor::RequestManager::reportSiteChange
void reportSiteChange(std::vector< std::shared_ptr< Source >> const &iOld, std::vector< std::shared_ptr< Source >> const &iNew, std::string orig_site=std::string{}) const
Definition: XrdRequestManager.cc:278
Service.h
seconds
double seconds()
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
source
static const std::string source
Definition: EdmProvDump.cc:47
XrdAdaptor::RequestManager::initialize
void initialize(std::weak_ptr< RequestManager > selfref)
Definition: XrdRequestManager.cc:118
IOPosBuffer::data
void * data(void) const
Definition: IOPosBuffer.h:42
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
XrdAdaptor::Source::getDomain
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:241
XRD_ADAPTOR_LONG_OPEN_DELAY
#define XRD_ADAPTOR_LONG_OPEN_DELAY
Definition: XrdRequestManager.cc:34
edm::CPUTimer::start
void start()
Definition: CPUTimer.cc:68
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
XrdRequestManager.h
b
double b
Definition: hdecay.h:118
q2
double q2[4]
Definition: TauolaWrapper.h:88
validateList
static IOSize validateList(const std::vector< IOPosBuffer > req)
Definition: XrdRequestManager.cc:875
XRD_CL_MAX_CHUNK
#define XRD_CL_MAX_CHUNK
Definition: XrdRequestManager.cc:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
XrdAdaptor::RequestManager::getActiveSourceNames
void getActiveSourceNames(std::vector< std::string > &sources) const
Definition: XrdRequestManager.cc:458
XrdAdaptor::RequestManager::m_name
const std::string m_name
Definition: XrdRequestManager.h:225
web.browse_db.env
env
Definition: browse_db.py:18
edm::LogWarning
Definition: MessageLogger.h:141
XrdAdaptor::RequestManager::m_nextInitialSourceToggle
bool m_nextInitialSourceToggle
Definition: XrdRequestManager.h:220
IOPosBuffer::set_size
void set_size(IOSize new_size)
Definition: IOPosBuffer.h:54
XrdAdaptor::Source::isDCachePool
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:251
q1
double q1[4]
Definition: TauolaWrapper.h:87
a
double a
Definition: hdecay.h:119
XrdAdaptor::RequestManager::splitClientRequest
void splitClientRequest(const std::vector< IOPosBuffer > &iolist, std::vector< IOPosBuffer > &req1, std::vector< IOPosBuffer > &req2, std::vector< std::shared_ptr< Source >> const &activeSources) const
Definition: XrdRequestManager.cc:889
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
cms::Exception::addAdditionalInfo
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
XrdAdaptor::RequestManager::handle
std::future< IOSize > handle(void *into, IOSize size, IOOffset off)
Definition: XrdRequestManager.h:54
mps_check.timeout
int timeout
Definition: mps_check.py:53
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
XrdAdaptor::Source::getXrootdSiteFromURL
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:321
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
thread_safety_macros.h
XrdAdaptor::RequestManager::m_distribution
std::uniform_real_distribution< float > m_distribution
Definition: XrdRequestManager.h:231
edm::Service
Definition: Service.h:30
XrdAdaptor::RequestManager::m_source_mutex
std::recursive_mutex m_source_mutex
Definition: XrdRequestManager.h:228
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
CalibrationSummaryClient_cfi.activeSources
activeSources
Definition: CalibrationSummaryClient_cfi.py:11
edm::LogVerbatim
Definition: MessageLogger.h:297
StatisticsSenderService.h
edm::CPUTimer::stop
Times stop()
Definition: CPUTimer.cc:87
XrdAdaptor::RequestManager::checkSources
void checkSources(timespec &now, IOSize requestSize, std::vector< std::shared_ptr< Source >> &activeSources, std::vector< std::shared_ptr< Source >> &inactiveSources)
Definition: XrdRequestManager.cc:293
get
#define get
XRD_ADAPTOR_OPEN_PROBE_PERCENT
#define XRD_ADAPTOR_OPEN_PROBE_PERCENT
Definition: XrdRequestManager.cc:33
nullHandler
SendMonitoringInfoHandler nullHandler
Definition: XrdRequestManager.cc:83
alignCSCRings.r
r
Definition: alignCSCRings.py:93
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
VtxSmearedBeamProfile_cfi.File
File
Definition: VtxSmearedBeamProfile_cfi.py:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
XrdAdaptor::RequestManager::handleOpen
virtual void handleOpen(XrdCl::XRootDStatus &status, std::shared_ptr< Source >)
Definition: XrdRequestManager.cc:574
IOPosBuffer::size
IOSize size(void) const
Definition: IOPosBuffer.h:45
edm::storage::StatisticsSenderService::getJobID
static const char * getJobID()
Definition: StatisticsSenderService.cc:145
cms::Exception::clearContext
void clearContext()
Definition: Exception.cc:161
XrdAdaptor::RequestManager::OpenHandler::getInstance
static std::shared_ptr< OpenHandler > getInstance(std::weak_ptr< RequestManager > manager)
Definition: XrdRequestManager.h:237
IOPosBuffer::offset
IOOffset offset(void) const
Definition: IOPosBuffer.h:39
XrdAdaptor::RequestManager::RequestManager
RequestManager(const std::string &filename, XrdCl::OpenFlags::Flags flags, XrdCl::Access::Mode perms)
Definition: XrdRequestManager.cc:108
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
XrdAdaptor::RequestManager::OpenHandler::~OpenHandler
~OpenHandler() override
Definition: XrdRequestManager.cc:965
SendMonitoringInfo
static void SendMonitoringInfo(XrdCl::File &file)
Definition: XrdRequestManager.cc:85
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:29
XrdAdaptor::RequestManager::prepareOpaqueString
std::string prepareOpaqueString() const
Definition: XrdRequestManager.cc:547
dqmMemoryStats.total
total
Definition: dqmMemoryStats.py:152
IOPosBuffer
Definition: IOPosBuffer.h:7
consumeChunkFront
static void consumeChunkFront(size_t &front, std::vector< IOPosBuffer > &input, std::vector< IOPosBuffer > &output, IOSize chunksize)
Definition: XrdRequestManager.cc:797
XrdAdaptor::XrootdException
Definition: XrdRequestManager.h:32
XrdAdaptor::RequestManager::m_disabledSourceStrings
tbb::concurrent_unordered_set< std::string > m_disabledSourceStrings
Definition: XrdRequestManager.h:209
hcal_runs.URL
URL
Definition: hcal_runs.py:4
cms::Exception
Definition: Exception.h:70
CPUTimer.h
XrdAdaptor::RequestManager::m_timeout
int m_timeout
Definition: XrdRequestManager.h:218
XrdAdaptor::RequestManager::OpenHandler::current_source
std::string current_source()
Definition: XrdRequestManager.cc:1021
XrdAdaptor::RequestManager
Definition: XrdRequestManager.h:45
IOSize
size_t IOSize
Definition: IOTypes.h:14
cms::Exception::clearMessage
void clearMessage()
Definition: Exception.cc:159
edm::errors::FileReadError
Definition: EDMException.h:50
XrdAdaptor::Source::getHostname
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:214
HLT_2018_cff.flags
flags
Definition: HLT_2018_cff.py:11758
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::storage::StatisticsSenderService::setCurrentServer
void setCurrentServer(const std::string &servername)
Definition: StatisticsSenderService.cc:151
SendMonitoringInfoHandler::HandleResponse
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequestManager.cc:70
XrdAdaptor
Definition: QualityMetric.h:15
cms::Exception::clearAdditionalInfo
void clearAdditionalInfo()
Definition: Exception.cc:163
XrdAdaptor::RequestManager::OpenHandler::OpenHandler
OpenHandler(std::weak_ptr< RequestManager > manager)
Definition: XrdRequestManager.cc:961
XrdAdaptor::RequestManager::checkSourcesImpl
void checkSourcesImpl(timespec &now, IOSize requestSize, std::vector< std::shared_ptr< Source >> &activeSources, std::vector< std::shared_ptr< Source >> &inactiveSources)
Definition: XrdRequestManager.cc:339
timeDiffMS
long long timeDiffMS(const timespec &a, const timespec &b)
Definition: XrdRequestManager.cc:59
XrdAdaptor::RequestManager::requestFailure
void requestFailure(std::shared_ptr< XrdAdaptor::ClientRequest > c_ptr, XrdCl::Status &c_status)
Definition: XrdRequestManager.cc:713
XrdAdaptor::ClientRequest
Definition: XrdRequest.h:23
CollectionTags_cfi.Source
Source
Definition: CollectionTags_cfi.py:11