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 (RequestList &)
 
void handle (std::shared_ptr< ClientRequest >)
 
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 (const std::string &url)
 
static bool isDCachePool (XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
 

Private Member Functions

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

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::Source ( timespec  now,
std::unique_ptr< XrdCl::File >  fileHandle,
const std::string &  exclude 
)

Definition at line 176 of file XrdSource.cc.

177  : m_lastDowngrade({0, 0}),
178  m_id("(unknown)"),
179  m_exclude(exclude),
180  m_fh(std::move(fh)),
181  m_stats(nullptr)
182 #ifdef XRD_FAKE_SLOW
183  ,
184  m_slow(++g_delayCount % XRD_SLOW_RATE == 0)
185 //, m_slow(++g_delayCount >= XRD_SLOW_RATE)
186 //, m_slow(true)
187 #endif
188 {
189  if (m_fh.get()) {
190  if (!m_fh->GetProperty("DataServer", m_id)) {
191  edm::LogWarning("XrdFileWarning") << "Source::Source() failed to determine data server name.'";
192  }
193  if (m_exclude.empty()) {
194  m_exclude = m_id;
195  }
196  }
198  m_prettyid = m_id + " (unknown site)";
199  std::string domain_id;
200  if (getDomain(m_id, domain_id)) {
201  m_site = domain_id;
202  } else {
203  m_site = "Unknown (" + m_id + ")";
204  }
205  setXrootdSite();
206  assert(m_qm.get());
207  assert(m_fh.get());
209  if (statsService) {
210  m_stats = statsService->getStatisticsForSite(m_site);
211  }
212 }

◆ ~Source()

Source::~Source ( )

Definition at line 361 of file XrdSource.cc.

361 { new DelayedClose(fh(), m_id, m_site); }

References fh(), m_id, and m_site.

Member Function Documentation

◆ determineHostExcludeString()

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

Definition at line 283 of file XrdSource.cc.

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

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

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

◆ ExcludeID()

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

Definition at line 40 of file XrdSource.h.

40 { return m_exclude; }

References m_exclude.

◆ fh() [1/2]

std::shared_ptr<XrdCl::File>& XrdAdaptor::Source::fh ( )
inlineprivate

Definition at line 71 of file XrdSource.h.

71 { return get_underlying_safe(m_fh); }

References edm::get_underlying_safe(), and m_fh.

◆ fh() [2/2]

std::shared_ptr<XrdCl::File const> XrdAdaptor::Source::fh ( ) const
inlineprivate

Definition at line 70 of file XrdSource.h.

70 { return get_underlying_safe(m_fh); }

References edm::get_underlying_safe(), and m_fh.

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

◆ getDomain()

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

Definition at line 241 of file XrdSource.cc.

241  {
242  getHostname(host, domain);
243  size_t pos = domain.find(".");
244  if (pos != std::string::npos && (pos < domain.size())) {
245  domain = domain.substr(pos + 1);
246  }
247 
248  return !domain.empty();
249 }

References getHostname(), and query::host.

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

◆ getFileHandle()

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

Definition at line 363 of file XrdSource.cc.

363 { return fh(); }

References fh().

◆ getHostname()

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

Definition at line 214 of file XrdSource.cc.

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

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

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

◆ getLastDowngrade()

struct timespec XrdAdaptor::Source::getLastDowngrade ( ) const
inline

Definition at line 44 of file XrdSource.h.

44  {
45  return m_lastDowngrade;
46  }

References m_lastDowngrade.

◆ getQuality()

unsigned XrdAdaptor::Source::getQuality ( )
inline

Definition at line 42 of file XrdSource.h.

42 { return m_qm->get(); }

References m_qm.

◆ getXrootdSite()

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

Definition at line 299 of file XrdSource.cc.

299  {
300  std::string lastUrl;
301  fh.GetProperty("LastURL", lastUrl);
302  if (lastUrl.empty() || isDCachePool(lastUrl)) {
304  if (!fh.GetProperty("DataServer", server)) {
305  id = "(unknown)";
306  } else {
307  id = server;
308  }
309  if (lastUrl.empty()) {
310  edm::LogWarning("XrdFileWarning") << "Unable to determine the URL associated with server " << id;
311  }
312  site = "Unknown";
313  if (!server.empty()) {
314  getDomain(server, site);
315  }
316  return false;
317  }
318  return getXrootdSiteFromURL(lastUrl, site);
319 }

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

Referenced by setXrootdSite().

◆ getXrootdSiteFromURL()

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

Definition at line 321 of file XrdSource.cc.

321  {
322  const std::string attr = "sitename";
323  XrdCl::Buffer *response = nullptr;
324  XrdCl::Buffer arg(attr.size());
325  arg.FromString(attr);
326 
327  XrdCl::FileSystem fs(url);
328  std::string rsite;
329  XrdCl::XRootDStatus st = QueryAttrHandler::query(fs, "sitename", std::chrono::seconds(1), rsite);
330  if (!st.IsOK()) {
331  XrdCl::URL xurl(url);
332  getDomain(xurl.GetHostName(), site);
333  delete response;
334  return false;
335  }
336  if (!rsite.empty() && (rsite[rsite.size() - 1] == '\n')) {
337  rsite = rsite.substr(0, rsite.size() - 1);
338  }
339  if (rsite == "sitename") {
340  XrdCl::URL xurl(url);
341  getDomain(xurl.GetHostName(), site);
342  return false;
343  }
344  site = rsite;
345  return true;
346 }

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

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

◆ handle() [1/2]

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

◆ handle() [2/2]

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

Definition at line 377 of file XrdSource.cc.

377  {
378  edm::LogVerbatim("XrdAdaptorInternal") << "Reading from " << ID() << ", quality " << m_qm->get() << std::endl;
379  c->m_source = shared_from_this();
380  c->m_self_reference = c;
381  m_qm->startWatch(c->m_qmw);
382  if (m_stats) {
383  std::shared_ptr<XrdReadStatistics> readStats = XrdSiteStatistics::startRead(stats(), c);
384  c->setStatistics(readStats);
385  }
386 #ifdef XRD_FAKE_SLOW
387  if (m_slow)
388  std::this_thread::sleep_for(std::chrono::milliseconds(XRD_DELAY));
389 #endif
390 
391  XrdCl::XRootDStatus status;
392  if (c->m_into) {
393  // See notes in ClientRequest definition to understand this voodoo.
394  status = m_fh->Read(c->m_off, c->m_size, c->m_into, c.get());
395  } else {
396  XrdCl::ChunkList cl;
397  cl.reserve(c->m_iolist->size());
398  for (const auto &it : *c->m_iolist) {
399  cl.emplace_back(it.offset(), it.size(), it.data());
400  }
401  validateList(cl);
402  status = m_fh->VectorRead(cl, nullptr, c.get());
403  }
404 
405  if (!status.IsOK()) {
407  ex << "XrdFile::Read or XrdFile::VectorRead failed with error: '" << status.ToStr() << "' (errNo = " << status.errNo
408  << ")";
409  ex.addContext("Calling Source::handle");
410  throw ex;
411  }
412 }

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

◆ ID()

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

Definition at line 37 of file XrdSource.h.

37 { return m_id; }

References m_id.

Referenced by handle().

◆ isDCachePool() [1/2]

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

Definition at line 273 of file XrdSource.cc.

273  {
274  XrdCl::URL url(lastUrl);
275  XrdCl::URL::ParamsMap map = url.GetParams();
276  // dCache pools always utilize this opaque identifier.
277  if (map.find("org.dcache.uuid") != map.end()) {
278  return true;
279  }
280  return false;
281 }

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

◆ isDCachePool() [2/2]

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

Definition at line 251 of file XrdSource.cc.

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

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

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

◆ PrettyID()

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

Definition at line 39 of file XrdSource.h.

39 { return m_prettyid; }

References m_prettyid.

◆ requestCallback()

void XrdAdaptor::Source::requestCallback ( )
private

◆ setLastDowngrade()

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

Definition at line 47 of file XrdSource.h.

47 { m_lastDowngrade = now; }

References m_lastDowngrade, and fileCollector::now.

◆ setXrootdSite()

void Source::setXrootdSite ( )
private

Definition at line 348 of file XrdSource.cc.

348  {
349  std::string site;
350  bool goodSitename = getXrootdSite(*m_fh, site);
351  if (!goodSitename) {
352  edm::LogInfo("XrdAdaptorInternal") << "Xrootd server at " << m_id
353  << " did not provide a sitename. Monitoring may be incomplete.";
354  } else {
355  m_site = site;
356  m_prettyid = m_id + " (site " + m_site + ")";
357  }
358  edm::LogInfo("XrdAdaptorInternal") << "Reading from new server " << m_id << " at site " << m_site;
359 }

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

◆ Site()

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

Definition at line 38 of file XrdSource.h.

38 { return m_site; }

References m_site.

◆ stats() [1/2]

std::shared_ptr<XrdSiteStatistics>& XrdAdaptor::Source::stats ( )
inlineprivate

Definition at line 73 of file XrdSource.h.

73 { return get_underlying_safe(m_stats); }

References edm::get_underlying_safe(), and m_stats.

◆ stats() [2/2]

std::shared_ptr<XrdSiteStatistics const> XrdAdaptor::Source::stats ( ) const
inlineprivate

Definition at line 72 of file XrdSource.h.

72 { return get_underlying_safe(m_stats); }

References edm::get_underlying_safe(), and m_stats.

Referenced by handle().

Member Data Documentation

◆ m_exclude

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

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

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

◆ m_id

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

Definition at line 76 of file XrdSource.h.

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

◆ m_lastDowngrade

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 75 of file XrdSource.h.

Referenced by getLastDowngrade(), and setLastDowngrade().

◆ m_prettyid

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

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

Referenced by getQuality(), and handle().

◆ m_site

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

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

Referenced by handle(), and stats().

XrdAdaptor::XrdSiteStatisticsInformation
Definition: XrdStatistics.h:55
XrdAdaptor::XrdSiteStatisticsInformation::getInstance
static XrdSiteStatisticsInformation * getInstance()
Definition: XrdStatistics.cc:86
XrdAdaptor::Source::m_id
std::string m_id
Definition: XrdSource.h:76
g_delayCount
std::atomic< int > g_delayCount
Definition: XrdSource.cc:30
XrdAdaptor::Source::stats
std::shared_ptr< XrdSiteStatistics const > stats() const
Definition: XrdSource.h:72
relmon_authenticated_wget.url
url
Definition: relmon_authenticated_wget.py:22
XrdAdaptor::Source::m_site
std::string m_site
Definition: XrdSource.h:78
XrdAdaptor::Source::m_qm
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:82
mps_update.status
status
Definition: mps_update.py:69
XrdAdaptor::Source::fh
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:70
pos
Definition: PixelAliasList.h:18
edm::LogInfo
Definition: MessageLogger.h:254
validateList
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:365
cms::cuda::assert
assert(be >=bs)
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
XrdAdaptor::Source::m_stats
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:83
edm::Exception
Definition: EDMException.h:77
query.host
host
Definition: query.py:115
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
fileCollector.now
now
Definition: fileCollector.py:207
edm::propagate_const::get
element_type const * get() const
Definition: propagate_const.h:64
XrdAdaptor::Source::m_fh
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:80
XrdAdaptor::XrdSiteStatistics::startRead
static std::shared_ptr< XrdReadStatistics > startRead(std::shared_ptr< XrdSiteStatistics > parent, std::shared_ptr< ClientRequest > req)
Definition: XrdStatistics.cc:110
seconds
double seconds()
QueryAttrHandler::query
static XrdCl::XRootDStatus query(XrdCl::FileSystem &fs, const std::string &attr, std::chrono::milliseconds timeout, std::string &result)
Definition: XrdSource.cc:85
XrdAdaptor::Source::getDomain
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:241
XrdAdaptor::Source::m_exclude
std::string m_exclude
Definition: XrdSource.h:79
XrdAdaptor::Source::m_lastDowngrade
struct timespec m_lastDowngrade
Definition: XrdSource.h:75
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
edm::get_underlying_safe
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:40
XrdAdaptor::Source::isDCachePool
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:251
contentValuesFiles.server
server
Definition: contentValuesFiles.py:37
XrdAdaptor::Source::getXrootdSiteFromURL
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:321
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
edm::LogVerbatim
Definition: MessageLogger.h:297
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
XrdAdaptor::Source::m_prettyid
std::string m_prettyid
Definition: XrdSource.h:77
eostools.move
def move(src, dest)
Definition: eostools.py:511
XrdAdaptor::QualityMetricFactory::get
static std::unique_ptr< QualityMetricSource > get(timespec now, const std::string &id)
Definition: QualityMetric.cc:134
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
XrdAdaptor::Source::getXrootdSite
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:299
DelayedClose
Definition: XrdSource.cc:39
funct::arg
A arg
Definition: Factorize.h:36
hcal_runs.URL
URL
Definition: hcal_runs.py:4
XrdAdaptor::Source::setXrootdSite
void setXrootdSite()
Definition: XrdSource.cc:348
mps_fire.result
result
Definition: mps_fire.py:303
genParticles_cff.map
map
Definition: genParticles_cff.py:11
XrdAdaptor::Source::ID
const std::string & ID() const
Definition: XrdSource.h:37
edm::errors::FileReadError
Definition: EDMException.h:50
XrdAdaptor::Source::getHostname
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:214