3 #define _GLIBCXX_USE_NANOSLEEP
13 #include "XrdCl/XrdClFile.hh"
23 #define MAX_REQUEST 256 * 1024
24 #define XRD_CL_MAX_CHUNK 512 * 1024
28 #define XRD_DELAY 1000
29 #define XRD_SLOW_RATE 2
47 : m_fh(
std::
move(fh)), m_id(
id), m_site(site) {
48 if (m_fh && m_fh->IsOpen()) {
49 if (!m_fh->Close(
this).IsOK()) {
58 XrdCl::AnyObject *response,
59 XrdCl::HostList *hostList)
override {
62 <<
"' (errno=" <<
status->errNo <<
", code=" <<
status->code
63 <<
", server=" << m_id <<
", site=" << m_site <<
")";
83 friend std::unique_ptr<QueryAttrHandler> std::make_unique<QueryAttrHandler>();
90 static XrdCl::XRootDStatus
query(XrdCl::FileSystem &fs,
92 std::chrono::milliseconds
timeout,
94 auto handler = std::make_unique<QueryAttrHandler>();
95 auto l_state = std::make_shared<QueryAttrState>();
96 handler->m_state = l_state;
97 XrdCl::Buffer
arg(attr.size());
108 std::unique_lock<std::mutex> guard(l_state->m_mutex);
110 l_state->m_condvar.wait_for(guard,
timeout, [&] {
return l_state->m_status.get(); });
112 if (l_state->m_status) {
113 if (l_state->m_status->IsOK()) {
114 result = l_state->m_response->ToString();
116 return *(l_state->m_status);
118 return XrdCl::XRootDStatus(
119 XrdCl::stError, XrdCl::errSocketTimeout, 1,
"Timeout when waiting for query callback.");
128 std::unique_ptr<XrdCl::AnyObject> response_mgr;
129 response_mgr.reset(response);
132 auto l_state = m_state.lock();
140 [&](
char *) { l_state->m_condvar.notify_all(); });
145 if (!l_state->m_status)
146 l_state->m_status = std::make_unique<XrdCl::XRootDStatus>(XrdCl::stError, XrdCl::errInternal);
155 XrdCl::Buffer *buf_ptr;
156 response->Get(buf_ptr);
158 response->Set(static_cast<int *>(
nullptr));
159 l_state->m_response.reset(buf_ptr);
161 l_state->m_status.reset(
status);
182 : m_lastDowngrade({0, 0}),
195 if (!m_fh->GetProperty(
"DataServer", m_id)) {
196 edm::LogWarning(
"XrdFileWarning") <<
"Source::Source() failed to determine data server name.'";
198 if (m_exclude.empty()) {
203 m_prettyid = m_id +
" (unknown site)";
205 if (getDomain(m_id, domain_id)) {
208 m_site =
"Unknown (" + m_id +
")";
215 m_stats = statsService->getStatisticsForSite(m_site);
220 size_t pos =
id.find(
':');
222 if ((
pos != std::string::npos) && (
pos > 0)) {
223 hostname =
id.substr(0,
pos);
227 if (!hostname.empty() && ((hostname[0] ==
'[') || isdigit(hostname[0]))) {
229 struct addrinfo hints;
230 memset(&hints, 0,
sizeof(
struct addrinfo));
231 hints.ai_family = AF_UNSPEC;
233 if (!getaddrinfo(hostname.c_str(),
nullptr, &hints, &
result)) {
234 std::vector<char>
host;
236 if (!getnameinfo(
result->ai_addr,
result->ai_addrlen, &
host[0], 255,
nullptr, 0, NI_NAMEREQD)) {
248 size_t pos = domain.find(
'.');
249 if (
pos != std::string::npos && (
pos < domain.size())) {
250 domain = domain.substr(
pos + 1);
253 return !domain.empty();
264 file.GetProperty(
"LastURL", lastUrl);
265 if (!lastUrl.empty()) {
267 if (
result && hostList && (hostList->size() > 1)) {
268 if (
isDCachePool((*hostList)[hostList->size() - 2].url.GetURL())) {
280 XrdCl::URL::ParamsMap
map =
url.GetParams();
282 if (
map.find(
"org.dcache.uuid") !=
map.end()) {
296 const XrdCl::HostInfo &
info = (*hostList)[hostList->size() - 3];
297 exclude =
info.url.GetHostName();
299 file.GetProperty(
"LastURL", lastUrl);
300 edm::LogVerbatim(
"XrdAdaptorInternal") <<
"Changing exclude list for URL " << lastUrl <<
" to " << exclude;
306 fh.GetProperty(
"LastURL", lastUrl);
309 if (!
fh.GetProperty(
"DataServer",
server)) {
314 if (lastUrl.empty()) {
315 edm::LogWarning(
"XrdFileWarning") <<
"Unable to determine the URL associated with server " <<
id;
328 XrdCl::Buffer *response =
nullptr;
329 XrdCl::Buffer
arg(attr.size());
330 arg.FromString(attr);
332 XrdCl::FileSystem fs(
url);
341 if (!rsite.empty() && (rsite[rsite.size() - 1] ==
'\n')) {
342 rsite = rsite.substr(0, rsite.size() - 1);
344 if (rsite ==
"sitename") {
358 <<
" did not provide a sitename. Monitoring may be incomplete.";
371 off_t last_offset = -1;
372 for (
const auto &ci :
cl) {
373 assert(static_cast<off_t>(ci.offset) > last_offset);
374 last_offset = ci.offset;
376 assert(ci.offset < 0x1ffffffffff);
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);
389 c->setStatistics(readStats);
393 std::this_thread::sleep_for(std::chrono::milliseconds(XRD_DELAY));
396 XrdCl::XRootDStatus
status;
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());
412 ex <<
"XrdFile::Read or XrdFile::VectorRead failed with error: '" <<
status.ToStr() <<
"' (errNo = " <<
status.errNo