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

void requestCallback ()
 
void setXrootdSite ()
 

Private Attributes

std::string m_exclude
 
std::shared_ptr< XrdCl::File > m_fh
 
std::string m_id
 
struct timespec m_lastDowngrade
 
std::string m_prettyid
 
std::unique_ptr
< QualityMetricSource
m_qm
 
std::string m_site
 
std::shared_ptr
< XrdSiteStatistics
m_stats
 

Detailed Description

Definition at line 22 of file XrdSource.h.

Constructor & Destructor Documentation

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

Definition at line 79 of file XrdSource.cc.

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

Definition at line 283 of file XrdSource.cc.

References m_fh, m_id, and m_site.

284 {
285  new DelayedClose(m_fh, m_id, m_site);
286 }
std::string m_id
Definition: XrdSource.h:67
std::string m_site
Definition: XrdSource.h:69
std::shared_ptr< XrdCl::File > m_fh
Definition: XrdSource.h:71

Member Function Documentation

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

Definition at line 196 of file XrdSource.cc.

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

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

197 {
198  // Detect a dCache pool and, if we are in the federation context, give a custom
199  // exclude parameter.
200  // We assume this is a federation context if there's at least a regional, dCache door,
201  // and dCache pool server (so, more than 2 servers!).
202 
203  exclude = "";
204  if (hostList && (hostList->size() > 3) && isDCachePool(file, hostList))
205  {
206  const XrdCl::HostInfo &info = (*hostList)[hostList->size()-3];
207  exclude = info.url.GetHostName();
208  std::string lastUrl; file.GetProperty("LastURL", lastUrl);
209  edm::LogVerbatim("XrdAdaptorInternal") << "Changing exclude list for URL " << lastUrl << " to " << exclude;
210  }
211 }
static const TGPicture * info(bool iBackgroundIsBlack)
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:155
const std::string& XrdAdaptor::Source::ExcludeID ( ) const
inline

Definition at line 38 of file XrdSource.h.

References m_exclude.

38 {return m_exclude;}
std::string m_exclude
Definition: XrdSource.h:70
bool Source::getDomain ( const std::string &  host,
std::string &  domain 
)
static

Definition at line 144 of file XrdSource.cc.

References getHostname().

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

145 {
146  getHostname(host, domain);
147  size_t pos = domain.find(".");
148  if (pos != std::string::npos && (pos < domain.size())) {domain = domain.substr(pos+1);}
149 
150  return domain.size();
151 }
string host
Definition: query.py:114
static bool getHostname(const std::string &id, std::string &hostname)
Definition: XrdSource.cc:116
std::shared_ptr< XrdCl::File > Source::getFileHandle ( )

Definition at line 289 of file XrdSource.cc.

References m_fh.

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

Definition at line 116 of file XrdSource.cc.

References query::host, NULL, and query::result.

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

117 {
118  size_t pos = id.find(":");
119  hostname = id;
120  if ((pos != std::string::npos) && (pos > 0)) {hostname = id.substr(0, pos);}
121 
122  bool retval = true;
123  if (hostname.size() && ((hostname[0] == '[') || isdigit(hostname[0])))
124  {
125  retval = false;
126  struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo));
127  hints.ai_family = AF_UNSPEC;
128  struct addrinfo *result;
129  if (!getaddrinfo(hostname.c_str(), NULL, &hints, &result))
130  {
131  std::vector<char> host; host.reserve(256);
132  if (!getnameinfo(result->ai_addr, result->ai_addrlen, &host[0], 255, NULL, 0, NI_NAMEREQD))
133  {
134  hostname = &host[0];
135  retval = true;
136  }
137  freeaddrinfo(result);
138  }
139  }
140  return retval;
141 }
#define NULL
Definition: scimark2.h:8
tuple result
Definition: query.py:137
string host
Definition: query.py:114
struct timespec XrdAdaptor::Source::getLastDowngrade ( ) const
inline

Definition at line 42 of file XrdSource.h.

References m_lastDowngrade.

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

Definition at line 40 of file XrdSource.h.

References m_qm.

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

Definition at line 215 of file XrdSource.cc.

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

Referenced by setXrootdSite().

216 {
217  std::string lastUrl;
218  fh.GetProperty("LastURL", lastUrl);
219  if (!lastUrl.size() || isDCachePool(lastUrl))
220  {
221  std::string server, id;
222  if (!fh.GetProperty("DataServer", server)) {id = "(unknown)";}
223  else {id = server;}
224  if (!lastUrl.size()) {edm::LogWarning("XrdFileWarning") << "Unable to determine the URL associated with server " << id;}
225  site = "Unknown";
226  if (server.size()) {getDomain(server, site);}
227  return false;
228  }
229  return getXrootdSiteFromURL(lastUrl, site);
230 }
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:144
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:155
static bool getXrootdSiteFromURL(std::string url, std::string &site)
Definition: XrdSource.cc:233
bool Source::getXrootdSiteFromURL ( std::string  url,
std::string &  site 
)
static

Definition at line 233 of file XrdSource.cc.

References helper::Config, getDomain(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

234 {
235  const std::string attr = "sitename";
236  XrdCl::Buffer *response = 0;
237  XrdCl::Buffer arg( attr.size() );
238  arg.FromString( attr );
239 
240  XrdCl::FileSystem fs(url);
241  XrdCl::XRootDStatus st = fs.Query(XrdCl::QueryCode::Config, arg, response);
242  if (!st.IsOK())
243  {
244  XrdCl::URL xurl(url);
245  getDomain(xurl.GetHostName(), site);
246  delete response;
247  return false;
248  }
249  std::string rsite = response->ToString();
250  delete response;
251  if (rsite.size() && (rsite[rsite.size()-1] == '\n'))
252  {
253  rsite = rsite.substr(0, rsite.size()-1);
254  }
255  if (rsite == "sitename")
256  {
257  XrdCl::URL xurl(url);
258  getDomain(xurl.GetHostName(), site);
259  return false;
260  }
261  site = rsite;
262  return true;
263 }
A arg
Definition: Factorize.h:36
static bool getDomain(const std::string &host, std::string &domain)
Definition: XrdSource.cc:144
tuple Config
Definition: helper.py:9
void Source::handle ( std::shared_ptr< ClientRequest c)

Definition at line 310 of file XrdSource.cc.

References EnergyCorrector::c, GetRecoTauVFromDQM_MC_cff::cl, ID(), m_fh, m_qm, m_stats, XrdAdaptor::XrdSiteStatistics::startRead(), and validateList().

311 {
312  edm::LogVerbatim("XrdAdaptorInternal") << "Reading from " << ID() << ", quality " << m_qm->get() << std::endl;
313  c->m_source = shared_from_this();
314  c->m_self_reference = c;
315  m_qm->startWatch(c->m_qmw);
316  if (m_stats)
317  {
318  std::shared_ptr<XrdReadStatistics> readStats = XrdSiteStatistics::startRead(m_stats, c);
319  c->setStatistics(readStats);
320  }
321 #ifdef XRD_FAKE_SLOW
322  if (m_slow) std::this_thread::sleep_for(std::chrono::milliseconds(XRD_DELAY));
323 #endif
324  if (c->m_into)
325  {
326  // See notes in ClientRequest definition to understand this voodoo.
327  m_fh->Read(c->m_off, c->m_size, c->m_into, c.get());
328  }
329  else
330  {
331  XrdCl::ChunkList cl;
332  cl.reserve(c->m_iolist->size());
333  for (const auto & it : *c->m_iolist)
334  {
335  cl.emplace_back(it.offset(), it.size(), it.data());
336  }
337  validateList(cl);
338  m_fh->VectorRead(cl, nullptr, c.get());
339  }
340 }
static void validateList(const XrdCl::ChunkList &cl)
Definition: XrdSource.cc:295
std::shared_ptr< XrdCl::File > m_fh
Definition: XrdSource.h:71
static std::shared_ptr< XrdReadStatistics > startRead(std::shared_ptr< XrdSiteStatistics > parent, std::shared_ptr< ClientRequest > req)
std::unique_ptr< QualityMetricSource > m_qm
Definition: XrdSource.h:73
std::shared_ptr< XrdSiteStatistics > m_stats
Definition: XrdSource.h:74
const std::string & ID() const
Definition: XrdSource.h:35
void XrdAdaptor::Source::handle ( RequestList &  )
const std::string& XrdAdaptor::Source::ID ( ) const
inline

Definition at line 35 of file XrdSource.h.

References m_id.

Referenced by handle().

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

Definition at line 155 of file XrdSource.cc.

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

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

156 {
157  // WORKAROUND: On open-file recovery in the Xrootd client, it'll carry around the
158  // dCache opaque information to other sites, causing isDCachePool to erroneously return
159  // true. We are working with the upstream developers to solve this.
160  //
161  // For now, we see if the previous server also looks like a dCache pool - something that
162  // wouldn't happen at a real site, as the previous server should look like a dCache door.
163  std::string lastUrl;
164  file.GetProperty("LastURL", lastUrl);
165  if (lastUrl.size())
166  {
167  bool result = isDCachePool(lastUrl);
168  if (result && hostList && (hostList->size() > 1))
169  {
170  if (isDCachePool((*hostList)[hostList->size()-2].url.GetURL()))
171  {
172  return false;
173  }
174  return true;
175  }
176  return result;
177  }
178  return false;
179 }
static bool isDCachePool(XrdCl::File &file, const XrdCl::HostList *hostList=nullptr)
Definition: XrdSource.cc:155
tuple result
Definition: query.py:137
bool Source::isDCachePool ( const std::string &  url)
static

Definition at line 182 of file XrdSource.cc.

References python.multivaluedict::map(), and relmon_authenticated_wget::url.

183 {
184  XrdCl::URL url(lastUrl);
185  XrdCl::URL::ParamsMap map = url.GetParams();
186  // dCache pools always utilize this opaque identifier.
187  if (map.find("org.dcache.uuid") != map.end())
188  {
189  return true;
190  }
191  return false;
192 }
const std::string& XrdAdaptor::Source::PrettyID ( ) const
inline

Definition at line 37 of file XrdSource.h.

References m_prettyid.

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

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

Definition at line 43 of file XrdSource.h.

References m_lastDowngrade, and fileCollector::now.

struct timespec m_lastDowngrade
Definition: XrdSource.h:66
void Source::setXrootdSite ( )
private

Definition at line 266 of file XrdSource.cc.

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

267 {
268  std::string site;
269  bool goodSitename = getXrootdSite(*m_fh, site);
270  if (!goodSitename)
271  {
272  edm::LogInfo("XrdAdaptorInternal")
273  << "Xrootd server at " << m_id << " did not provide a sitename. Monitoring may be incomplete.";
274  }
275  else
276  {
277  m_site = site;
278  m_prettyid = m_id + " (site " + m_site + ")";
279  }
280  edm::LogInfo("XrdAdaptorInternal") << "Reading from new server " << m_id << " at site " << m_site;
281 }
static bool getXrootdSite(XrdCl::File &file, std::string &site)
Definition: XrdSource.cc:215
std::string m_id
Definition: XrdSource.h:67
std::string m_site
Definition: XrdSource.h:69
std::shared_ptr< XrdCl::File > m_fh
Definition: XrdSource.h:71
std::string m_prettyid
Definition: XrdSource.h:68
const std::string& XrdAdaptor::Source::Site ( ) const
inline

Definition at line 36 of file XrdSource.h.

References m_site.

36 {return m_site;}
std::string m_site
Definition: XrdSource.h:69

Member Data Documentation

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

Definition at line 70 of file XrdSource.h.

Referenced by ExcludeID().

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

Definition at line 71 of file XrdSource.h.

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

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

Definition at line 67 of file XrdSource.h.

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

struct timespec XrdAdaptor::Source::m_lastDowngrade
private

Definition at line 66 of file XrdSource.h.

Referenced by getLastDowngrade(), and setLastDowngrade().

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

Definition at line 68 of file XrdSource.h.

Referenced by PrettyID(), and setXrootdSite().

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

Definition at line 73 of file XrdSource.h.

Referenced by getQuality(), and handle().

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

Definition at line 69 of file XrdSource.h.

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

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

Definition at line 74 of file XrdSource.h.

Referenced by handle().