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 <iostream>
3 
5 
6 #include "XrdRequest.h"
7 #include "XrdRequestManager.h"
8 
9 using namespace XrdAdaptor;
10 
11 // If you define XRD_FAKE_ERROR, 1/5 read requests should fail.
12 #ifdef XRD_FAKE_ERROR
13 #define FAKE_ERROR_COUNTER 5
14 int g_fakeError = 0;
15 #else
16 #define FAKE_ERROR_COUNTER 0
17 int g_fakeError = 0;
18 #endif
19 
21 
22 void
23 XrdAdaptor::ClientRequest::HandleResponse(XrdCl::XRootDStatus *stat, XrdCl::AnyObject *resp)
24 {
25  std::unique_ptr<XrdCl::AnyObject> response(resp);
26  std::unique_ptr<XrdCl::XRootDStatus> status(stat);
27  std::shared_ptr<ClientRequest> self_ref = m_self_reference;
28  m_self_reference.reset();
29  {
31  m_qmw.swap(qmw);
32  }
33  m_stats.reset();
34 
35  if ((!FAKE_ERROR_COUNTER || ((++g_fakeError % FAKE_ERROR_COUNTER) != 0)) && (status->IsOK() && resp))
36  {
37  if (m_into)
38  {
39  XrdCl::ChunkInfo *read_info;
40  response->Get(read_info);
41  m_promise.set_value(read_info->length);
42  }
43  else
44  {
45  XrdCl::VectorReadInfo *read_info;
46  response->Get(read_info);
47  m_promise.set_value(read_info->GetSize());
48  }
49  }
50  else
51  {
52  Source *source = m_source.get();
53  edm::LogWarning("XrdAdaptorInternal") << "XrdRequestManager::handle(name='"
54  << m_manager.getFilename() << ") failure when reading from "
55  << (source ? source->PrettyID() : "(unknown source)")
56  << "; failed with error '" << status->ToStr() << "' (errno="
57  << status->errNo << ", code=" << status->code << ").";
58  m_failure_count++;
59  try
60  {
61  try
62  {
63  m_manager.requestFailure(self_ref, *status);
64  return;
65  }
66  catch (XrootdException& ex)
67  {
68  if (ex.getCode() == XrdCl::errInvalidResponse)
69  {
70  m_promise.set_exception(std::current_exception());
71  }
72  else throw;
73  }
74  }
75  catch (edm::Exception& ex)
76  {
77  ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() failure while running connection recovery");
78  std::stringstream ss;
79  ss << "Original error: '" << status->ToStr() << "' (errno="
80  << status->errNo << ", code=" << status->code << ", source=" << (source ? source->PrettyID() : "(unknown source)") << ").";
81  ex.addAdditionalInfo(ss.str());
82  m_promise.set_exception(std::current_exception());
83  edm::LogWarning("XrdAdaptorInternal") << "Caught a CMSSW exception when running connection recovery.";
84  }
85  catch (...)
86  {
88  ex << "XrdRequestManager::handle(name='" << m_manager.getFilename()
89  << ") failed with error '" << status->ToStr()
90  << "' (errno=" << status->errNo << ", code="
91  << status->code << "). Unknown exception occurred when running"
92  << " connection recovery.";
93  ex.addContext("Calling XrdRequestManager::handle()");
94  m_manager.addConnections(ex);
95  ex.addAdditionalInfo("Original source of error is " + (source ? source->PrettyID() : "(unknown source)"));
96  m_promise.set_exception(std::make_exception_ptr(ex));
97  edm::LogWarning("XrdAdaptorInternal") << "Caught a new exception when running connection recovery.";
98  }
99  }
100 }
101 
const std::string & PrettyID() const
Definition: XrdSource.h:37
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
void addContext(std::string const &context)
Definition: Exception.cc:227
int g_fakeError
Definition: XrdRequest.cc:17
void swap(QualityMetricWatch &)
#define FAKE_ERROR_COUNTER
Definition: XrdRequest.cc:16
tuple status
Definition: ntuplemaker.py:245
static std::string const source
Definition: EdmProvDump.cc:42
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
Definition: XrdRequest.cc:23