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
 
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

◆ Source() [1/2]

XrdAdaptor::Source::Source ( const Source )
delete

◆ Source() [2/2]

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

Definition at line 183 of file XrdSource.cc.

184  : m_lastDowngrade({0, 0}),
185  m_id("(unknown)"),
186  m_exclude(exclude),
187  m_fh(std::move(fh)),
188  m_stats(nullptr)
189 #ifdef XRD_FAKE_SLOW
190  ,
191  m_slow(++g_delayCount % XRD_SLOW_RATE == 0)
192 //, m_slow(++g_delayCount >= XRD_SLOW_RATE)
193 //, m_slow(true)
194 #endif
195 {
196  if (m_fh.get()) {
197  if (!m_fh->GetProperty("DataServer", m_id)) {
198  edm::LogWarning("XrdFileWarning") << "Source::Source() failed to determine data server name.'";
199  }
200  if (m_exclude.empty()) {
201  m_exclude = m_id;
202  }
203  }
205  m_prettyid = m_id + " (unknown site)";
206  std::string domain_id;
207  if (getDomain(m_id, domain_id)) {
208  m_site = domain_id;
209  } else {
210  m_site = "Unknown (" + m_id + ")";
211  }
212  setXrootdSite();
213  assert(m_qm.get());
214  assert(m_fh.get());
216  if (statsService) {
217  m_stats = statsService->getStatisticsForSite(m_site);
218  }
219 }
std::string m_id
Definition: XrdSource.h:77
std::atomic< int > g_delayCount
Definition: XrdSource.cc:32
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:71
std::string m_exclude
Definition: XrdSource.h:80
struct timespec m_lastDowngrade
Definition: XrdSource.h:76
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:84
std::string m_site
Definition: XrdSource.h:79
assert(be >=bs)
constexpr element_type const * get() const
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:81
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:248
static XrdSiteStatisticsInformation * getInstance()
std::string m_prettyid
Definition: XrdSource.h:78
Log< level::Warning, false > LogWarning
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:83
def move(src, dest)
Definition: eostools.py:511

◆ ~Source()

Source::~Source ( )

Definition at line 367 of file XrdSource.cc.

References fh(), m_id, and m_site.

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

Member Function Documentation

◆ determineHostExcludeString()

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

Definition at line 290 of file XrdSource.cc.

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

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

290  {
291  // Detect a dCache pool and, if we are in the federation context, give a custom
292  // exclude parameter.
293  // We assume this is a federation context if there's at least a regional, dCache door,
294  // and dCache pool server (so, more than 2 servers!).
295 
296  exclude = "";
297  if (hostList && (hostList->size() > 3) && isDCachePool(file, hostList)) {
298  const XrdCl::HostInfo &info = (*hostList)[hostList->size() - 3];
299  exclude = info.url.GetHostName();
300  std::string lastUrl;
301  file.GetProperty("LastURL", lastUrl);
302  edm::LogVerbatim("XrdAdaptorInternal") << "Changing exclude list for URL " << lastUrl << " to " << exclude;
303  }
304 }
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:258

◆ ExcludeID()

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

◆ fh() [1/2]

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(), getXrootdSite(), 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

◆ fh() [2/2]

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

◆ getDomain()

bool Source::getDomain ( const std::string &  host,
std::string &  domain 
)
static

Definition at line 248 of file XrdSource.cc.

References getHostname(), and query::host.

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

248  {
249  getHostname(host, domain);
250  size_t pos = domain.find('.');
251  if (pos != std::string::npos && (pos < domain.size())) {
252  domain = domain.substr(pos + 1);
253  }
254 
255  return !domain.empty();
256 }
string host
Definition: query.py:115
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:221

◆ getFileHandle()

std::shared_ptr< XrdCl::File > Source::getFileHandle ( )

Definition at line 369 of file XrdSource.cc.

References fh().

369 { return fh(); }
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:71

◆ getHostname()

bool Source::getHostname ( const std::string &  id,
std::string &  hostname 
)
static

Definition at line 221 of file XrdSource.cc.

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

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

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

◆ getLastDowngrade()

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

◆ getQuality()

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

◆ getXrootdSite()

bool Source::getXrootdSite ( XrdCl::File &  file,
std::string &  site 
)
static

Definition at line 306 of file XrdSource.cc.

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

Referenced by setXrootdSite().

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

◆ getXrootdSiteFromURL()

bool Source::getXrootdSiteFromURL ( std::string  url,
std::string &  site 
)
static

Definition at line 328 of file XrdSource.cc.

References getDomain(), QueryAttrHandler::query(), seconds(), AlCaHLTBitMon_QueryRunRegistry::string, hcal_runs::URL, and relmon_authenticated_wget::url.

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

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

◆ handle() [1/2]

void Source::handle ( std::shared_ptr< ClientRequest c)

Definition at line 383 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().

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

◆ handle() [2/2]

void XrdAdaptor::Source::handle ( RequestList &  )

◆ ID()

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

◆ isDCachePool() [1/2]

bool Source::isDCachePool ( XrdCl::File &  file,
const XrdCl::HostList *  hostList = nullptr 
)
static

Definition at line 258 of file XrdSource.cc.

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

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

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

◆ isDCachePool() [2/2]

bool Source::isDCachePool ( const std::string &  url)
static

Definition at line 280 of file XrdSource.cc.

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

280  {
281  XrdCl::URL url(lastUrl);
282  XrdCl::URL::ParamsMap map = url.GetParams();
283  // dCache pools always utilize this opaque identifier.
284  if (map.find("org.dcache.uuid") != map.end()) {
285  return true;
286  }
287  return false;
288 }

◆ operator=()

Source& XrdAdaptor::Source::operator= ( const Source )
delete

◆ PrettyID()

const std::string& XrdAdaptor::Source::PrettyID ( ) const
inline

Definition at line 40 of file XrdSource.h.

References m_prettyid.

40 { return m_prettyid; }
std::string m_prettyid
Definition: XrdSource.h:78

◆ requestCallback()

void XrdAdaptor::Source::requestCallback ( )
private

◆ setLastDowngrade()

void XrdAdaptor::Source::setLastDowngrade ( struct timespec  now)
inline

Definition at line 48 of file XrdSource.h.

References m_lastDowngrade, and submitPVValidationJobs::now.

◆ setXrootdSite()

void Source::setXrootdSite ( )
private

Definition at line 354 of file XrdSource.cc.

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

354  {
355  std::string site;
356  bool goodSitename = getXrootdSite(*m_fh, site);
357  if (!goodSitename) {
358  edm::LogInfo("XrdAdaptorInternal") << "Xrootd server at " << m_id
359  << " did not provide a sitename. Monitoring may be incomplete.";
360  } else {
361  m_site = site;
362  m_prettyid = m_id + " (site " + m_site + ")";
363  }
364  edm::LogInfo("XrdAdaptorInternal") << "Reading from new server " << m_id << " at site " << m_site;
365 }
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:306
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

◆ Site()

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

◆ stats() [1/2]

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)

◆ stats() [2/2]

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

◆ m_exclude

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

Definition at line 80 of file XrdSource.h.

Referenced by ExcludeID().

◆ m_fh

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().

◆ m_id

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

Definition at line 77 of file XrdSource.h.

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

◆ m_lastDowngrade

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 76 of file XrdSource.h.

Referenced by getLastDowngrade(), and setLastDowngrade().

◆ m_prettyid

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

Definition at line 78 of file XrdSource.h.

Referenced by PrettyID(), and setXrootdSite().

◆ m_qm

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().

◆ m_site

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

Definition at line 79 of file XrdSource.h.

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

◆ m_stats

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().