test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XrdStorageMaker.cc
Go to the documentation of this file.
1 
5 
11 
12 #include "XrdCl/XrdClDefaultEnv.hh"
13 #include "XrdNet/XrdNetUtils.hh"
14 
15 #include <atomic>
16 #include <mutex>
17 
18 class MakerResponseHandler : public XrdCl::ResponseHandler
19 {
20 public:
21  virtual void HandleResponse( XrdCl::XRootDStatus *status,
22  XrdCl::AnyObject *response )
23  {
24  // Note: Prepare call has a response object.
25  delete response;
26  delete status;
27  }
28 
29 };
30 
31 class XrdStorageMaker final : public StorageMaker
32 {
33 public:
34  static const unsigned int XRD_DEFAULT_TIMEOUT = 3*60;
35 
37  m_lastDebugLevel(1),//so that 0 will trigger change
38  m_lastTimeout(0)
39  {
40  // When CMSSW loads, both XrdCl and XrdClient end up being loaded
41  // (ROOT loads XrdClient). XrdClient forces IPv4-only. Accordingly,
42  // we must explicitly set the default network stack in XrdCl to
43  // whatever is available on the node (IPv4 or IPv6).
44  XrdCl::Env *env = XrdCl::DefaultEnv::GetEnv();
45  if (env)
46  {
47  env->PutString("NetworkStack", "IPAuto");
48  }
49  XrdNetUtils::SetAuto(XrdNetUtils::prefAuto);
51  setDebugLevel(0);
52  }
53 
56  virtual std::unique_ptr<Storage> open (const std::string &proto,
57  const std::string &path,
58  int mode,
59  const AuxSettings& aux) const override
60  {
62  setTimeout(aux.timeout);
63 
65  StorageFactory::ReadHint readHint = f->readHint();
66  StorageFactory::CacheHint cacheHint = f->cacheHint();
67 
69  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
70  mode &= ~IOFlags::OpenUnbuffered;
71  else
73 
74  std::string fullpath(proto + ":" + path);
75  auto file = std::make_unique<XrdFile>(fullpath, mode);
76  return f->wrapNonLocalFile(std::move(file), proto, std::string(), mode);
77  }
78 
79  virtual void stagein (const std::string &proto, const std::string &path,
80  const AuxSettings& aux) const override
81  {
83  setTimeout(aux.timeout);
84 
85  std::string fullpath(proto + ":" + path);
86  XrdCl::URL url(fullpath);
87  XrdCl::FileSystem fs(url);
88  std::vector<std::string> fileList; fileList.push_back(url.GetPath());
89  auto status = fs.Prepare(fileList, XrdCl::PrepareFlags::Stage, 0, &m_null_handler);
90  if (!status.IsOK())
91  {
92  edm::LogWarning("StageInError") << "XrdCl::FileSystem::Prepare failed with error '"
93  << status.ToStr() << "' (errNo = " << status.errNo << ")";
94  }
95  }
96 
97  virtual bool check (const std::string &proto,
98  const std::string &path,
99  const AuxSettings& aux,
100  IOOffset *size = 0) const override
101  {
103  setTimeout(aux.timeout);
104 
105  std::string fullpath(proto + ":" + path);
106  XrdCl::URL url(fullpath);
107  XrdCl::FileSystem fs(url);
108 
109  XrdCl::StatInfo *stat;
110  if (!(fs.Stat(url.GetPath(), stat)).IsOK() || (stat == nullptr))
111  {
112  return false;
113  }
114 
115  if (size) *size = stat->GetSize();
116  return true;
117  }
118 
119  void setDebugLevel (unsigned int level) const
120  {
121  auto oldLevel = m_lastDebugLevel.load();
122  if(level == oldLevel) {
123  return;
124  }
125  std::lock_guard<std::mutex> guard(m_envMutex);
126  if(oldLevel != m_lastDebugLevel) {
127  //another thread just changed this value
128  return;
129  }
130 
131  // 'Error' is way too low of debug level - we have interest
132  // in warning in the default
133  switch (level)
134  {
135  case 0:
136  XrdCl::DefaultEnv::SetLogLevel("Warning");
137  break;
138  case 1:
139  XrdCl::DefaultEnv::SetLogLevel("Info");
140  break;
141  case 2:
142  XrdCl::DefaultEnv::SetLogLevel("Debug");
143  break;
144  case 3:
145  XrdCl::DefaultEnv::SetLogLevel("Dump");
146  break;
147  case 4:
148  XrdCl::DefaultEnv::SetLogLevel("Dump");
149  break;
150  default:
152  ex << "Invalid log level specified " << level;
153  ex.addContext("Calling XrdStorageMaker::setDebugLevel()");
154  throw ex;
155  }
157  }
158 
159  void setTimeout(unsigned int timeout) const
160  {
161  timeout = timeout ? timeout : XRD_DEFAULT_TIMEOUT;
162 
163  auto oldTimeout = m_lastTimeout.load();
164  if (oldTimeout == timeout) {
165  return;
166  }
167 
168  std::lock_guard<std::mutex> guard(m_envMutex);
169  if (oldTimeout != m_lastTimeout) {
170  //Another thread beat us to changing the value
171  return;
172  }
173 
174  XrdCl::Env *env = XrdCl::DefaultEnv::GetEnv();
175  if (env)
176  {
177  env->PutInt("StreamTimeout", timeout);
178  env->PutInt("RequestTimeout", timeout);
179  env->PutInt("ConnectionWindow", timeout);
180  env->PutInt("StreamErrorWindow", timeout);
181  // Crank down some of the connection defaults. We have more
182  // aggressive error recovery than the default client so we
183  // can error out sooner.
184  env->PutInt("ConnectionWindow", timeout/6+1);
185  env->PutInt("ConnectionRetry", 2);
186  }
188  }
189 
190 private:
191  [[cms::thread_safe]] mutable MakerResponseHandler m_null_handler;
193  mutable std::atomic<unsigned int> m_lastDebugLevel;
194  mutable std::atomic<unsigned int> m_lastTimeout;
195 };
196 
199 
CacheHint cacheHint(void) const
std::unique_ptr< Storage > wrapNonLocalFile(std::unique_ptr< Storage > s, const std::string &proto, const std::string &path, int mode) const
std::atomic< unsigned int > m_lastDebugLevel
static boost::mutex mutex
Definition: LHEProxy.cc:11
MakerResponseHandler m_null_handler
virtual void stagein(const std::string &proto, const std::string &path, const AuxSettings &aux) const override
std::mutex m_envMutex
int timeout
Definition: mps_check.py:51
static const StorageFactory * get(void)
void setTimeout(unsigned int timeout) const
std::atomic< unsigned int > m_lastTimeout
string URL
Definition: rrClient.py:4
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
def move
Definition: eostools.py:510
double f[11][100]
virtual bool check(const std::string &proto, const std::string &path, const AuxSettings &aux, IOOffset *size=0) const override
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:113
static const unsigned int XRD_DEFAULT_TIMEOUT
ReadHint readHint(void) const
void addContext(std::string const &context)
Definition: Exception.cc:227
int64_t IOOffset
Definition: IOTypes.h:19
#define DEFINE_EDM_PLUGIN(factory, type, name)
tuple level
Definition: testEve_cfg.py:34
tuple size
Write out results.
virtual std::unique_ptr< Storage > open(const std::string &proto, const std::string &path, int mode, const AuxSettings &aux) const override
void setDebugLevel(unsigned int level) const
tuple status
Definition: mps_update.py:57