CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 24 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.

191  : m_lastDowngrade({0, 0}),
struct timespec m_lastDowngrade
Definition: XrdSource.h:73
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:74
std::string m_site
Definition: XrdSource.h:76
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:68

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 40 of file XrdSource.h.

References m_exclude.

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

Definition at line 68 of file XrdSource.h.

References edm::get_underlying_safe(), and m_fh.

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

68 {return get_underlying_safe(m_fh);}
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:78
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 69 of file XrdSource.h.

References edm::get_underlying_safe(), and m_fh.

69 {return get_underlying_safe(m_fh);}
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:78
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(), and XrdAdaptor::RequestManager::initialize().

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.size();
262 }
string host
Definition: query.py:114
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:68
bool Source::getHostname ( const std::string &  id,
std::string &  hostname 
)
static

Definition at line 227 of file XrdSource.cc.

References query::host, NULL, 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.size() && ((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(), NULL, &hints, &result))
241  {
242  std::vector<char> host; host.reserve(256);
243  if (!getnameinfo(result->ai_addr, result->ai_addrlen, &host[0], 255, NULL, 0, NI_NAMEREQD))
244  {
245  hostname = &host[0];
246  retval = true;
247  }
248  freeaddrinfo(result);
249  }
250  }
251  return retval;
252 }
#define NULL
Definition: scimark2.h:8
tuple result
Definition: mps_fire.py:83
string host
Definition: query.py:114
struct timespec XrdAdaptor::Source::getLastDowngrade ( ) const
inline

Definition at line 44 of file XrdSource.h.

References m_lastDowngrade.

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

Definition at line 42 of file XrdSource.h.

References m_qm.

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

Definition at line 326 of file XrdSource.cc.

References getDomain(), getXrootdSiteFromURL(), isDCachePool(), contentValuesFiles::server, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by setXrootdSite().

327 {
328  std::string lastUrl;
329  fh.GetProperty("LastURL", lastUrl);
330  if (!lastUrl.size() || isDCachePool(lastUrl))
331  {
332  std::string server, id;
333  if (!fh.GetProperty("DataServer", server)) {id = "(unknown)";}
334  else {id = server;}
335  if (!lastUrl.size()) {edm::LogWarning("XrdFileWarning") << "Unable to determine the URL associated with server " << id;}
336  site = "Unknown";
337  if (server.size()) {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:68
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(), AlCaHLTBitMon_QueryRunRegistry::string, and util.rrClient::URL.

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

345 {
346  const std::string attr = "sitename";
347  XrdCl::Buffer *response = 0;
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:36
string URL
Definition: rrClient.py:4
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, GetRecoTauVFromDQM_MC_cff::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:81
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:405
std::shared_ptr< XrdSiteStatistics const > stats() const
Definition: XrdSource.h:70
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:78
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:80
const std::string & ID() const
Definition: XrdSource.h:37
tuple status
Definition: mps_update.py:57
void XrdAdaptor::Source::handle ( RequestList &  )
const std::string& XrdAdaptor::Source::ID ( ) const
inline

Definition at line 37 of file XrdSource.h.

References m_id.

Referenced by handle().

37 {return m_id;}
std::string m_id
Definition: XrdSource.h:74
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.size())
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 }
tuple result
Definition: mps_fire.py:83
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 util.rrClient::URL, 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 }
string URL
Definition: rrClient.py:4
const std::string& XrdAdaptor::Source::PrettyID ( ) const
inline

Definition at line 39 of file XrdSource.h.

References m_prettyid.

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

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

Definition at line 45 of file XrdSource.h.

References m_lastDowngrade, and fileCollector::now.

struct timespec m_lastDowngrade
Definition: XrdSource.h:73
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.

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:74
std::string m_site
Definition: XrdSource.h:76
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:78
std::string m_prettyid
Definition: XrdSource.h:75
const std::string& XrdAdaptor::Source::Site ( ) const
inline

Definition at line 38 of file XrdSource.h.

References m_site.

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

Definition at line 70 of file XrdSource.h.

References edm::get_underlying_safe(), and m_stats.

Referenced by handle().

edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:81
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 71 of file XrdSource.h.

References edm::get_underlying_safe(), and m_stats.

edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:81
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 77 of file XrdSource.h.

Referenced by ExcludeID().

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

Definition at line 78 of file XrdSource.h.

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

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

Definition at line 74 of file XrdSource.h.

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

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 73 of file XrdSource.h.

Referenced by getLastDowngrade(), and setLastDowngrade().

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

Definition at line 75 of file XrdSource.h.

Referenced by PrettyID(), and setXrootdSite().

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

Definition at line 80 of file XrdSource.h.

Referenced by getQuality(), and handle().

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

Definition at line 76 of file XrdSource.h.

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

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

Definition at line 81 of file XrdSource.h.

Referenced by handle(), and stats().