CMS 3D CMS Logo

XrdRequest.cc
Go to the documentation of this file.
1 
2 #include <atomic>
3 #include <iostream>
4 
6 
7 #include "XrdRequest.h"
8 #include "XrdRequestManager.h"
9 
10 using namespace XrdAdaptor;
11 
12 // If you define XRD_FAKE_ERROR, 1/5 read requests should fail.
13 #ifdef XRD_FAKE_ERROR
14 #define FAKE_ERROR_COUNTER 5
15 static std::atomic<int> g_fakeError{0};
16 #else
17 #define FAKE_ERROR_COUNTER 0
18 static std::atomic<int> g_fakeError{0};
19 #endif
20 
22 
23 void XrdAdaptor::ClientRequest::HandleResponse(XrdCl::XRootDStatus *stat, XrdCl::AnyObject *resp) {
24  std::unique_ptr<XrdCl::AnyObject> response(resp);
25  std::unique_ptr<XrdCl::XRootDStatus> status(stat);
26  std::shared_ptr<ClientRequest> self_ref = self_reference();
27  m_self_reference = nullptr; // propagate_const<T> has no reset() function
28  {
30  m_qmw.swap(qmw);
31  }
32  m_stats = nullptr; // propagate_const<T> has no reset() function
33 
34  if ((!FAKE_ERROR_COUNTER || ((++g_fakeError % FAKE_ERROR_COUNTER) != 0)) && (status->IsOK() && resp)) {
35  if (m_into) {
36  XrdCl::ChunkInfo *read_info;
37  response->Get(read_info);
38  if (read_info == nullptr) {
40  ex << "nullptr returned from response->Get().";
41  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called.");
42  m_promise.set_exception(std::make_exception_ptr(ex));
43  return;
44  }
45  if (read_info->length == 0) {
46  edm::LogWarning("XrdAdaptorInternal")
47  << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n " << m_manager.getFilename()
48  << "\n received a read_info->length = 0 and read_info->offset = " << read_info->offset;
49  }
50  m_promise.set_value(read_info->length);
51  } else {
52  XrdCl::VectorReadInfo *read_info;
53  response->Get(read_info);
54  if (read_info == nullptr) {
56  ex << "nullptr returned from response->Get() from vector read.";
57  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called.");
58  m_promise.set_exception(std::make_exception_ptr(ex));
59  return;
60  }
61  if (read_info->GetSize() == 0) {
62  edm::LogWarning("XrdAdaptorInternal") << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n "
63  << m_manager.getFilename() << "\n received a read_info->GetSize() = 0";
64  }
65 
66  m_promise.set_value(read_info->GetSize());
67  }
68  } else {
69  Source *source = m_source.get();
70  edm::LogWarning("XrdAdaptorInternal")
71  << "XrdRequestManager::handle(name='" << m_manager.getFilename() << ") failure when reading from "
72  << (source ? source->PrettyID() : "(unknown source)") << "; failed with error '" << status->ToStr()
73  << "' (errno=" << status->errNo << ", code=" << status->code << ").";
74  m_failure_count++;
75  try {
76  try {
77  m_manager.requestFailure(self_ref, *status);
78  return;
79  } catch (XrootdException &ex) {
80  if (ex.getCode() == XrdCl::errInvalidResponse) {
81  m_promise.set_exception(std::current_exception());
82  } else
83  throw;
84  }
85  } catch (edm::Exception &ex) {
86  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() failure while running connection recovery");
87  std::stringstream ss;
88  ss << "Original error: '" << status->ToStr() << "' (errno=" << status->errNo << ", code=" << status->code
89  << ", source=" << (source ? source->PrettyID() : "(unknown source)") << ").";
90  ex.addAdditionalInfo(ss.str());
91  m_promise.set_exception(std::current_exception());
92  edm::LogWarning("XrdAdaptorInternal") << "Caught a CMSSW exception when running connection recovery.";
93  } catch (std::exception const &) {
95  ex << "XrdRequestManager::handle(name='" << m_manager.getFilename() << ") failed with error '" << status->ToStr()
96  << "' (errno=" << status->errNo << ", code=" << status->code << "). Unknown exception occurred when running"
97  << " connection recovery.";
98  ex.addContext("Calling XrdRequestManager::handle()");
99  m_manager.addConnections(ex);
100  ex.addAdditionalInfo("Original source of error is " + (source ? source->PrettyID() : "(unknown source)"));
101  m_promise.set_exception(std::make_exception_ptr(ex));
102  edm::LogWarning("XrdAdaptorInternal") << "Caught a new exception when running connection recovery.";
103  }
104  }
105 }
FAKE_ERROR_COUNTER
#define FAKE_ERROR_COUNTER
Definition: XrdRequest.cc:17
XrdAdaptor::ClientRequest::~ClientRequest
~ClientRequest() override
Definition: XrdRequest.cc:21
MessageLogger.h
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
mps_update.status
status
Definition: mps_update.py:69
g_fakeError
static std::atomic< int > g_fakeError
Definition: XrdRequest.cc:18
XrdAdaptor::XrootdException::getCode
uint16_t getCode()
Definition: XrdRequestManager.h:38
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Exception
Definition: EDMException.h:77
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
XrdAdaptor::QualityMetricWatch
Definition: QualityMetric.h:20
source
static const std::string source
Definition: EdmProvDump.cc:47
XrdAdaptor::ClientRequest::HandleResponse
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:23
XrdRequestManager.h
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
XrdRequest.h
cms::Exception::addAdditionalInfo
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
XrdAdaptor::Source
Definition: XrdSource.h:23
XrdAdaptor::QualityMetricWatch::swap
void swap(QualityMetricWatch &)
Definition: QualityMetric.cc:55
XrdAdaptor::XrootdException
Definition: XrdRequestManager.h:31
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
edm::errors::FileReadError
Definition: EDMException.h:50
XrdAdaptor
Definition: QualityMetric.h:14