CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
XrdAdaptor::Source Class Reference

#include <XrdSource.h>

Inheritance diagram for XrdAdaptor::Source:

Public Member Functions

const std::string & ExcludeID () const
 
std::shared_ptr< XrdCl::File > getFileHandle ()
 
struct timespec getLastDowngrade () const
 
unsigned getQuality ()
 
void handle (std::shared_ptr< ClientRequest >)
 
void handle (RequestList &)
 
const std::string & ID () const
 
const std::string & PrettyID () const
 
void setLastDowngrade (struct timespec now)
 
const std::string & Site () const
 
 Source (timespec now, std::unique_ptr< XrdCl::File > fileHandle, const std::string &exclude)
 
 ~Source ()
 

Static Public Member Functions

static void determineHostExcludeString (XrdCl::File &file, const XrdCl::HostList *hostList, std::string &exclude)
 
static bool getDomain (const std::string &host, std::string &domain)
 
static bool getHostname (const std::string &id, std::string &hostname)
 
static bool getXrootdSite (XrdCl::File &file, std::string &site)
 
static bool getXrootdSiteFromURL (std::string url, std::string &site)
 
static bool isDCachePool (XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
 
static bool isDCachePool (const std::string &url)
 

Private Member Functions

std::shared_ptr< XrdCl::File const > fh () const
 
std::shared_ptr< XrdCl::File > & fh ()
 
void requestCallback ()
 
void setXrootdSite ()
 
std::shared_ptr< XrdSiteStatistics const > stats () const
 
std::shared_ptr< XrdSiteStatistics > & stats ()
 

Private Attributes

std::string m_exclude
 
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
 
std::string m_id
 
struct timespec m_lastDowngrade
 
std::string m_prettyid
 
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
 
std::string m_site
 
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
 

Detailed Description

Definition at line 25 of file XrdSource.h.

Constructor & Destructor Documentation

Source::Source ( timespec  now,
std::unique_ptr< XrdCl::File >  fileHandle,
const std::string &  exclude 
)

Definition at line 190 of file XrdSource.cc.

References fh(), g_delayCount, edm::propagate_const< T >::get(), XrdAdaptor::QualityMetricFactory::get(), getDomain(), XrdAdaptor::XrdSiteStatisticsInformation::getInstance(), m_exclude, m_fh, m_id, m_prettyid, m_qm, m_site, m_stats, eostools::move(), cmsPerfSuiteHarvest::now, setXrootdSite(), and AlCaHLTBitMon_QueryRunRegistry::string.

191  : m_lastDowngrade({0, 0}),
192  m_id("(unknown)"),
193  m_exclude(exclude),
194  m_fh(std::move(fh)),
195  m_stats(nullptr)
196 #ifdef XRD_FAKE_SLOW
197  , m_slow(++g_delayCount % XRD_SLOW_RATE == 0)
198  //, m_slow(++g_delayCount >= XRD_SLOW_RATE)
199  //, m_slow(true)
200 #endif
201 {
202  if (m_fh.get())
203  {
204  if (!m_fh->GetProperty("DataServer", m_id))
205  {
206  edm::LogWarning("XrdFileWarning")
207  << "Source::Source() failed to determine data server name.'";
208  }
209  if (m_exclude.empty()) {m_exclude = m_id;}
210  }
212  m_prettyid = m_id + " (unknown site)";
213  std::string domain_id;
214  if (getDomain(m_id, domain_id)) {m_site = domain_id;}
215  else {m_site = "Unknown (" + m_id + ")";}
216  setXrootdSite();
217  assert(m_qm.get());
218  assert(m_fh.get());
220  if (statsService)
221  {
222  m_stats = statsService->getStatisticsForSite(m_site);
223  }
224 }
std::string m_id
Definition: XrdSource.h:75
std::atomic< int > g_delayCount
Definition: XrdSource.cc:30
std::string m_exclude
Definition: XrdSource.h:78
struct timespec m_lastDowngrade
Definition: XrdSource.h:74
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:82
std::string m_site
Definition: XrdSource.h:77
static std::unique_ptr< QualityMetricSource > get(timespec now, const std::string &id)
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:79
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:255
static XrdSiteStatisticsInformation * getInstance()
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:69
element_type const * get() const
std::string m_prettyid
Definition: XrdSource.h:76
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:81
def move(src, dest)
Definition: eostools.py:511
Source::~Source ( )

Definition at line 393 of file XrdSource.cc.

References fh(), m_id, and m_site.

394 {
395  new DelayedClose(fh(), m_id, m_site);
396 }
std::string m_id
Definition: XrdSource.h:75
std::string m_site
Definition: XrdSource.h:77
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:69

Member Function Documentation

void Source::determineHostExcludeString ( XrdCl::File &  file,
const XrdCl::HostList *  hostList,
std::string &  exclude 
)
static

Definition at line 307 of file XrdSource.cc.

References info(), isDCachePool(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by XrdAdaptor::RequestManager::OpenHandler::HandleResponseWithHosts(), and XrdAdaptor::RequestManager::initialize().

308 {
309  // Detect a dCache pool and, if we are in the federation context, give a custom
310  // exclude parameter.
311  // We assume this is a federation context if there's at least a regional, dCache door,
312  // and dCache pool server (so, more than 2 servers!).
313 
314  exclude = "";
315  if (hostList && (hostList->size() > 3) && isDCachePool(file, hostList))
316  {
317  const XrdCl::HostInfo &info = (*hostList)[hostList->size()-3];
318  exclude = info.url.GetHostName();
319  std::string lastUrl; file.GetProperty("LastURL", lastUrl);
320  edm::LogVerbatim("XrdAdaptorInternal") << "Changing exclude list for URL " << lastUrl << " to " << exclude;
321  }
322 }
static const TGPicture * info(bool iBackgroundIsBlack)
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:266
const std::string& XrdAdaptor::Source::ExcludeID ( ) const
inline

Definition at line 41 of file XrdSource.h.

41 {return m_exclude;}
std::string m_exclude
Definition: XrdSource.h:78
std::shared_ptr<XrdCl::File const> XrdAdaptor::Source::fh ( ) const
inlineprivate

Definition at line 69 of file XrdSource.h.

References edm::get_underlying_safe().

Referenced by getFileHandle(), Source(), and ~Source().

69 {return get_underlying_safe(m_fh);}
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:79
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::shared_ptr<XrdCl::File>& XrdAdaptor::Source::fh ( )
inlineprivate

Definition at line 70 of file XrdSource.h.

References edm::get_underlying_safe().

70 {return get_underlying_safe(m_fh);}
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:79
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
bool Source::getDomain ( const std::string &  host,
std::string &  domain 
)
static

Definition at line 255 of file XrdSource.cc.

References getHostname().

Referenced by getXrootdSite(), getXrootdSiteFromURL(), XrdAdaptor::RequestManager::initialize(), and Source().

256 {
257  getHostname(host, domain);
258  size_t pos = domain.find(".");
259  if (pos != std::string::npos && (pos < domain.size())) {domain = domain.substr(pos+1);}
260 
261  return !domain.empty();
262 }
host
Definition: query.py:115
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:227
std::shared_ptr< XrdCl::File > Source::getFileHandle ( )

Definition at line 399 of file XrdSource.cc.

References fh().

400 {
401  return fh();
402 }
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:69
bool Source::getHostname ( const std::string &  id,
std::string &  hostname 
)
static

Definition at line 227 of file XrdSource.cc.

References query::host, triggerObjects_cff::id, and mps_fire::result.

Referenced by getDomain(), XrdAdaptor::RequestManager::initialize(), and XrdAdaptor::RequestManager::queueUpdateCurrentServer().

228 {
229  size_t pos = id.find(":");
230  hostname = id;
231  if ((pos != std::string::npos) && (pos > 0)) {hostname = id.substr(0, pos);}
232 
233  bool retval = true;
234  if (!hostname.empty() && ((hostname[0] == '[') || isdigit(hostname[0])))
235  {
236  retval = false;
237  struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo));
238  hints.ai_family = AF_UNSPEC;
239  struct addrinfo *result;
240  if (!getaddrinfo(hostname.c_str(), nullptr, &hints, &result))
241  {
242  std::vector<char> host; host.reserve(256);
243  if (!getnameinfo(result->ai_addr, result->ai_addrlen, &host[0], 255, nullptr, 0, NI_NAMEREQD))
244  {
245  hostname = &host[0];
246  retval = true;
247  }
248  freeaddrinfo(result);
249  }
250  }
251  return retval;
252 }
host
Definition: query.py:115
struct timespec XrdAdaptor::Source::getLastDowngrade ( ) const
inline

Definition at line 45 of file XrdSource.h.

45 {return m_lastDowngrade;}
struct timespec m_lastDowngrade
Definition: XrdSource.h:74
unsigned XrdAdaptor::Source::getQuality ( )
inline

Definition at line 43 of file XrdSource.h.

43 {return m_qm->get();}
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:81
bool Source::getXrootdSite ( XrdCl::File &  file,
std::string &  site 
)
static

Definition at line 326 of file XrdSource.cc.

References getDomain(), getXrootdSiteFromURL(), triggerObjects_cff::id, isDCachePool(), definitions::server, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by setXrootdSite().

327 {
328  std::string lastUrl;
329  fh.GetProperty("LastURL", lastUrl);
330  if (lastUrl.empty() || isDCachePool(lastUrl))
331  {
333  if (!fh.GetProperty("DataServer", server)) {id = "(unknown)";}
334  else {id = server;}
335  if (lastUrl.empty()) {edm::LogWarning("XrdFileWarning") << "Unable to determine the URL associated with server " << id;}
336  site = "Unknown";
337  if (!server.empty()) {getDomain(server, site);}
338  return false;
339  }
340  return getXrootdSiteFromURL(lastUrl, site);
341 }
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:255
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:266
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:69
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:344
bool Source::getXrootdSiteFromURL ( std::string  url,
std::string &  site 
)
static

Definition at line 344 of file XrdSource.cc.

References getDomain(), QueryAttrHandler::query(), seconds(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getXrootdSite(), and XrdAdaptor::RequestManager::initialize().

345 {
346  const std::string attr = "sitename";
347  XrdCl::Buffer *response = nullptr;
348  XrdCl::Buffer arg( attr.size() );
349  arg.FromString( attr );
350 
351  XrdCl::FileSystem fs(url);
352  std::string rsite;
353  XrdCl::XRootDStatus st = QueryAttrHandler::query(fs, "sitename", std::chrono::seconds(1), rsite);
354  if (!st.IsOK())
355  {
356  XrdCl::URL xurl(url);
357  getDomain(xurl.GetHostName(), site);
358  delete response;
359  return false;
360  }
361  if (!rsite.empty() && (rsite[rsite.size()-1] == '\n'))
362  {
363  rsite = rsite.substr(0, rsite.size()-1);
364  }
365  if (rsite == "sitename")
366  {
367  XrdCl::URL xurl(url);
368  getDomain(xurl.GetHostName(), site);
369  return false;
370  }
371  site = rsite;
372  return true;
373 }
double seconds()
static XrdCl::XRootDStatus query(XrdCl::FileSystem &fs, const std::string &attr, std::chrono::milliseconds timeout, std::string &result)
Definition: XrdSource.cc:99
A arg
Definition: Factorize.h:38
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:255
void Source::handle ( std::shared_ptr< ClientRequest c)

Definition at line 420 of file XrdSource.cc.

References cms::Exception::addContext(), EnergyCorrector::c, haddnano::cl, edm::errors::FileReadError, ID(), m_fh, m_qm, m_stats, XrdAdaptor::XrdSiteStatistics::startRead(), stats(), mps_update::status, and validateList().

421 {
422  edm::LogVerbatim("XrdAdaptorInternal") << "Reading from " << ID() << ", quality " << m_qm->get() << std::endl;
423  c->m_source = shared_from_this();
424  c->m_self_reference = c;
425  m_qm->startWatch(c->m_qmw);
426  if (m_stats)
427  {
428  std::shared_ptr<XrdReadStatistics> readStats = XrdSiteStatistics::startRead(stats(), c);
429  c->setStatistics(readStats);
430  }
431 #ifdef XRD_FAKE_SLOW
432  if (m_slow) std::this_thread::sleep_for(std::chrono::milliseconds(XRD_DELAY));
433 #endif
434 
435  XrdCl::XRootDStatus status;
436  if (c->m_into)
437  {
438  // See notes in ClientRequest definition to understand this voodoo.
439  status = m_fh->Read(c->m_off, c->m_size, c->m_into, c.get());
440  }
441  else
442  {
443  XrdCl::ChunkList cl;
444  cl.reserve(c->m_iolist->size());
445  for (const auto & it : *c->m_iolist)
446  {
447  cl.emplace_back(it.offset(), it.size(), it.data());
448  }
449  validateList(cl);
450  status = m_fh->VectorRead(cl, nullptr, c.get());
451  }
452 
453  if (!status.IsOK())
454  {
456  ex << "XrdFile::Read or XrdFile::VectorRead failed with error: '"
457  << status.ToStr() << "' (errNo = " << status.errNo << ")";
458  ex.addContext("Calling Source::handle");
459  throw ex;
460  }
461 }
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:82
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:405
std::shared_ptr< XrdSiteStatistics const > stats() const
Definition: XrdSource.h:71
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:79
static std::shared_ptr< XrdReadStatistics > startRead(std::shared_ptr< XrdSiteStatistics > parent, std::shared_ptr< ClientRequest > req)
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:81
const std::string & ID() const
Definition: XrdSource.h:38
void XrdAdaptor::Source::handle ( RequestList &  )
const std::string& XrdAdaptor::Source::ID ( ) const
inline

Definition at line 38 of file XrdSource.h.

Referenced by handle().

38 {return m_id;}
std::string m_id
Definition: XrdSource.h:75
bool Source::isDCachePool ( XrdCl::File &  file,
const XrdCl::HostList *  hostList = nullptr 
)
static

Definition at line 266 of file XrdSource.cc.

References mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by determineHostExcludeString(), getXrootdSite(), and SendMonitoringInfo().

267 {
268  // WORKAROUND: On open-file recovery in the Xrootd client, it'll carry around the
269  // dCache opaque information to other sites, causing isDCachePool to erroneously return
270  // true. We are working with the upstream developers to solve this.
271  //
272  // For now, we see if the previous server also looks like a dCache pool - something that
273  // wouldn't happen at a real site, as the previous server should look like a dCache door.
274  std::string lastUrl;
275  file.GetProperty("LastURL", lastUrl);
276  if (!lastUrl.empty())
277  {
278  bool result = isDCachePool(lastUrl);
279  if (result && hostList && (hostList->size() > 1))
280  {
281  if (isDCachePool((*hostList)[hostList->size()-2].url.GetURL()))
282  {
283  return false;
284  }
285  return true;
286  }
287  return result;
288  }
289  return false;
290 }
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:266
bool Source::isDCachePool ( const std::string &  url)
static

Definition at line 293 of file XrdSource.cc.

References genParticles_cff::map, and relmon_authenticated_wget::url.

294 {
295  XrdCl::URL url(lastUrl);
296  XrdCl::URL::ParamsMap map = url.GetParams();
297  // dCache pools always utilize this opaque identifier.
298  if (map.find("org.dcache.uuid") != map.end())
299  {
300  return true;
301  }
302  return false;
303 }
const std::string& XrdAdaptor::Source::PrettyID ( ) const
inline

Definition at line 40 of file XrdSource.h.

Referenced by XrdAdaptor::ClientRequest::HandleResponse().

40 {return m_prettyid;}
std::string m_prettyid
Definition: XrdSource.h:76
void XrdAdaptor::Source::requestCallback ( )
private
void XrdAdaptor::Source::setLastDowngrade ( struct timespec  now)
inline
void Source::setXrootdSite ( )
private

Definition at line 376 of file XrdSource.cc.

References getXrootdSite(), m_fh, m_id, m_prettyid, m_site, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by Source().

377 {
378  std::string site;
379  bool goodSitename = getXrootdSite(*m_fh, site);
380  if (!goodSitename)
381  {
382  edm::LogInfo("XrdAdaptorInternal")
383  << "Xrootd server at " << m_id << " did not provide a sitename. Monitoring may be incomplete.";
384  }
385  else
386  {
387  m_site = site;
388  m_prettyid = m_id + " (site " + m_site + ")";
389  }
390  edm::LogInfo("XrdAdaptorInternal") << "Reading from new server " << m_id << " at site " << m_site;
391 }
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:326
std::string m_id
Definition: XrdSource.h:75
std::string m_site
Definition: XrdSource.h:77
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:79
std::string m_prettyid
Definition: XrdSource.h:76
const std::string& XrdAdaptor::Source::Site ( ) const
inline

Definition at line 39 of file XrdSource.h.

39 {return m_site;}
std::string m_site
Definition: XrdSource.h:77
std::shared_ptr<XrdSiteStatistics const> XrdAdaptor::Source::stats ( ) const
inlineprivate

Definition at line 71 of file XrdSource.h.

References edm::get_underlying_safe().

Referenced by handle().

edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:82
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::shared_ptr<XrdSiteStatistics>& XrdAdaptor::Source::stats ( )
inlineprivate

Definition at line 72 of file XrdSource.h.

References edm::get_underlying_safe().

edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:82
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)

Member Data Documentation

std::string XrdAdaptor::Source::m_exclude
private

Definition at line 78 of file XrdSource.h.

Referenced by Source().

edm::propagate_const<std::shared_ptr<XrdCl::File> > XrdAdaptor::Source::m_fh
private

Definition at line 79 of file XrdSource.h.

Referenced by handle(), setXrootdSite(), and Source().

std::string XrdAdaptor::Source::m_id
private

Definition at line 75 of file XrdSource.h.

Referenced by setXrootdSite(), Source(), and ~Source().

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 74 of file XrdSource.h.

std::string XrdAdaptor::Source::m_prettyid
private

Definition at line 76 of file XrdSource.h.

Referenced by setXrootdSite(), and Source().

edm::propagate_const<std::unique_ptr<QualityMetricSource> > XrdAdaptor::Source::m_qm
private

Definition at line 81 of file XrdSource.h.

Referenced by handle(), and Source().

std::string XrdAdaptor::Source::m_site
private

Definition at line 77 of file XrdSource.h.

Referenced by setXrootdSite(), Source(), and ~Source().

edm::propagate_const<std::shared_ptr<XrdSiteStatistics> > XrdAdaptor::Source::m_stats
private

Definition at line 82 of file XrdSource.h.

Referenced by handle(), and Source().