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
24 XrdAdaptor::ClientRequest::HandleResponse(XrdCl::XRootDStatus *stat, XrdCl::AnyObject *resp)
25 {
26  std::unique_ptr<XrdCl::AnyObject> response(resp);
27  std::unique_ptr<XrdCl::XRootDStatus> status(stat);
28  std::shared_ptr<ClientRequest> self_ref = self_reference();
29  m_self_reference = nullptr; // propagate_const<T> has no reset() function
30  {
32  m_qmw.swap(qmw);
33  }
34  m_stats = nullptr; // propagate_const<T> has no reset() function
35 
36  if ((!FAKE_ERROR_COUNTER || ((++g_fakeError % FAKE_ERROR_COUNTER) != 0)) && (status->IsOK() && resp))
37  {
38  if (m_into)
39  {
40  XrdCl::ChunkInfo *read_info;
41  response->Get(read_info);
42  if( read_info == nullptr) {
44  ex<<"nullptr returned from response->Get().";
45  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called." );
46  m_promise.set_exception( std::make_exception_ptr(ex));
47  return;
48  }
49  if( read_info->length == 0) {edm::LogWarning("XrdAdaptorInternal") << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n "
50  << m_manager.getFilename() << "\n received a read_info->length = 0 and read_info->offset = "<<read_info->offset;
51  }
52  m_promise.set_value(read_info->length);
53  }
54  else
55  {
56  XrdCl::VectorReadInfo *read_info;
57  response->Get(read_info);
58  if( read_info == nullptr) {
60  ex<<"nullptr returned from response->Get() from vector read.";
61  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called." );
62  m_promise.set_exception( std::make_exception_ptr(ex));
63  return;
64  }
65  if( read_info->GetSize() == 0) {edm::LogWarning("XrdAdaptorInternal") << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n "
66  << m_manager.getFilename() << "\n received a read_info->GetSize() = 0";
67  }
68 
69  m_promise.set_value(read_info->GetSize());
70  }
71  }
72  else
73  {
74  Source *source = m_source.get();
75  edm::LogWarning("XrdAdaptorInternal") << "XrdRequestManager::handle(name='"
76  << m_manager.getFilename() << ") failure when reading from "
77  << (source ? source->PrettyID() : "(unknown source)")
78  << "; failed with error '" << status->ToStr() << "' (errno="
79  << status->errNo << ", code=" << status->code << ").";
80  m_failure_count++;
81  try
82  {
83  try
84  {
85  m_manager.requestFailure(self_ref, *status);
86  return;
87  }
88  catch (XrootdException& ex)
89  {
90  if (ex.getCode() == XrdCl::errInvalidResponse)
91  {
92  m_promise.set_exception(std::current_exception());
93  }
94  else throw;
95  }
96  }
97  catch (edm::Exception& ex)
98  {
99  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() failure while running connection recovery");
100  std::stringstream ss;
101  ss << "Original error: '" << status->ToStr() << "' (errno="
102  << status->errNo << ", code=" << status->code << ", source=" << (source ? source->PrettyID() : "(unknown source)") << ").";
103  ex.addAdditionalInfo(ss.str());
104  m_promise.set_exception(std::current_exception());
105  edm::LogWarning("XrdAdaptorInternal") << "Caught a CMSSW exception when running connection recovery.";
106  }
107  catch (std::exception)
108  {
110  ex << "XrdRequestManager::handle(name='" << m_manager.getFilename()
111  << ") failed with error '" << status->ToStr()
112  << "' (errno=" << status->errNo << ", code="
113  << status->code << "). Unknown exception occurred when running"
114  << " connection recovery.";
115  ex.addContext("Calling XrdRequestManager::handle()");
116  m_manager.addConnections(ex);
117  ex.addAdditionalInfo("Original source of error is " + (source ? source->PrettyID() : "(unknown source)"));
118  m_promise.set_exception(std::make_exception_ptr(ex));
119  edm::LogWarning("XrdAdaptorInternal") << "Caught a new exception when running connection recovery.";
120  }
121  }
122 }
123 
const std::string & PrettyID() const
Definition: XrdSource.h:39
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
void addContext(std::string const &context)
Definition: Exception.cc:227
void swap(QualityMetricWatch &)
#define FAKE_ERROR_COUNTER
Definition: XrdRequest.cc:17
static std::string const source
Definition: EdmProvDump.cc:43
static std::atomic< int > g_fakeError
Definition: XrdRequest.cc:18
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:24