Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:09

0001 
0002 #include <atomic>
0003 #include <iostream>
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "XrdRequest.h"
0008 #include "XrdRequestManager.h"
0009 
0010 using namespace XrdAdaptor;
0011 
0012 // If you define XRD_FAKE_ERROR, 1/5 read requests should fail.
0013 #ifdef XRD_FAKE_ERROR
0014 #define FAKE_ERROR_COUNTER 5
0015 static std::atomic<int> g_fakeError{0};
0016 #else
0017 #define FAKE_ERROR_COUNTER 0
0018 static std::atomic<int> g_fakeError{0};
0019 #endif
0020 
0021 XrdAdaptor::ClientRequest::~ClientRequest() {}
0022 
0023 void XrdAdaptor::ClientRequest::HandleResponse(XrdCl::XRootDStatus *stat, XrdCl::AnyObject *resp) {
0024   std::unique_ptr<XrdCl::AnyObject> response(resp);
0025   std::unique_ptr<XrdCl::XRootDStatus> status(stat);
0026   std::shared_ptr<ClientRequest> self_ref = self_reference();
0027   m_self_reference = nullptr;  // propagate_const<T> has no reset() function
0028   {
0029     QualityMetricWatch qmw;
0030     m_qmw.swap(qmw);
0031   }
0032   m_stats = nullptr;  // propagate_const<T> has no reset() function
0033 
0034   if ((!FAKE_ERROR_COUNTER || ((++g_fakeError % FAKE_ERROR_COUNTER) != 0)) && (status->IsOK() && resp)) {
0035     if (m_into) {
0036       XrdCl::ChunkInfo *read_info;
0037       response->Get(read_info);
0038       if (read_info == nullptr) {
0039         edm::Exception ex(edm::errors::FileReadError);
0040         ex << "nullptr returned from response->Get().";
0041         ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called.");
0042         m_promise.set_exception(std::make_exception_ptr(ex));
0043         return;
0044       }
0045       if (read_info->length == 0) {
0046         edm::LogWarning("XrdAdaptorInternal")
0047             << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n " << m_manager.getFilename()
0048             << "\n  received a read_info->length = 0 and read_info->offset = " << read_info->offset;
0049       }
0050       m_promise.set_value(read_info->length);
0051     } else {
0052       XrdCl::VectorReadInfo *read_info;
0053       response->Get(read_info);
0054       if (read_info == nullptr) {
0055         edm::Exception ex(edm::errors::FileReadError);
0056         ex << "nullptr returned from response->Get() from vector read.";
0057         ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() called.");
0058         m_promise.set_exception(std::make_exception_ptr(ex));
0059         return;
0060       }
0061       if (read_info->GetSize() == 0) {
0062         edm::LogWarning("XrdAdaptorInternal") << "XrdAdaptor::ClientRequest::HandleResponse: While reading from\n "
0063                                               << m_manager.getFilename() << "\n  received a read_info->GetSize() = 0";
0064       }
0065 
0066       m_promise.set_value(read_info->GetSize());
0067     }
0068   } else {
0069     Source *source = m_source.get();
0070     edm::LogWarning("XrdAdaptorInternal")
0071         << "XrdRequestManager::handle(name='" << m_manager.getFilename() << ") failure when reading from "
0072         << (source ? source->PrettyID() : "(unknown source)") << "; failed with error '" << status->ToStr()
0073         << "' (errno=" << status->errNo << ", code=" << status->code << ").";
0074     m_failure_count++;
0075     try {
0076       try {
0077         m_manager.requestFailure(self_ref, *status);
0078         return;
0079       } catch (XrootdException &ex) {
0080         if (ex.getCode() == XrdCl::errInvalidResponse) {
0081           m_promise.set_exception(std::current_exception());
0082         } else
0083           throw;
0084       }
0085     } catch (edm::Exception &ex) {
0086       ex.addContext("XrdAdaptor::ClientRequest::HandleResponse() failure while running connection recovery");
0087       std::stringstream ss;
0088       ss << "Original error: '" << status->ToStr() << "' (errno=" << status->errNo << ", code=" << status->code
0089          << ", source=" << (source ? source->PrettyID() : "(unknown source)") << ").";
0090       ex.addAdditionalInfo(ss.str());
0091       m_promise.set_exception(std::current_exception());
0092       edm::LogWarning("XrdAdaptorInternal") << "Caught a CMSSW exception when running connection recovery.";
0093     } catch (std::exception const &) {
0094       edm::Exception ex(edm::errors::FileReadError);
0095       ex << "XrdRequestManager::handle(name='" << m_manager.getFilename() << ") failed with error '" << status->ToStr()
0096          << "' (errno=" << status->errNo << ", code=" << status->code << ").  Unknown exception occurred when running"
0097          << " connection recovery.";
0098       ex.addContext("Calling XrdRequestManager::handle()");
0099       m_manager.addConnections(ex);
0100       ex.addAdditionalInfo("Original source of error is " + (source ? source->PrettyID() : "(unknown source)"));
0101       m_promise.set_exception(std::make_exception_ptr(ex));
0102       edm::LogWarning("XrdAdaptorInternal") << "Caught a new exception when running connection recovery.";
0103     }
0104   }
0105 }