CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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
 
Sourceoperator= (const Source &)=delete
 
const std::string & PrettyID () const
 
void setLastDowngrade (struct timespec now)
 
const std::string & Site () const
 
 Source (const Source &)=delete
 
 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 23 of file XrdSource.h.

Constructor & Destructor Documentation

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

Definition at line 181 of file XrdSource.cc.

182  : m_lastDowngrade({0, 0}),
struct timespec m_lastDowngrade
Definition: XrdSource.h:76
Source::~Source ( )

Definition at line 366 of file XrdSource.cc.

References fh(), m_id, and m_site.

366 { new DelayedClose(fh(), m_id, m_site); }
std::string m_id
Definition: XrdSource.h:77
std::string m_site
Definition: XrdSource.h:79
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:71

Member Function Documentation

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

Definition at line 288 of file XrdSource.cc.

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

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

288  {
289  // Detect a dCache pool and, if we are in the federation context, give a custom
290  // exclude parameter.
291  // We assume this is a federation context if there's at least a regional, dCache door,
292  // and dCache pool server (so, more than 2 servers!).
293 
294  exclude = "";
295  if (hostList && (hostList->size() > 3) && isDCachePool(file, hostList)) {
296  const XrdCl::HostInfo &info = (*hostList)[hostList->size() - 3];
297  exclude = info.url.GetHostName();
298  std::string lastUrl;
299  file.GetProperty("LastURL", lastUrl);
300  edm::LogVerbatim("XrdAdaptorInternal") << "Changing exclude list for URL " << lastUrl << " to " << exclude;
301  }
302 }
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:256
const std::string& XrdAdaptor::Source::ExcludeID ( ) const
inline

Definition at line 41 of file XrdSource.h.

References m_exclude.

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

Definition at line 71 of file XrdSource.h.

References edm::get_underlying_safe(), and m_fh.

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

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

Definition at line 72 of file XrdSource.h.

References edm::get_underlying_safe(), and m_fh.

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

Definition at line 246 of file XrdSource.cc.

References getHostname().

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

246  {
247  getHostname(host, domain);
248  size_t pos = domain.find('.');
249  if (pos != std::string::npos && (pos < domain.size())) {
250  domain = domain.substr(pos + 1);
251  }
252 
253  return !domain.empty();
254 }
string host
Definition: query.py:115
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:219
std::shared_ptr< XrdCl::File > Source::getFileHandle ( )

Definition at line 368 of file XrdSource.cc.

References fh().

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

Definition at line 219 of file XrdSource.cc.

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

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

219  {
220  size_t pos = id.find(':');
221  hostname = id;
222  if ((pos != std::string::npos) && (pos > 0)) {
223  hostname = id.substr(0, pos);
224  }
225 
226  bool retval = true;
227  if (!hostname.empty() && ((hostname[0] == '[') || isdigit(hostname[0]))) {
228  retval = false;
229  struct addrinfo hints;
230  memset(&hints, 0, sizeof(struct addrinfo));
231  hints.ai_family = AF_UNSPEC;
232  struct addrinfo *result;
233  if (!getaddrinfo(hostname.c_str(), nullptr, &hints, &result)) {
234  std::vector<char> host;
235  host.reserve(256);
236  if (!getnameinfo(result->ai_addr, result->ai_addrlen, &host[0], 255, nullptr, 0, NI_NAMEREQD)) {
237  hostname = &host[0];
238  retval = true;
239  }
240  freeaddrinfo(result);
241  }
242  }
243  return retval;
244 }
uint16_t *__restrict__ id
tuple result
Definition: mps_fire.py:311
string host
Definition: query.py:115
struct timespec XrdAdaptor::Source::getLastDowngrade ( ) const
inline

Definition at line 45 of file XrdSource.h.

References m_lastDowngrade.

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

Definition at line 43 of file XrdSource.h.

References m_qm.

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

Definition at line 304 of file XrdSource.cc.

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

Referenced by setXrootdSite().

304  {
305  std::string lastUrl;
306  fh.GetProperty("LastURL", lastUrl);
307  if (lastUrl.empty() || isDCachePool(lastUrl)) {
309  if (!fh.GetProperty("DataServer", server)) {
310  id = "(unknown)";
311  } else {
312  id = server;
313  }
314  if (lastUrl.empty()) {
315  edm::LogWarning("XrdFileWarning") << "Unable to determine the URL associated with server " << id;
316  }
317  site = "Unknown";
318  if (!server.empty()) {
319  getDomain(server, site);
320  }
321  return false;
322  }
323  return getXrootdSiteFromURL(lastUrl, site);
324 }
uint16_t *__restrict__ id
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:246
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:256
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:71
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:326
Log< level::Warning, false > LogWarning
bool Source::getXrootdSiteFromURL ( std::string  url,
std::string &  site 
)
static

Definition at line 326 of file XrdSource.cc.

References getDomain(), QueryAttrHandler::query(), uploadConditions::response, seconds(), AlCaHLTBitMon_QueryRunRegistry::string, and hcal_runs::URL.

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

326  {
327  const std::string attr = "sitename";
328  XrdCl::Buffer *response = nullptr;
329  XrdCl::Buffer arg(attr.size());
330  arg.FromString(attr);
331 
332  XrdCl::FileSystem fs(url);
333  std::string rsite;
334  XrdCl::XRootDStatus st = QueryAttrHandler::query(fs, "sitename", std::chrono::seconds(1), rsite);
335  if (!st.IsOK()) {
336  XrdCl::URL xurl(url);
337  getDomain(xurl.GetHostName(), site);
338  delete response;
339  return false;
340  }
341  if (!rsite.empty() && (rsite[rsite.size() - 1] == '\n')) {
342  rsite = rsite.substr(0, rsite.size() - 1);
343  }
344  if (rsite == "sitename") {
345  XrdCl::URL xurl(url);
346  getDomain(xurl.GetHostName(), site);
347  return false;
348  }
349  site = rsite;
350  return true;
351 }
double seconds()
static XrdCl::XRootDStatus query(XrdCl::FileSystem &fs, const std::string &attr, std::chrono::milliseconds timeout, std::string &result)
Definition: XrdSource.cc:90
A arg
Definition: Factorize.h:31
string URL
Definition: hcal_runs.py:4
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:246
void Source::handle ( std::shared_ptr< ClientRequest c)

Definition at line 382 of file XrdSource.cc.

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

382  {
383  edm::LogVerbatim("XrdAdaptorInternal") << "Reading from " << ID() << ", quality " << m_qm->get() << std::endl;
384  c->m_source = shared_from_this();
385  c->m_self_reference = c;
386  m_qm->startWatch(c->m_qmw);
387  if (m_stats) {
388  std::shared_ptr<XrdReadStatistics> readStats = XrdSiteStatistics::startRead(stats(), c);
389  c->setStatistics(readStats);
390  }
391 #ifdef XRD_FAKE_SLOW
392  if (m_slow)
393  std::this_thread::sleep_for(std::chrono::milliseconds(XRD_DELAY));
394 #endif
395 
396  XrdCl::XRootDStatus status;
397  if (c->m_into) {
398  // See notes in ClientRequest definition to understand this voodoo.
399  status = m_fh->Read(c->m_off, c->m_size, c->m_into, c.get());
400  } else {
401  XrdCl::ChunkList cl;
402  cl.reserve(c->m_iolist->size());
403  for (const auto &it : *c->m_iolist) {
404  cl.emplace_back(it.offset(), it.size(), it.data());
405  }
406  validateList(cl);
407  status = m_fh->VectorRead(cl, nullptr, c.get());
408  }
409 
410  if (!status.IsOK()) {
412  ex << "XrdFile::Read or XrdFile::VectorRead failed with error: '" << status.ToStr() << "' (errNo = " << status.errNo
413  << ")";
414  ex.addContext("Calling Source::handle");
415  throw ex;
416  }
417 }
Log< level::Info, true > LogVerbatim
const edm::EventSetup & c
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:84
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:370
list status
Definition: mps_update.py:107
tuple cl
Definition: haddnano.py:49
std::shared_ptr< XrdSiteStatistics const > stats() const
Definition: XrdSource.h:73
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:81
static std::shared_ptr< XrdReadStatistics > startRead(std::shared_ptr< XrdSiteStatistics > parent, std::shared_ptr< ClientRequest > req)
T get() const
Definition: EventSetup.h:88
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:83
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.

References m_id.

Referenced by handle().

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

Definition at line 256 of file XrdSource.cc.

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

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

256  {
257  // WORKAROUND: On open-file recovery in the Xrootd client, it'll carry around the
258  // dCache opaque information to other sites, causing isDCachePool to erroneously return
259  // true. We are working with the upstream developers to solve this.
260  //
261  // For now, we see if the previous server also looks like a dCache pool - something that
262  // wouldn't happen at a real site, as the previous server should look like a dCache door.
263  std::string lastUrl;
264  file.GetProperty("LastURL", lastUrl);
265  if (!lastUrl.empty()) {
266  bool result = isDCachePool(lastUrl);
267  if (result && hostList && (hostList->size() > 1)) {
268  if (isDCachePool((*hostList)[hostList->size() - 2].url.GetURL())) {
269  return false;
270  }
271  return true;
272  }
273  return result;
274  }
275  return false;
276 }
tuple result
Definition: mps_fire.py:311
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:256
bool Source::isDCachePool ( const std::string &  url)
static

Definition at line 278 of file XrdSource.cc.

References hcal_runs::URL, and relmon_authenticated_wget::url.

278  {
279  XrdCl::URL url(lastUrl);
280  XrdCl::URL::ParamsMap map = url.GetParams();
281  // dCache pools always utilize this opaque identifier.
282  if (map.find("org.dcache.uuid") != map.end()) {
283  return true;
284  }
285  return false;
286 }
string URL
Definition: hcal_runs.py:4
Source& XrdAdaptor::Source::operator= ( const Source )
delete
const std::string& XrdAdaptor::Source::PrettyID ( ) const
inline

Definition at line 40 of file XrdSource.h.

References m_prettyid.

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

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

Definition at line 48 of file XrdSource.h.

References m_lastDowngrade, and submitPVValidationJobs::now.

void Source::setXrootdSite ( )
private

Definition at line 353 of file XrdSource.cc.

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

353  {
354  std::string site;
355  bool goodSitename = getXrootdSite(*m_fh, site);
356  if (!goodSitename) {
357  edm::LogInfo("XrdAdaptorInternal") << "Xrootd server at " << m_id
358  << " did not provide a sitename. Monitoring may be incomplete.";
359  } else {
360  m_site = site;
361  m_prettyid = m_id + " (site " + m_site + ")";
362  }
363  edm::LogInfo("XrdAdaptorInternal") << "Reading from new server " << m_id << " at site " << m_site;
364 }
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:304
std::string m_id
Definition: XrdSource.h:77
std::string m_site
Definition: XrdSource.h:79
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:81
Log< level::Info, false > LogInfo
std::string m_prettyid
Definition: XrdSource.h:78
const std::string& XrdAdaptor::Source::Site ( ) const
inline

Definition at line 39 of file XrdSource.h.

References m_site.

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

Definition at line 73 of file XrdSource.h.

References edm::get_underlying_safe(), and m_stats.

Referenced by handle().

73 { return get_underlying_safe(m_stats); }
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:84
constexpr 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 74 of file XrdSource.h.

References edm::get_underlying_safe(), and m_stats.

74 { return get_underlying_safe(m_stats); }
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:84
constexpr 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 80 of file XrdSource.h.

Referenced by ExcludeID().

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

Definition at line 81 of file XrdSource.h.

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

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

Definition at line 77 of file XrdSource.h.

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

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 76 of file XrdSource.h.

Referenced by getLastDowngrade(), and setLastDowngrade().

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

Definition at line 78 of file XrdSource.h.

Referenced by PrettyID(), and setXrootdSite().

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

Definition at line 83 of file XrdSource.h.

Referenced by getQuality(), and handle().

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

Definition at line 79 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 84 of file XrdSource.h.

Referenced by handle(), and stats().