xrootd
XrdClFileStateHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_FILE_STATE_HANDLER_HH__
20 #define __XRD_CL_FILE_STATE_HANDLER_HH__
21 
24 #include "XrdCl/XrdClFileSystem.hh"
26 #include "XrdSys/XrdSysPthread.hh"
27 #include <list>
28 #include <set>
29 
30 namespace XrdCl
31 {
32  class Message;
33 
34  //----------------------------------------------------------------------------
36  //----------------------------------------------------------------------------
38  {
39  public:
40  //------------------------------------------------------------------------
42  //------------------------------------------------------------------------
44  {
51  };
52 
53  //------------------------------------------------------------------------
55  //------------------------------------------------------------------------
57 
58  //------------------------------------------------------------------------
60  //------------------------------------------------------------------------
62 
63  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
74  XRootDStatus Open( const std::string &url,
75  uint16_t flags,
76  uint16_t mode,
77  ResponseHandler *handler,
78  uint16_t timeout = 0 );
79 
80  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
89  uint16_t timeout = 0 );
90 
91  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  XRootDStatus Stat( bool force,
103  ResponseHandler *handler,
104  uint16_t timeout = 0 );
105 
106 
107  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  XRootDStatus Read( uint64_t offset,
124  uint32_t size,
125  void *buffer,
126  ResponseHandler *handler,
127  uint16_t timeout = 0 );
128 
129  //------------------------------------------------------------------------
139  //------------------------------------------------------------------------
140  XRootDStatus Write( uint64_t offset,
141  uint32_t size,
142  const void *buffer,
143  ResponseHandler *handler,
144  uint16_t timeout = 0 );
145 
146 
147  //------------------------------------------------------------------------
154  //------------------------------------------------------------------------
156  uint16_t timeout = 0 );
157 
158  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  XRootDStatus Truncate( uint64_t size,
168  ResponseHandler *handler,
169  uint16_t timeout = 0 );
170 
171  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
181  XRootDStatus VectorRead( const ChunkList &chunks,
182  void *buffer,
183  ResponseHandler *handler,
184  uint16_t timeout = 0 );
185 
186  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  void OnOpen( const XRootDStatus *status,
190  const OpenInfo *openInfo,
191  const HostList *hostList );
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  void OnClose( const XRootDStatus *status );
197 
198  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  void OnStateError( XRootDStatus *status,
202  Message *message,
203  ResponseHandler *userHandler,
204  MessageSendParams &sendParams );
205 
206  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  void OnStateRedirection( RedirectInfo *redirectInfo,
210  Message *message,
211  ResponseHandler *userHandler,
212  MessageSendParams &sendParams );
213 
214  //------------------------------------------------------------------------
216  //------------------------------------------------------------------------
217  void OnStateResponse( XRootDStatus *status,
218  Message *message,
219  AnyObject *response,
220  HostList *hostList );
221 
222  //------------------------------------------------------------------------
224  //------------------------------------------------------------------------
225  bool IsOpen() const;
226 
227  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  void EnableReadRecovery( bool enable );
232 
233  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  void EnableWriteRecovery( bool enable );
238 
239  //------------------------------------------------------------------------
241  //------------------------------------------------------------------------
242  std::string GetDataServer() const;
243 
244  //------------------------------------------------------------------------
246  //------------------------------------------------------------------------
247  URL GetLastURL() const;
248 
249  //------------------------------------------------------------------------
251  //------------------------------------------------------------------------
252  void Lock()
253  {
254  pMutex.Lock();
255  }
256 
257  //------------------------------------------------------------------------
259  //------------------------------------------------------------------------
260  void UnLock()
261  {
262  pMutex.UnLock();
263  }
264 
265  //------------------------------------------------------------------------
267  //------------------------------------------------------------------------
268  void AfterForkChild();
269 
270  private:
271  //------------------------------------------------------------------------
272  // Helper for queueing messages
273  //------------------------------------------------------------------------
274  struct RequestData
275  {
278  const MessageSendParams &p ):
279  request(r), handler(h), params(p) {}
283  };
284  typedef std::list<RequestData> RequestList;
285 
286  //------------------------------------------------------------------------
288  //------------------------------------------------------------------------
289  Status SendOrQueue( const URL &url,
290  Message *msg,
291  ResponseHandler *handler,
292  MessageSendParams &sendParams );
293 
294  //------------------------------------------------------------------------
296  //------------------------------------------------------------------------
297  bool IsRecoverable( const XRootDStatus &stataus ) const;
298 
299  //------------------------------------------------------------------------
306  //------------------------------------------------------------------------
307  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
308 
309  //------------------------------------------------------------------------
311  //------------------------------------------------------------------------
313 
314  //------------------------------------------------------------------------
316  //------------------------------------------------------------------------
317  bool IsReadOnly() const;
318 
319  //------------------------------------------------------------------------
321  //------------------------------------------------------------------------
322  Status ReOpenFileAtServer( const URL &url, uint16_t timeout );
323 
324  //------------------------------------------------------------------------
326  //------------------------------------------------------------------------
327  void FailMessage( RequestData rd, XRootDStatus status );
328 
329  //------------------------------------------------------------------------
331  //------------------------------------------------------------------------
332  void FailQueuedMessages( Status status );
333 
334  //------------------------------------------------------------------------
336  //------------------------------------------------------------------------
337  void ReSendQueuedMessages();
338 
339  //------------------------------------------------------------------------
341  //------------------------------------------------------------------------
342  void ReWriteFileHandle( Message *msg );
343 
344  //------------------------------------------------------------------------
346  //------------------------------------------------------------------------
348  {
349  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
350  pRBytes = 0;
351  pVBytes = 0;
352  pWBytes = 0;
353  pVSegs = 0;
354  pRCount = 0;
355  pVCount = 0;
356  pWCount = 0;
357  pCloseReason = Status();
358  }
359 
360  //------------------------------------------------------------------------
362  //------------------------------------------------------------------------
363  void MonitorClose( const XRootDStatus *status );
364 
373  uint8_t *pFileHandle;
374  uint16_t pOpenMode;
375  uint16_t pOpenFlags;
377  std::set<Message*> pInTheFly;
378  uint64_t pSessionId;
381 
382  //------------------------------------------------------------------------
383  // Monitoring variables
384  //------------------------------------------------------------------------
385  timeval pOpenTime;
386  uint64_t pRBytes;
387  uint64_t pVBytes;
388  uint64_t pWBytes;
389  uint64_t pVSegs;
390  uint64_t pRCount;
391  uint64_t pVCount;
392  uint64_t pWCount;
394  };
395 }
396 
397 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__