CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  m_promise.set_value(read_info->length);
43  }
44  else
45  {
46  XrdCl::VectorReadInfo *read_info;
47  response->Get(read_info);
48  m_promise.set_value(read_info->GetSize());
49  }
50  }
51  else
52  {
53  Source *source = m_source.get();
54  edm::LogWarning("XrdAdaptorInternal") << "XrdRequestManager::handle(name='"
55  << m_manager.getFilename() << ") failure when reading from "
56  << (source ? source->PrettyID() : "(unknown source)")
57  << "; failed with error '" << status->ToStr() << "' (errno="
58  << status->errNo << ", code=" << status->code << ").";
59  m_failure_count++;
60  try
61  {
62  try
63  {
64  m_manager.requestFailure(self_ref, *status);
65  return;
66  }
67  catch (XrootdException& ex)
68  {
69  if (ex.getCode() == XrdCl::errInvalidResponse)
70  {
71  m_promise.set_exception(std::current_exception());
72  }
73  else throw;
74  }
75  }
76  catch (edm::Exception& ex)
77  {
78  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() failure while running connection recovery");
79  std::stringstream ss;
80  ss << "Original error: '" << status->ToStr() << "' (errno="
81  << status->errNo << ", code=" << status->code << ", source=" << (source ? source->PrettyID() : "(unknown source)") << ").";
82  ex.addAdditionalInfo(ss.str());
83  m_promise.set_exception(std::current_exception());
84  edm::LogWarning("XrdAdaptorInternal") << "Caught a CMSSW exception when running connection recovery.";
85  }
86  catch (std::exception)
87  {
89  ex << "XrdRequestManager::handle(name='" << m_manager.getFilename()
90  << ") failed with error '" << status->ToStr()
91  << "' (errno=" << status->errNo << ", code="
92  << status->code << "). Unknown exception occurred when running"
93  << " connection recovery.";
94  ex.addContext("Calling XrdRequestManager::handle()");
95  m_manager.addConnections(ex);
96  ex.addAdditionalInfo("Original source of error is " + (source ? source->PrettyID() : "(unknown source)"));
97  m_promise.set_exception(std::make_exception_ptr(ex));
98  edm::LogWarning("XrdAdaptorInternal") << "Caught a new exception when running connection recovery.";
99  }
100  }
101 }
102 
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
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:24
tuple status
Definition: mps_update.py:57