XRootD
Loading...
Searching...
No Matches
XrdClHttp::File Class Referencefinal

#include <XrdClHttpFile.hh>

Inheritance diagram for XrdClHttp::File:
Collaboration diagram for XrdClHttp::File:

Public Member Functions

 File (std::shared_ptr< XrdClHttp::HandlerQueue > queue, XrdCl::Log *log)
virtual ~File () noexcept
virtual XrdCl::XRootDStatus Close (XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Fcntl (const XrdCl::Buffer &arg, XrdCl::ResponseHandler *handler, time_t timeout) override
XrdCl::OpenFlags::Flags Flags () const
struct timespec GetHeaderTimeout (time_t oper_timeout) const
virtual bool GetProperty (const std::string &name, std::string &value) const override
virtual bool IsOpen () const override
virtual XrdCl::XRootDStatus Open (const std::string &url, XrdCl::OpenFlags::Flags flags, XrdCl::Access::Mode mode, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus PgRead (uint64_t offset, uint32_t size, void *buffer, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Read (uint64_t offset, uint32_t size, void *buffer, XrdCl::ResponseHandler *handler, time_t timeout) override
void SetHeaderTimeout (const struct timespec &ts)
virtual bool SetProperty (const std::string &name, const std::string &value) override
virtual XrdCl::XRootDStatus Stat (bool force, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus VectorRead (const XrdCl::ChunkList &chunks, void *buffer, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Write (uint64_t offset, uint32_t size, const void *buffer, XrdCl::ResponseHandler *handler, time_t timeout) override
virtual XrdCl::XRootDStatus Write (uint64_t offset, XrdCl::Buffer &&buffer, XrdCl::ResponseHandler *handler, time_t timeout) override
Public Member Functions inherited from XrdCl::FilePlugIn
virtual ~FilePlugIn ()
 Destructor.
virtual XRootDStatus Clone (const CloneLocations &locs, ResponseHandler *handler, time_t timeout)
virtual std::unique_ptr< ExportedFileTemplateExportTemplate () const
virtual XRootDStatus Fcntl (QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, time_t timeout)
virtual XRootDStatus OpenUsingTemplate (ExportedFileTemplate *templ, const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout)
virtual XRootDStatus PgWrite (uint64_t offset, uint32_t nbpgs, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, time_t timeout)
virtual XRootDStatus PreRead (const TractList &tracts, ResponseHandler *handler, time_t timeout)
virtual XRootDStatus Read (uint64_t offset, uint32_t size, Optional< uint64_t > fdoff, int fd, ResponseHandler *handler, time_t timeout=0)
virtual XRootDStatus Sync (ResponseHandler *handler, time_t timeout)
virtual XRootDStatus Truncate (uint64_t size, ResponseHandler *handler, time_t timeout)
virtual XRootDStatus VectorWrite (const ChunkList &chunks, ResponseHandler *handler, time_t timeout=0)
virtual XRootDStatus Visa (ResponseHandler *handler, time_t timeout)
virtual XRootDStatus Write (uint64_t offset, uint32_t size, Optional< uint64_t > fdoff, int fd, ResponseHandler *handler, time_t timeout=0)
virtual XRootDStatus WriteV (uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)

Static Public Member Functions

static const struct timespec & GetDefaultHeaderTimeout ()
static struct timespec GetFederationMetadataTimeout ()
static struct timespec GetHeaderTimeoutWithDefault (time_t oper_timeout, const struct timespec &header_timeout)
static const struct timespec & GetMinimumHeaderTimeout ()
static std::string GetMonitoringJson ()
static struct timespec ParseHeaderTimeout (const std::string &header_value, XrdCl::Log *logger)
static void SetDefaultHeaderTimeout (struct timespec &ts)
static void SetFederationMetadataTimeout (const struct timespec &ts)
static void SetMinimumHeaderTimeout (struct timespec &ts)

Detailed Description

Definition at line 43 of file XrdClHttpFile.hh.

Constructor & Destructor Documentation

◆ File()

XrdClHttp::File::File ( std::shared_ptr< XrdClHttp::HandlerQueue > queue,
XrdCl::Log * log )
inline

Definition at line 45 of file XrdClHttpFile.hh.

45 :
46 m_queue(queue),
47 m_logger(log),
48 m_default_put_handler(new PutDefaultHandler(*this))
49 {}

Referenced by GetHeaderTimeout(), GetHeaderTimeoutWithDefault(), and ParseHeaderTimeout().

Here is the caller graph for this function:

◆ ~File()

File::~File ( )
virtualnoexcept

Definition at line 202 of file XrdClHttpFile.cc.

202 {
203 auto handler = m_put_handler.load(std::memory_order_acquire);
204 if (handler) {
205 // We must wait for all ongoing writes to complete; the XrdCl::File
206 // destructor will trigger a Close() operation when it is called without
207 // waiting for the Close to finish, then invoke our destructor.
208 // If the Close() is still ongoing, then the handler will receive a
209 // callback after its memory is freed.
210 handler->WaitForCompletion();
211 delete handler;
212 }
213}

References ~File().

Referenced by ~File().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ Close()

XrdCl::XRootDStatus File::Close ( XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Close

Reimplemented from XrdCl::FilePlugIn.

Definition at line 390 of file XrdClHttpFile.cc.

392{
393 if (!m_is_opened) {
394 m_logger->Error(kLogXrdClHttp, "Cannot close. URL isn't open");
395 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
396 }
397 m_is_opened = false;
398
399 std::unique_ptr<XrdCl::XRootDStatus> status(new XrdCl::XRootDStatus{});
400 if (m_put_op && !m_put_op->HasFailed()) {
401 auto put_size = m_put_offset.load(std::memory_order_relaxed);
402 if (m_asize >= 0 && put_size == m_asize) {
403 if (put_size == m_asize) {
404 m_logger->Debug(kLogXrdClHttp, "Closing a finished file %s", m_url.c_str());
405 } else {
406 m_logger->Debug(kLogXrdClHttp, "Closing a file %s with partial size (offset %llu, expected %lld)",
407 m_url.c_str(), static_cast<unsigned long long>(put_size), static_cast<long long>(m_asize));
408 status.reset(new XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp,
409 0, "Cannot close file with partial size"));
410 }
411 } else {
412 m_logger->Debug(kLogXrdClHttp, "Flushing final write buffer on close");
413 auto put_handler = m_put_handler.load(std::memory_order_acquire);
414 if (put_handler) {
415 return put_handler->QueueWrite(std::make_pair(nullptr, 0), handler);
416 } else {
417 m_logger->Error(kLogXrdClHttp, "Internal state error - put operation ongoing without handle");
418 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
419 }
420 }
421 } else if (!m_put_op && m_open_flags & XrdCl::OpenFlags::Write) {
422 timespec ts;
423 timespec_get(&ts, TIME_UTC);
424 ts.tv_sec += timeout;
425 m_asize = 0;
426 auto handler_wrapper = new PutResponseHandler(new CloseCreateHandler(handler));
427 m_put_handler.store(handler_wrapper, std::memory_order_release);
428 m_put_op.reset(new XrdClHttp::CurlPutOp(
429 handler_wrapper, m_default_put_handler, m_url, nullptr, 0, ts, m_logger,
430 GetConnCallout(), &m_default_header_callout
431 ));
432 handler_wrapper->SetOp(m_put_op);
433 m_url_current = "";
434 m_last_url = "";
435 m_logger->Debug(kLogXrdClHttp, "Creating a zero-sized object at %s for close", m_url.c_str());
436 try {
437 m_queue->Produce(m_put_op);
438 } catch (...) {
439 m_put_handler.store(nullptr, std::memory_order_release);
440 m_logger->Warning(kLogXrdClHttp, "Failed to add put op to queue");
441 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
442 }
443 return {};
444 }
445
446 m_logger->Debug(kLogXrdClHttp, "Closed %s", m_url.c_str());
447 m_url_current = "";
448 m_last_url = "";
449
450 if (handler) {
451 handler->HandleResponse(status.release(), nullptr);
452 }
453 return XrdCl::XRootDStatus();
454}
static std::string ts()
timestamp output for logging messages
Definition XrdCephOss.cc:53
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
const uint64_t kLogXrdClHttp
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errInvalidOp
const uint16_t errOSError
@ Write
Open only for writing.

References XrdCl::errInvalidOp, XrdCl::errOSError, XrdCl::ResponseHandler::HandleResponse(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, ts(), and XrdCl::OpenFlags::Write.

Here is the call graph for this function:

◆ Fcntl()

XrdCl::XRootDStatus File::Fcntl ( const XrdCl::Buffer & arg,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Fcntl

Reimplemented from XrdCl::FilePlugIn.

Definition at line 494 of file XrdClHttpFile.cc.

496{
497 if (!m_is_opened) {
498 m_logger->Error(kLogXrdClHttp, "Cannot run fcntl. URL isn't open");
499 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
500 }
501
502 auto obj = new XrdCl::AnyObject();
503 std::string as = arg.ToString();
504 try
505 {
507 if (code == XrdCl::QueryCode::XAttr)
508 {
509 nlohmann::json xatt;
510 std::string etagRes;
511 if (GetProperty("ETag", etagRes))
512 {
513 xatt["ETag"] = etagRes;
514 }
515 std::string cc;
516 if (GetProperty("Cache-Control", cc))
517 {
518 if (cc.find("must-revalidate") != std::string::npos)
519 {
520 xatt["revalidate"] = true;
521 }
522 size_t fm = cc.find("max-age=");
523 if (fm != std::string::npos)
524 {
525 fm += 9; // idx of the first character after the make-age= match
526 for (size_t i = fm; i < cc.length(); i++)
527 {
528 if (!std::isdigit(cc[i]))
529 {
530 std::string sa = cc.substr(fm, i);
531 long int a = std::stol(sa);
532 time_t t = time(NULL) + a;
533 xatt["expire"] = t;
534 break;
535 }
536 }
537 }
538 }
539 XrdCl::Buffer *respBuff = new XrdCl::Buffer();
540 m_logger->Debug(kLogXrdClHttp, "Fcntl content %s", xatt.dump().c_str());
541 respBuff->FromString(xatt.dump());
542 obj->Set(respBuff);
543 }
544 //
545 // Query codes supported by XrdCl::File::Fctnl
546 //
547 else {
548 std::string msg;
549 XrdCl::XRootDStatus status = XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
550 switch (code) {
552 msg = "Server status query not supported.";
553 break;
554 case XrdCl::QueryCode::Checksum: // fallthrough
556 msg = "Checksum query not supported.";
557 break;
559 msg = "Server configuration query not supported.";
560 break;
562 msg = "Local space stats query not supported.";
563 break;
564 case XrdCl::QueryCode::Opaque: // fallthrough
566 // XrdCl implementation dependent
567 msg = "Opaque query not supported.";
568 break;
570 msg = "Prepare status query not supported.";
571 break;
572 default:
573 msg = "Invalid information query type code";
574 }
575 m_logger->Error(kLogXrdClHttp, "%s", msg.c_str());
576 return status;
577 }
578 }
579 catch (const std::exception& e)
580 {
581 m_logger->Warning(kLogXrdClHttp, "Failed to parse query code %s", e.what());
582 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errDataError);
583 }
584
585 handler->HandleResponse(new XrdCl::XRootDStatus(), obj);
586 return XrdCl::XRootDStatus();
587}
virtual bool GetProperty(const std::string &name, std::string &value) const override
void FromString(const std::string str)
Fill the buffer from a string.
std::string ToString() const
Convert the buffer to a string.
const uint16_t errDataError
data is corrupted
Code
XRootD query request codes.
@ OpaqueFile
Implementation dependent.
@ XAttr
Query file extended attributes.
@ Opaque
Implementation dependent.
@ Config
Query server configuration.
@ Stats
Query server stats.
@ ChecksumCancel
Query file checksum cancellation.
@ Checksum
Query file checksum.
@ Space
Query logical space stats.
@ Prepare
Query prepare status.

References XrdCl::QueryCode::Checksum, XrdCl::QueryCode::ChecksumCancel, XrdCl::QueryCode::Config, XrdCl::errDataError, XrdCl::errInvalidOp, XrdCl::Buffer::FromString(), GetProperty(), XrdCl::ResponseHandler::HandleResponse(), XrdClHttp::kLogXrdClHttp, XrdCl::QueryCode::Opaque, XrdCl::QueryCode::OpaqueFile, XrdCl::QueryCode::Prepare, XrdCl::QueryCode::Space, XrdCl::QueryCode::Stats, XrdCl::stError, XrdCl::Buffer::ToString(), and XrdCl::QueryCode::XAttr.

Here is the call graph for this function:

◆ Flags()

XrdCl::OpenFlags::Flags XrdClHttp::File::Flags ( ) const
inline

Definition at line 107 of file XrdClHttpFile.hh.

107{return m_open_flags;}

References Flags().

Referenced by Flags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefaultHeaderTimeout()

const struct timespec & XrdClHttp::File::GetDefaultHeaderTimeout ( )
inlinestatic

Definition at line 119 of file XrdClHttpFile.hh.

119{return m_default_header_timeout;}

Referenced by ParseHeaderTimeout().

Here is the caller graph for this function:

◆ GetFederationMetadataTimeout()

struct timespec XrdClHttp::File::GetFederationMetadataTimeout ( )
inlinestatic

Definition at line 137 of file XrdClHttpFile.hh.

137{return m_fed_timeout;}

References GetFederationMetadataTimeout().

Referenced by GetFederationMetadataTimeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHeaderTimeout()

struct timespec File::GetHeaderTimeout ( time_t oper_timeout) const

Definition at line 282 of file XrdClHttpFile.cc.

283{
284 return GetHeaderTimeoutWithDefault(oper_timeout, m_header_timeout);
285}
static struct timespec GetHeaderTimeoutWithDefault(time_t oper_timeout, const struct timespec &header_timeout)

References File(), GetHeaderTimeout(), and GetHeaderTimeoutWithDefault().

Referenced by GetHeaderTimeout(), Open(), PgRead(), Read(), VectorRead(), Write(), and Write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHeaderTimeoutWithDefault()

struct timespec File::GetHeaderTimeoutWithDefault ( time_t oper_timeout,
const struct timespec & header_timeout )
static

Definition at line 262 of file XrdClHttpFile.cc.

263{
264 if (oper_timeout == 0) {
266 XrdCl::DefaultEnv::GetEnv()->GetInt( "RequestTimeout", val );
267 oper_timeout = val;
268 }
269 if (oper_timeout <= 0) {
270 return header_timeout;
271 }
272 if (oper_timeout == header_timeout.tv_sec) {
273 return {header_timeout.tv_sec, 0};
274 } else if (header_timeout.tv_sec < oper_timeout) {
275 return header_timeout;
276 } else { // header timeout is larger than the operation timeout
277 return {oper_timeout, 0};
278 }
279}
static Env * GetEnv()
Get default client environment.
bool GetInt(const std::string &key, int &value)
Definition XrdClEnv.cc:115
const int DefaultRequestTimeout

References File(), XrdCl::DefaultRequestTimeout, XrdCl::DefaultEnv::GetEnv(), GetHeaderTimeoutWithDefault(), and XrdCl::Env::GetInt().

Referenced by GetHeaderTimeout(), and GetHeaderTimeoutWithDefault().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMinimumHeaderTimeout()

const struct timespec & XrdClHttp::File::GetMinimumHeaderTimeout ( )
inlinestatic

Definition at line 113 of file XrdClHttpFile.hh.

113{return m_min_client_timeout;}

Referenced by ParseHeaderTimeout().

Here is the caller graph for this function:

◆ GetMonitoringJson()

std::string File::GetMonitoringJson ( )
static

Definition at line 288 of file XrdClHttpFile.cc.

289{
290 return "{\"prefetch\": {"
291 "\"count\": " + std::to_string(m_prefetch_count) + ","
292 "\"expired\": " + std::to_string(m_prefetch_expired_count) + ","
293 "\"failed\": " + std::to_string(m_prefetch_failed_count) + ","
294 "\"reads_hit\": " + std::to_string(m_prefetch_reads_hit) + ","
295 "\"reads_miss\": " + std::to_string(m_prefetch_reads_miss) + ","
296 "\"bytes_used\": " + std::to_string(m_prefetch_bytes_used) +
297 "}}";
298}

◆ GetProperty()

bool File::GetProperty ( const std::string & name,
std::string & value ) const
overridevirtual
See also
XrdCl::File::GetProperty

Reimplemented from XrdCl::FilePlugIn.

Definition at line 967 of file XrdClHttpFile.cc.

969{
970 if (name == "CurrentURL") {
971 value = GetCurrentURL();
972 return true;
973 }
974
975 if (name == "IsPrefetching") {
976 value = m_default_prefetch_handler->IsPrefetching() ? "true" : "false";
977 return true;
978 }
979
980 std::shared_lock lock(m_properties_mutex);
981 if (name == "LastURL") {
982 value = m_last_url;
983 return true;
984 }
985
986 const auto p = m_properties.find(name);
987 if (p == std::end(m_properties)) {
988 return false;
989 }
990
991 value = p->second;
992 return true;
993}

Referenced by Fcntl(), and Stat().

Here is the caller graph for this function:

◆ IsOpen()

bool File::IsOpen ( ) const
overridevirtual
See also
XrdCl::File::IsOpen

Reimplemented from XrdCl::FilePlugIn.

Definition at line 961 of file XrdClHttpFile.cc.

962{
963 return m_is_opened;
964}

◆ Open()

XrdCl::XRootDStatus File::Open ( const std::string & url,
XrdCl::OpenFlags::Flags flags,
XrdCl::Access::Mode mode,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Open

Reimplemented from XrdCl::FilePlugIn.

Definition at line 301 of file XrdClHttpFile.cc.

306{
307 if (m_is_opened) {
308 m_logger->Error(kLogXrdClHttp, "URL %s already open", url.c_str());
309 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
310 }
311
312 m_open_flags = flags;
313
314 m_header_timeout.tv_nsec = m_default_header_timeout.tv_nsec;
315 m_header_timeout.tv_sec = m_default_header_timeout.tv_sec;
316 auto parsed_url = XrdCl::URL();
317 parsed_url.SetPort(0);
318 if (!parsed_url.FromString(url)) {
319 m_logger->Error(kLogXrdClHttp, "Failed to parse provided URL as a valid URL: %s", url.c_str());
320 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidArgs);
321 }
322 auto pm = parsed_url.GetParams();
323 auto iter = pm.find("xrdclhttp.timeout");
324 std::string timeout_string = (iter == pm.end()) ? "" : iter->second;
325 m_header_timeout = ParseHeaderTimeout(timeout_string, m_logger);
326 pm["xrdclhttp.timeout"] = XrdClHttp::MarshalDuration(m_header_timeout);
327 parsed_url.SetParams(pm);
328 iter = pm.find("oss.asize");
329 if (iter != pm.end()) {
330 off_t asize;
331 auto ec = std::from_chars(iter->second.c_str(), iter->second.c_str() + iter->second.size(), asize);
332 if ((ec.ec == std::errc()) && (ec.ptr == iter->second.c_str() + iter->second.size()) && asize >= 0) {
333 m_asize = asize;
334 } else {
335 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp, 0, "Unable to parse oss.asize to a valid size");
336 }
337 pm.erase(iter);
338 parsed_url.SetParams(pm);
339 }
340
341 m_url = parsed_url.GetURL();
342 m_last_url = "";
343 m_url_current = "";
344
345 auto ts = GetHeaderTimeout(timeout);
346
347 bool full_download = m_full_download.load(std::memory_order_relaxed);
348 m_default_prefetch_handler.reset(new PrefetchDefaultHandler(*this));
349 if (full_download) {
350 m_default_prefetch_handler->m_prefetch_enabled.store(true, std::memory_order_relaxed);
351 }
352
353 if (full_download && !(flags & XrdCl::OpenFlags::Write)) {
354 m_logger->Debug(kLogXrdClHttp, "Opening %s in full download mode", m_url.c_str());
355
356 handler = new OpenFullDownloadResponseHandler(&m_is_opened, SendResponseInfo(), handler);
357 m_prefetch_size = std::numeric_limits<off_t>::max();
358 auto [status, ok] = ReadPrefetch(0, 0, nullptr, handler, timeout, false);
359 if (ok) {
360 return status;
361 } else {
362 m_logger->Error(kLogXrdClHttp, "Failed to start prefetch of data at open (URL %s): %s", m_url.c_str(), status.ToString().c_str());
363 return status;
364 }
365 }
366
367
368 m_logger->Debug(kLogXrdClHttp, "Opening %s (with timeout %lld)", m_url.c_str(), (long long) timeout);
369
370 // This response handler sets the m_is_opened flag to true if the open callback is successfully invoked.
371 handler = new OpenResponseHandler(&m_is_opened, handler);
372
373 std::shared_ptr<XrdClHttp::CurlOpenOp> openOp(
374 new XrdClHttp::CurlOpenOp(
375 handler, GetCurrentURL(), ts, m_logger, this, SendResponseInfo(), GetConnCallout(),
376 &m_default_header_callout
377 )
378 );
379 try {
380 m_queue->Produce(std::move(openOp));
381 } catch (...) {
382 m_logger->Warning(kLogXrdClHttp, "Failed to add open op to queue");
383 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
384 }
385
386 return XrdCl::XRootDStatus();
387}
static struct timespec ParseHeaderTimeout(const std::string &header_value, XrdCl::Log *logger)
struct timespec GetHeaderTimeout(time_t oper_timeout) const
std::string MarshalDuration(const struct timespec &timeout)
const uint16_t errInvalidArgs

References ec, XrdCl::errInvalidArgs, XrdCl::errInvalidOp, XrdCl::errOSError, GetHeaderTimeout(), XrdClHttp::kLogXrdClHttp, XrdClHttp::MarshalDuration(), ParseHeaderTimeout(), XrdCl::stError, XrdCl::Status::ToString(), ts(), and XrdCl::OpenFlags::Write.

Here is the call graph for this function:

◆ ParseHeaderTimeout()

struct timespec File::ParseHeaderTimeout ( const std::string & header_value,
XrdCl::Log * logger )
static

Definition at line 234 of file XrdClHttpFile.cc.

235{
236 struct timespec ts = File::GetDefaultHeaderTimeout();
237 if (!timeout_string.empty()) {
238 std::string errmsg;
239 // Parse the provided timeout and decrease by a second if we can (if it's below a second, halve it).
240 // The thinking is that if the client needs a response in N seconds, then we ought to set the internal
241 // timeout to (N-1) seconds to provide enough time for our response to arrive at the client.
242 if (!XrdClHttp::ParseTimeout(timeout_string, ts, errmsg)) {
243 logger->Error(kLogXrdClHttp, "Failed to parse xrdclhttp.timeout parameter: %s", errmsg.c_str());
244 } else if (ts.tv_sec >= 1) {
245 ts.tv_sec--;
246 } else {
247 ts.tv_nsec /= 2;
248 }
249 }
250 const auto mct = File::GetMinimumHeaderTimeout();
251 if (ts.tv_sec < mct.tv_sec ||
252 (ts.tv_sec == mct.tv_sec && ts.tv_nsec < mct.tv_nsec))
253 {
254 ts.tv_sec = mct.tv_sec;
255 ts.tv_nsec = mct.tv_nsec;
256 }
257
258 return ts;
259}
static const struct timespec & GetDefaultHeaderTimeout()
static const struct timespec & GetMinimumHeaderTimeout()
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
bool ParseTimeout(const std::string &duration, struct timespec &, std::string &errmsg)

References File(), GetDefaultHeaderTimeout(), GetMinimumHeaderTimeout(), XrdClHttp::kLogXrdClHttp, ParseHeaderTimeout(), XrdClHttp::ParseTimeout(), and ts().

Referenced by Open(), and ParseHeaderTimeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PgRead()

XrdCl::XRootDStatus File::PgRead ( uint64_t offset,
uint32_t size,
void * buffer,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl:File PgRead

Reimplemented from XrdCl::FilePlugIn.

Definition at line 916 of file XrdClHttpFile.cc.

921{
922 if (!m_is_opened) {
923 m_logger->Error(kLogXrdClHttp, "Cannot pgread. URL isn't open");
924 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
925 }
926 auto [status, ok] = ReadPrefetch(offset, size, buffer, handler, timeout, true);
927 if (ok) {
928 if (status.IsOK()) {
929 m_logger->Debug(kLogXrdClHttp, "PgRead %s (%d bytes at offset %lld) will be served from prefetch handler", m_url.c_str(), size, static_cast<long long>(offset));
930 } else {
931 m_logger->Warning(kLogXrdClHttp, "PgRead %s (%d bytes at offset %lld) failed: %s", m_url.c_str(), size, static_cast<long long>(offset), status.GetErrorMessage().c_str());
932 }
933 return status;
934 } else if (m_full_download.load(std::memory_order_relaxed)) {
935 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp, 0, "Non-sequential read detected when in full-download mode");
936 }
937
938 auto ts = GetHeaderTimeout(timeout);
939 auto url = GetCurrentURL();
940 m_logger->Debug(kLogXrdClHttp, "PgRead %s (%d bytes at offset %lld)", url.c_str(), size, static_cast<long long>(offset));
941
942 std::shared_ptr<XrdClHttp::CurlPgReadOp> readOp(
943 new XrdClHttp::CurlPgReadOp(
944 handler, m_default_prefetch_handler, url, ts, std::make_pair(offset, size),
945 static_cast<char*>(buffer), size, m_logger,
946 GetConnCallout(), &m_default_header_callout
947 )
948 );
949
950 try {
951 m_queue->Produce(std::move(readOp));
952 } catch (...) {
953 m_logger->Warning(kLogXrdClHttp, "Failed to add read op to queue");
954 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
955 }
956
957 return XrdCl::XRootDStatus();
958}

References XrdCl::errInvalidOp, XrdCl::errOSError, XrdCl::XRootDStatus::GetErrorMessage(), GetHeaderTimeout(), XrdCl::Status::IsOK(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, and ts().

Here is the call graph for this function:

◆ Read()

XrdCl::XRootDStatus File::Read ( uint64_t offset,
uint32_t size,
void * buffer,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Read

Reimplemented from XrdCl::FilePlugIn.

Definition at line 590 of file XrdClHttpFile.cc.

595{
596 if (!m_is_opened) {
597 m_logger->Error(kLogXrdClHttp, "Cannot read. URL isn't open");
598 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
599 }
600 auto [status, ok] = ReadPrefetch(offset, size, buffer, handler, timeout, false);
601 if (ok) {
602 if (status.IsOK()) {
603 m_logger->Debug(kLogXrdClHttp, "Read %s (%d bytes at offset %lld) will be served from prefetch handler", m_url.c_str(), size, static_cast<long long>(offset));
604 } else {
605 m_logger->Warning(kLogXrdClHttp, "Read %s (%d bytes at offset %lld) failed: %s", m_url.c_str(), size, static_cast<long long>(offset), status.GetErrorMessage().c_str());
606 }
607 return status;
608 } else if (m_full_download.load(std::memory_order_relaxed)) {
609 std::unique_lock lock(m_default_prefetch_handler->m_prefetch_mutex);
610 if (m_prefetch_op && m_prefetch_op->IsDone() && (static_cast<off_t>(offset) == m_prefetch_offset.load(std::memory_order_acquire))) {
611 if (handler) {
612 auto ci = new XrdCl::ChunkInfo(offset, 0, buffer);
613 auto obj = new XrdCl::AnyObject();
614 obj->Set(ci);
615 handler->HandleResponse(new XrdCl::XRootDStatus{}, obj);
616 }
617 return XrdCl::XRootDStatus{};
618 }
619 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp, 0, "Non-sequential read detected when in full-download mode");
620 }
621
622 auto ts = GetHeaderTimeout(timeout);
623 auto url = GetCurrentURL();
624 m_logger->Debug(kLogXrdClHttp, "Read %s (%d bytes at offset %lld with timeout %lld)", url.c_str(), size, static_cast<long long>(offset), static_cast<long long>(ts.tv_sec));
625
626 std::shared_ptr<XrdClHttp::CurlReadOp> readOp(
627 new XrdClHttp::CurlReadOp(
628 handler, m_default_prefetch_handler, url, ts, std::make_pair(offset, size),
629 static_cast<char*>(buffer), size, m_logger,
630 GetConnCallout(), &m_default_header_callout
631 )
632 );
633 try {
634 m_queue->Produce(std::move(readOp));
635 } catch (...) {
636 m_logger->Warning(kLogXrdClHttp, "Failed to add read op to queue");
637 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
638 }
639
640 return XrdCl::XRootDStatus();
641}

References XrdCl::errInvalidOp, XrdCl::errOSError, XrdCl::XRootDStatus::GetErrorMessage(), GetHeaderTimeout(), XrdCl::ResponseHandler::HandleResponse(), XrdCl::Status::IsOK(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, and ts().

Here is the call graph for this function:

◆ SetDefaultHeaderTimeout()

void XrdClHttp::File::SetDefaultHeaderTimeout ( struct timespec & ts)
inlinestatic

Definition at line 116 of file XrdClHttpFile.hh.

116{m_default_header_timeout.tv_sec = ts.tv_sec; m_default_header_timeout.tv_nsec = ts.tv_nsec;}

References ts().

Here is the call graph for this function:

◆ SetFederationMetadataTimeout()

void XrdClHttp::File::SetFederationMetadataTimeout ( const struct timespec & ts)
inlinestatic

Definition at line 134 of file XrdClHttpFile.hh.

134{m_fed_timeout.tv_sec = ts.tv_sec; m_fed_timeout.tv_nsec = ts.tv_nsec;}

References SetFederationMetadataTimeout(), and ts().

Referenced by SetFederationMetadataTimeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetHeaderTimeout()

void XrdClHttp::File::SetHeaderTimeout ( const struct timespec & ts)
inline

Definition at line 122 of file XrdClHttpFile.hh.

122{m_header_timeout.tv_sec = ts.tv_sec; m_header_timeout.tv_nsec = ts.tv_nsec;}

References ts().

Here is the call graph for this function:

◆ SetMinimumHeaderTimeout()

void XrdClHttp::File::SetMinimumHeaderTimeout ( struct timespec & ts)
inlinestatic

Definition at line 110 of file XrdClHttpFile.hh.

110{m_min_client_timeout.tv_sec = ts.tv_sec; m_min_client_timeout.tv_nsec = ts.tv_nsec;}

References ts().

Here is the call graph for this function:

◆ SetProperty()

bool File::SetProperty ( const std::string & name,
const std::string & value )
overridevirtual
See also
XrdCl::File::SetProperty

Reimplemented from XrdCl::FilePlugIn.

Definition at line 1001 of file XrdClHttpFile.cc.

1003{
1004 if (name == "XrdClHttpHeaderCallout") {
1005 long long pointer;
1006 try {
1007 pointer = std::stoll(value, nullptr, 16);
1008 } catch (...) {
1009 pointer = 0;
1010 }
1011 m_header_callout.store(reinterpret_cast<XrdClHttp::HeaderCallout*>(pointer), std::memory_order_release);
1012 } else if (name == "XrdClHttpFullDownload") {
1013 if (value == "true") {
1014 auto prefetch_handler = m_default_prefetch_handler;
1015 if (prefetch_handler) {
1016 std::unique_lock lock(prefetch_handler->m_prefetch_mutex);
1017 prefetch_handler->m_prefetch_enabled.store(true, std::memory_order_relaxed);
1018 }
1019 m_full_download.store(true, std::memory_order_relaxed);
1020 }
1021 }
1022
1023 std::unique_lock lock(m_properties_mutex);
1024
1025 m_properties[name] = value;
1026 if (name == "LastURL") {
1027 m_last_url = value;
1028 m_url_current = "";
1029 }
1030 else if (name == "XrdClHttpQueryParam") {
1031 CalculateCurrentURL(value);
1032 }
1033 else if (name == "XrdClHttpMaintenancePeriod") {
1034 unsigned period;
1035 auto ec = std::from_chars(value.c_str(), value.c_str() + value.size(), period);
1036 if ((ec.ec == std::errc()) && (ec.ptr == value.c_str() + value.size()) && period > 0) {
1037 m_logger->Debug(kLogXrdClHttp, "Setting maintenance period to %u", period);
1039 }
1040 }
1041 else if (name == "XrdClHttpStallTimeout") {
1042 std::string errmsg;
1043 timespec ts;
1044 if (!ParseTimeout(value, ts, errmsg)) {
1045 m_logger->Debug(kLogXrdClHttp, "Failed to parse timeout value (%s): %s", value.c_str(), errmsg.c_str());
1046 } else {
1047 CurlOperation::SetStallTimeout(std::chrono::seconds{ts.tv_sec} + std::chrono::nanoseconds{ts.tv_nsec});
1048 }
1049 }
1050 else if (name == "XrdClHttpPrefetchSize") {
1051 off_t size;
1052 auto ec = std::from_chars(value.c_str(), value.c_str() + value.size(), size);
1053 if ((ec.ec == std::errc()) && (ec.ptr == value.c_str() + value.size())) {
1054 lock.unlock();
1055 std::unique_lock lock2(m_default_prefetch_handler->m_prefetch_mutex);
1056 m_prefetch_size = size;
1057 } else {
1058 m_logger->Debug(kLogXrdClHttp, "XrdClHttpPrefetchSize value (%s) was not parseable", value.c_str());
1059 }
1060 }
1061 return true;
1062}
static void SetStallTimeout(int stall_interval)
static void SetMaintenancePeriod(unsigned maint)

References ec, XrdClHttp::kLogXrdClHttp, XrdClHttp::ParseTimeout(), XrdClHttp::CurlWorker::SetMaintenancePeriod(), XrdClHttp::CurlOperation::SetStallTimeout(), and ts().

Here is the call graph for this function:

◆ Stat()

XrdCl::XRootDStatus File::Stat ( bool force,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Stat

Reimplemented from XrdCl::FilePlugIn.

Definition at line 457 of file XrdClHttpFile.cc.

460{
461 if (!m_is_opened) {
462 m_logger->Error(kLogXrdClHttp, "Cannot stat. URL isn't open");
463 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
464 }
465
466 std::string content_length_str;
467 int64_t content_length;
468 if (!GetProperty("ContentLength", content_length_str)) {
469 m_logger->Error(kLogXrdClHttp, "Content length missing for %s", m_url.c_str());
470 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
471 }
472 try {
473 content_length = std::stoll(content_length_str);
474 } catch (...) {
475 m_logger->Error(kLogXrdClHttp, "Content length not an integer for %s", m_url.c_str());
476 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
477 }
478 if (content_length < 0) {
479 m_logger->Error(kLogXrdClHttp, "Content length negative for %s", m_url.c_str());
480 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidResponse);
481 }
482
483 m_logger->Debug(kLogXrdClHttp, "Successful stat operation on %s (size %lld)", m_url.c_str(), static_cast<long long>(content_length));
484 auto stat_info = new XrdCl::StatInfo("nobody", content_length,
486 auto obj = new XrdCl::AnyObject();
487 obj->Set(stat_info);
488
489 handler->HandleResponse(new XrdCl::XRootDStatus(), obj);
490 return XrdCl::XRootDStatus();
491}
@ IsReadable
Read access is allowed.
const uint16_t errInvalidResponse

References XrdCl::errInvalidOp, XrdCl::errInvalidResponse, GetProperty(), XrdCl::ResponseHandler::HandleResponse(), XrdCl::StatInfo::IsReadable, XrdClHttp::kLogXrdClHttp, and XrdCl::stError.

Here is the call graph for this function:

◆ VectorRead()

XrdCl::XRootDStatus File::VectorRead ( const XrdCl::ChunkList & chunks,
void * buffer,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::VectorRead

Reimplemented from XrdCl::FilePlugIn.

Definition at line 755 of file XrdClHttpFile.cc.

759{
760 if (!m_is_opened) {
761 m_logger->Error(kLogXrdClHttp, "Cannot do vector read: URL isn't open");
762 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
763 } else if (m_full_download.load(std::memory_order_relaxed)) {
764 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp, 0, "Only sequential reads are supported when in full-download mode");
765 }
766 if (chunks.empty()) {
767 if (handler) {
768 auto status = new XrdCl::XRootDStatus();
769 auto vr = std::make_unique<XrdCl::VectorReadInfo>();
770 vr->SetSize(0);
771 auto obj = new XrdCl::AnyObject();
772 obj->Set(vr.release());
773 handler->HandleResponse(status, obj);
774 }
775 return XrdCl::XRootDStatus();
776 }
777
778 auto ts = GetHeaderTimeout(timeout);
779 auto url = GetCurrentURL();
780 m_logger->Debug(kLogXrdClHttp, "Read %s (%lld chunks; first chunk is %u bytes at offset %lld with timeout %lld)", url.c_str(), static_cast<long long>(chunks.size()), static_cast<unsigned>(chunks[0].GetLength()), static_cast<long long>(chunks[0].GetOffset()), static_cast<long long>(ts.tv_sec));
781
782 std::shared_ptr<XrdClHttp::CurlVectorReadOp> readOp(
783 new XrdClHttp::CurlVectorReadOp(
784 handler, url, ts, chunks, m_logger, GetConnCallout(), &m_default_header_callout
785 )
786 );
787 try {
788 m_queue->Produce(std::move(readOp));
789 } catch (...) {
790 m_logger->Warning(kLogXrdClHttp, "Failed to add vector read op to queue");
791 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
792 }
793
794 return XrdCl::XRootDStatus();
795}

References XrdCl::errInvalidOp, XrdCl::errOSError, GetHeaderTimeout(), XrdCl::ResponseHandler::HandleResponse(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, and ts().

Here is the call graph for this function:

◆ Write() [1/2]

XrdCl::XRootDStatus File::Write ( uint64_t offset,
uint32_t size,
const void * buffer,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Write

Reimplemented from XrdCl::FilePlugIn.

Definition at line 798 of file XrdClHttpFile.cc.

803{
804 if (!m_is_opened) {
805 m_logger->Error(kLogXrdClHttp, "Cannot write: URL isn't open");
806 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
807 } else if (m_full_download.load(std::memory_order_relaxed)) {
808 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp, 0, "Only sequential reads are supported when in full-download mode");
809 }
810 m_default_prefetch_handler->DisablePrefetch();
811
812 auto ts = GetHeaderTimeout(timeout);
813 auto url = GetCurrentURL();
814 m_logger->Debug(kLogXrdClHttp, "Write %s (%d bytes at offset %lld with timeout %lld)", url.c_str(), size, static_cast<long long>(offset), static_cast<long long>(ts.tv_sec));
815
816 auto handler_wrapper = m_put_handler.load(std::memory_order_relaxed);
817 if (!handler_wrapper) {
818 handler_wrapper = new PutResponseHandler(handler);
819 PutResponseHandler *expected_value = nullptr;
820 if (!m_put_handler.compare_exchange_strong(expected_value, handler_wrapper, std::memory_order_acq_rel)) {
821 delete handler_wrapper;
822 return expected_value->QueueWrite(std::make_pair(buffer, size), handler);
823 }
824
825 if (offset != 0) {
826 m_put_handler.store(nullptr, std::memory_order_release);
827 delete handler_wrapper;
828 m_logger->Warning(kLogXrdClHttp, "Cannot start PUT operation at non-zero offset");
829 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidArgs, 0, "HTTP uploads must start at offset 0");
830 }
831 m_put_op.reset(new XrdClHttp::CurlPutOp(
832 handler_wrapper, m_default_put_handler, url, static_cast<const char*>(buffer), size, ts, m_logger,
833 GetConnCallout(), &m_default_header_callout
834 ));
835 handler_wrapper->SetOp(m_put_op);
836 m_put_offset.fetch_add(size, std::memory_order_acq_rel);
837 try {
838 m_queue->Produce(m_put_op);
839 } catch (...) {
840 m_put_handler.store(nullptr, std::memory_order_release);
841 delete handler_wrapper;
842 m_logger->Warning(kLogXrdClHttp, "Failed to add put op to queue");
843 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
844 }
845 return XrdCl::XRootDStatus();
846 }
847
848 auto old_offset = m_put_offset.fetch_add(size, std::memory_order_acq_rel);
849 if (static_cast<off_t>(offset) != old_offset) {
850 m_put_offset.fetch_sub(size, std::memory_order_acq_rel);
851 m_logger->Warning(kLogXrdClHttp, "Requested write offset at %lld does not match current file descriptor offset at %lld",
852 static_cast<long long>(offset), static_cast<long long>(old_offset));
853 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidArgs, 0, "Requested write offset does not match current offset");
854 }
855 return handler_wrapper->QueueWrite(std::make_pair(buffer, size), handler);
856}

References XrdCl::errInvalidArgs, XrdCl::errInvalidOp, XrdCl::errOSError, GetHeaderTimeout(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, and ts().

Here is the call graph for this function:

◆ Write() [2/2]

XrdCl::XRootDStatus File::Write ( uint64_t offset,
XrdCl::Buffer && buffer,
XrdCl::ResponseHandler * handler,
time_t timeout )
overridevirtual
See also
XrdCl::File::Write

Reimplemented from XrdCl::FilePlugIn.

Definition at line 859 of file XrdClHttpFile.cc.

863{
864 if (!m_is_opened) {
865 m_logger->Error(kLogXrdClHttp, "Cannot write: URL isn't open");
866 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidOp);
867 }
868 m_default_prefetch_handler->DisablePrefetch();
869
870 auto ts = GetHeaderTimeout(timeout);
871 auto url = GetCurrentURL();
872 m_logger->Debug(kLogXrdClHttp, "Write %s (%d bytes at offset %lld with timeout %lld)", url.c_str(), static_cast<int>(buffer.GetSize()), static_cast<long long>(offset), static_cast<long long>(ts.tv_sec));
873
874 auto handler_wrapper = m_put_handler.load(std::memory_order_relaxed);
875 if (!handler_wrapper) {
876 handler_wrapper = new PutResponseHandler(handler);
877 PutResponseHandler *expected_value = nullptr;
878 if (!m_put_handler.compare_exchange_strong(expected_value, handler_wrapper, std::memory_order_acq_rel)) {
879 delete handler_wrapper;
880 return expected_value->QueueWrite(std::move(buffer), handler);
881 }
882
883 if (offset != 0) {
884 m_put_handler.store(nullptr, std::memory_order_release);
885 delete handler_wrapper;
886 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidArgs, 0, "HTTP uploads must start at offset 0");
887 }
888 m_put_op.reset(new XrdClHttp::CurlPutOp(
889 handler_wrapper, m_default_put_handler, url, std::move(buffer), ts, m_logger,
890 GetConnCallout(), &m_default_header_callout
891 ));
892 handler_wrapper->SetOp(m_put_op);
893 m_put_offset.fetch_add(buffer.GetSize(), std::memory_order_acq_rel);
894 try {
895 m_queue->Produce(m_put_op);
896 } catch (...) {
897 m_put_handler.store(nullptr, std::memory_order_release);
898 delete handler_wrapper;
899 m_logger->Warning(kLogXrdClHttp, "Failed to add put op to queue");
900 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errOSError);
901 }
902 return XrdCl::XRootDStatus();
903 }
904
905 auto old_offset = m_put_offset.fetch_add(buffer.GetSize(), std::memory_order_acq_rel);
906 if (static_cast<off_t>(offset) != old_offset) {
907 m_put_offset.fetch_sub(buffer.GetSize(), std::memory_order_acq_rel);
908 m_logger->Warning(kLogXrdClHttp, "Requested write offset at %lld does not match current file descriptor offset at %lld",
909 static_cast<long long>(offset), static_cast<long long>(old_offset));
910 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidArgs, 0, "Requested write offset does not match current offset");
911 }
912 return handler_wrapper->QueueWrite(std::move(buffer), handler);
913}
uint32_t GetSize() const
Get the size of the message.

References XrdCl::errInvalidArgs, XrdCl::errInvalidOp, XrdCl::errOSError, GetHeaderTimeout(), XrdClHttp::kLogXrdClHttp, XrdCl::stError, and ts().

Here is the call graph for this function:

The documentation for this class was generated from the following files: