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
 
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 (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 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 181 of file XrdSource.cc.

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

◆ ~Source()

Source::~Source ( )

Definition at line 366 of file XrdSource.cc.

366 { 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 288 of file XrdSource.cc.

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 }

References geometryDiff::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 41 of file XrdSource.h.

41 { return m_exclude; }

References m_exclude.

◆ fh() [1/2]

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

Definition at line 72 of file XrdSource.h.

72 { 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 71 of file XrdSource.h.

71 { 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 246 of file XrdSource.cc.

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 }

References getHostname(), and query::host.

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

◆ getFileHandle()

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

Definition at line 368 of file XrdSource.cc.

368 { return fh(); }

References fh().

◆ getHostname()

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

Definition at line 219 of file XrdSource.cc.

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 }

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

45  {
46  return m_lastDowngrade;
47  }

References m_lastDowngrade.

◆ getQuality()

unsigned XrdAdaptor::Source::getQuality ( )
inline

Definition at line 43 of file XrdSource.h.

43 { return m_qm->get(); }

References m_qm.

◆ getXrootdSite()

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

Definition at line 304 of file XrdSource.cc.

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 }

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 326 of file XrdSource.cc.

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 }

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 382 of file XrdSource.cc.

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 }

References cms::Exception::addContext(), 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 38 of file XrdSource.h.

38 { return m_id; }

References m_id.

Referenced by handle().

◆ isDCachePool() [1/2]

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

Definition at line 278 of file XrdSource.cc.

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 }

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 256 of file XrdSource.cc.

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 }

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

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

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

40 { return m_prettyid; }

References m_prettyid.

◆ requestCallback()

void XrdAdaptor::Source::requestCallback ( )
private

◆ setLastDowngrade()

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

Definition at line 48 of file XrdSource.h.

48 { m_lastDowngrade = now; }

References m_lastDowngrade, and submitPVValidationJobs::now.

◆ setXrootdSite()

void Source::setXrootdSite ( )
private

Definition at line 353 of file XrdSource.cc.

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 }

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

39 { return m_site; }

References m_site.

◆ stats() [1/2]

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

Definition at line 74 of file XrdSource.h.

74 { 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 73 of file XrdSource.h.

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

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:77
g_delayCount
std::atomic< int > g_delayCount
Definition: XrdSource.cc:32
XrdAdaptor::Source::stats
std::shared_ptr< XrdSiteStatistics const > stats() const
Definition: XrdSource.h:73
relmon_authenticated_wget.url
url
Definition: relmon_authenticated_wget.py:22
XrdAdaptor::Source::m_site
std::string m_site
Definition: XrdSource.h:79
XrdAdaptor::Source::m_qm
edm::propagate_const< std::unique_ptr< QualityMetricSource > > m_qm
Definition: XrdSource.h:83
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
mps_update.status
status
Definition: mps_update.py:68
XrdAdaptor::Source::fh
std::shared_ptr< XrdCl::File const > fh() const
Definition: XrdSource.h:71
pos
Definition: PixelAliasList.h:18
validateList
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:370
cms::cuda::assert
assert(be >=bs)
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
XrdAdaptor::Source::m_stats
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_stats
Definition: XrdSource.h:84
edm::get_underlying_safe
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:41
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
query.host
string host
Definition: query.py:115
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Exception
Definition: EDMException.h:77
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
XrdAdaptor::Source::m_fh
edm::propagate_const< std::shared_ptr< XrdCl::File > > m_fh
Definition: XrdSource.h:81
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:90
XrdAdaptor::Source::getDomain
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:246
XrdAdaptor::Source::m_exclude
std::string m_exclude
Definition: XrdSource.h:80
XrdAdaptor::Source::m_lastDowngrade
struct timespec m_lastDowngrade
Definition: XrdSource.h:76
geometryDiff.file
file
Definition: geometryDiff.py:13
XrdAdaptor::Source::isDCachePool
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:256
contentValuesFiles.server
server
Definition: contentValuesFiles.py:37
XrdAdaptor::Source::getXrootdSiteFromURL
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:326
XrdAdaptor::Source::m_prettyid
std::string m_prettyid
Definition: XrdSource.h:78
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
XrdAdaptor::Source::getXrootdSite
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:304
DelayedClose
Definition: XrdSource.cc:41
funct::arg
A arg
Definition: Factorize.h:31
hcal_runs.URL
URL
Definition: hcal_runs.py:4
XrdAdaptor::Source::setXrootdSite
void setXrootdSite()
Definition: XrdSource.cc:353
mps_fire.result
result
Definition: mps_fire.py:311
genParticles_cff.map
map
Definition: genParticles_cff.py:11
XrdAdaptor::Source::ID
const std::string & ID() const
Definition: XrdSource.h:38
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::errors::FileReadError
Definition: EDMException.h:50
XrdAdaptor::Source::getHostname
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:219