xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
XrdClFileStateHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_FILE_STATE_HANDLER_HH__
26 #define __XRD_CL_FILE_STATE_HANDLER_HH__
27 
30 #include "XrdCl/XrdClFileSystem.hh"
32 #include "XrdSys/XrdSysPthread.hh"
34 #include <list>
35 #include <set>
36 
37 #include <sys/uio.h>
38 
39 namespace XrdCl
40 {
41  class ResponseHandlerHolder;
42  class Message;
43 
44  //----------------------------------------------------------------------------
46  //----------------------------------------------------------------------------
48  {
49  public:
50  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
54  {
61  };
62 
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
67 
68  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
74  FileStateHandler( bool useVirtRedirector );
75 
76  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
80 
81  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  XRootDStatus Open( const std::string &url,
93  uint16_t flags,
94  uint16_t mode,
95  ResponseHandler *handler,
96  uint16_t timeout = 0 );
97 
98  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
107  uint16_t timeout = 0 );
108 
109  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  XRootDStatus Stat( bool force,
121  ResponseHandler *handler,
122  uint16_t timeout = 0 );
123 
124 
125  //------------------------------------------------------------------------
140  //------------------------------------------------------------------------
141  XRootDStatus Read( uint64_t offset,
142  uint32_t size,
143  void *buffer,
144  ResponseHandler *handler,
145  uint16_t timeout = 0 );
146 
147  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  XRootDStatus Write( uint64_t offset,
159  uint32_t size,
160  const void *buffer,
161  ResponseHandler *handler,
162  uint16_t timeout = 0 );
163 
164 
165  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
174  uint16_t timeout = 0 );
175 
176  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  XRootDStatus Truncate( uint64_t size,
186  ResponseHandler *handler,
187  uint16_t timeout = 0 );
188 
189  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  XRootDStatus VectorRead( const ChunkList &chunks,
200  void *buffer,
201  ResponseHandler *handler,
202  uint16_t timeout = 0 );
203 
204  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  XRootDStatus VectorWrite( const ChunkList &chunks,
214  ResponseHandler *handler,
215  uint16_t timeout = 0 );
216 
217  //------------------------------------------------------------------------
227  //------------------------------------------------------------------------
228  XRootDStatus WriteV( uint64_t offset,
229  const struct iovec *iov,
230  int iovcnt,
231  ResponseHandler *handler,
232  uint16_t timeout = 0 );
233 
234  //------------------------------------------------------------------------
245  //------------------------------------------------------------------------
246  XRootDStatus Fcntl( const Buffer &arg,
247  ResponseHandler *handler,
248  uint16_t timeout = 0 );
249 
250  //------------------------------------------------------------------------
259  //------------------------------------------------------------------------
261  uint16_t timeout = 0 );
262 
263  //------------------------------------------------------------------------
265  //------------------------------------------------------------------------
266  void OnOpen( const XRootDStatus *status,
267  const OpenInfo *openInfo,
268  const HostList *hostList );
269 
270  //------------------------------------------------------------------------
272  //------------------------------------------------------------------------
273  void OnClose( const XRootDStatus *status );
274 
275  //------------------------------------------------------------------------
277  //------------------------------------------------------------------------
278  void OnStateError( XRootDStatus *status,
279  Message *message,
280  ResponseHandler *userHandler,
281  MessageSendParams &sendParams );
282 
283  //------------------------------------------------------------------------
285  //------------------------------------------------------------------------
286  void OnStateRedirection( const std::string &redirectUrl,
287  Message *message,
288  ResponseHandler *userHandler,
289  MessageSendParams &sendParams );
290 
291  //------------------------------------------------------------------------
293  //------------------------------------------------------------------------
294  void OnStateResponse( XRootDStatus *status,
295  Message *message,
296  AnyObject *response,
297  HostList *hostList );
298 
299  //------------------------------------------------------------------------
301  //------------------------------------------------------------------------
302  bool IsOpen() const;
303 
304  //------------------------------------------------------------------------
308  //------------------------------------------------------------------------
309  bool SetProperty( const std::string &name, const std::string &value );
310 
311  //------------------------------------------------------------------------
315  //------------------------------------------------------------------------
316  bool GetProperty( const std::string &name, std::string &value ) const;
317 
318  //------------------------------------------------------------------------
320  //------------------------------------------------------------------------
321  void Lock()
322  {
323  pMutex.Lock();
324  }
325 
326  //------------------------------------------------------------------------
328  //------------------------------------------------------------------------
329  void UnLock()
330  {
331  pMutex.UnLock();
332  }
333 
334  //------------------------------------------------------------------------
336  //------------------------------------------------------------------------
337  void Tick( time_t now );
338 
339  //------------------------------------------------------------------------
341  //------------------------------------------------------------------------
342  void TimeOutRequests( time_t now );
343 
344  //------------------------------------------------------------------------
346  //------------------------------------------------------------------------
347  void AfterForkChild();
348 
349  private:
350  //------------------------------------------------------------------------
351  // Helper for queuing messages
352  //------------------------------------------------------------------------
353  struct RequestData
354  {
357  const MessageSendParams &p ):
358  request(r), handler(h), params(p) {}
362  };
363  typedef std::list<RequestData> RequestList;
364 
365  //------------------------------------------------------------------------
367  //------------------------------------------------------------------------
368  Status SendOrQueue( const URL &url,
369  Message *msg,
370  ResponseHandler *handler,
371  MessageSendParams &sendParams );
372 
373  //------------------------------------------------------------------------
375  //------------------------------------------------------------------------
376  bool IsRecoverable( const XRootDStatus &stataus ) const;
377 
378  //------------------------------------------------------------------------
384  //------------------------------------------------------------------------
385  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
386 
387  //------------------------------------------------------------------------
389  //------------------------------------------------------------------------
391 
392  //------------------------------------------------------------------------
393  // Send a close and ignore the response
394  //------------------------------------------------------------------------
395  Status SendClose( uint16_t timeout );
396 
397  //------------------------------------------------------------------------
399  //------------------------------------------------------------------------
400  bool IsReadOnly() const;
401 
402  //------------------------------------------------------------------------
404  //------------------------------------------------------------------------
405  Status ReOpenFileAtServer( const URL &url, uint16_t timeout );
406 
407  //------------------------------------------------------------------------
409  //------------------------------------------------------------------------
410  void FailMessage( RequestData rd, XRootDStatus status );
411 
412  //------------------------------------------------------------------------
414  //------------------------------------------------------------------------
415  void FailQueuedMessages( XRootDStatus status );
416 
417  //------------------------------------------------------------------------
419  //------------------------------------------------------------------------
420  void ReSendQueuedMessages();
421 
422  //------------------------------------------------------------------------
424  //------------------------------------------------------------------------
425  void ReWriteFileHandle( Message *msg );
426 
427  //------------------------------------------------------------------------
429  //------------------------------------------------------------------------
431  {
432  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
433  pRBytes = 0;
434  pVRBytes = 0;
435  pWBytes = 0;
436  pVSegs = 0;
437  pRCount = 0;
438  pVRCount = 0;
439  pWCount = 0;
440  pCloseReason = Status();
441  }
442 
443  //------------------------------------------------------------------------
445  //------------------------------------------------------------------------
446  void MonitorClose( const XRootDStatus *status );
447 
448  //------------------------------------------------------------------------
454  //------------------------------------------------------------------------
455  XRootDStatus IssueRequest( const URL &url,
456  Message *msg,
457  ResponseHandler *handler,
458  MessageSendParams &sendParams );
459 
468  uint8_t *pFileHandle;
469  uint16_t pOpenMode;
470  uint16_t pOpenFlags;
472  std::set<Message*> pInTheFly;
473  uint64_t pSessionId;
478 
479  //------------------------------------------------------------------------
480  // Monitoring variables
481  //------------------------------------------------------------------------
482  timeval pOpenTime;
483  uint64_t pRBytes;
484  uint64_t pVRBytes;
485  uint64_t pWBytes;
486  uint64_t pVWBytes;
487  uint64_t pVSegs;
488  uint64_t pRCount;
489  uint64_t pVRCount;
490  uint64_t pWCount;
491  uint64_t pVWCount;
493 
494  //------------------------------------------------------------------------
495  // Holds the OpenHanlder used to issue reopen
496  // (there is only only OpenHandler reopening a file at a time)
497  //------------------------------------------------------------------------
498  ResponseHandlerHolder *pReOpenHandler;
499 
500  //------------------------------------------------------------------------
501  // Responsible for file:// operations on the local filesystem
502  //------------------------------------------------------------------------
504  };
505 }
506 
507 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:485
bool IsRecoverable(const XRootDStatus &stataus) const
Check if the stateful error is recoverable.
void AfterForkChild()
Called in the child process after the fork.
Definition: XrdClAnyObject.hh:32
void OnClose(const XRootDStatus *status)
Process the results of the closing operation.
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:321
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:329
Definition: XrdClMessageUtils.hh:128
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:483
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:769
Status RecoverMessage(RequestData rd, bool callbackOnFailure=true)
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:473
Status ReOpenFileAtServer(const URL &url, uint16_t timeout)
Re-open the current file at a given server.
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:486
Object stat info.
Definition: XrdClXRootDResponses.hh:332
void TimeOutRequests(time_t now)
Declare timeout on requests being recovered.
void OnOpen(const XRootDStatus *status, const OpenInfo *openInfo, const HostList *hostList)
Process the results of the opening operation.
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:490
RequestData()
Definition: XrdClFileStateHandler.hh:355
void FailQueuedMessages(XRootDStatus status)
Fail queued messages.
The file is closed.
Definition: XrdClFileStateHandler.hh:55
void OnStateRedirection(const std::string &redirectUrl, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle stateful redirect.
Message * request
Definition: XrdClFileStateHandler.hh:359
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVSegs
Definition: XrdClFileStateHandler.hh:487
void OnStateError(XRootDStatus *status, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle an error while sending a stateful message.
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:475
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:360
void Tick(time_t now)
Tick.
Procedure execution status.
Definition: XrdClStatus.hh:109
FileStateHandler()
Constructor.
void MonitorClose(const XRootDStatus *status)
Dispatch monitoring information on close.
Opening is in progress.
Definition: XrdClFileStateHandler.hh:59
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:698
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:430
void ReWriteFileHandle(Message *msg)
Re-write file handle.
XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdSysPthread.hh:165
XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout=0)
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:474
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:503
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:363
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:472
Closing operation is in progress.
Definition: XrdClFileStateHandler.hh:60
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:482
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:834
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:488
MessageSendParams params
Definition: XrdClFileStateHandler.hh:361
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:470
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
Opening has failed.
Definition: XrdClFileStateHandler.hh:57
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:56
Request status.
Definition: XrdClXRootDResponses.hh:212
FileStatus
State of the file.
Definition: XrdClFileStateHandler.hh:53
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:477
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:498
Definition: XrdClFileStateHandler.hh:353
Recovering from an error.
Definition: XrdClFileStateHandler.hh:58
bool IsReadOnly() const
Check if the file is open for read only.
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:356
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:461
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:492
bool SetProperty(const std::string &name, const std::string &value)
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:491
bool GetProperty(const std::string &name, std::string &value) const
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:471
Handle an async response.
Definition: XrdClXRootDResponses.hh:839
void OnStateResponse(XRootDStatus *status, Message *message, AnyObject *response, HostList *hostList)
Handle stateful response.
void Lock()
Definition: XrdSysPthread.hh:220
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:47
Definition: XrdClLocalFileHandler.hh:32
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
~FileStateHandler()
Destructor.
URL representation.
Definition: XrdClURL.hh:30
Status SendOrQueue(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
Send a message to a host or put it in the recovery queue.
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:464
XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:476
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:489
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:462
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:468
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:467
void FailMessage(RequestData rd, XRootDStatus status)
Fail a message.
void ReSendQueuedMessages()
Re-send queued messages.
URL * pDataServer
Definition: XrdClFileStateHandler.hh:465
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:469
XRootDStatus IssueRequest(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
bool IsOpen() const
Check if the file is open.
void UnLock()
Definition: XrdSysPthread.hh:222
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:463
Status SendClose(uint16_t timeout)
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:484
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:460
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:466
Binary blob representation.
Definition: XrdClBuffer.hh:33
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0)
Status RunRecovery()
Run the recovery procedure if appropriate.