xrootd
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 "XrdCl/XrdClOptional.hh"
35 #include <list>
36 #include <set>
37 #include <vector>
38 
39 #include <sys/uio.h>
40 
41 namespace XrdCl
42 {
43  class ResponseHandlerHolder;
44  class Message;
45 
46  //----------------------------------------------------------------------------
48  //----------------------------------------------------------------------------
50  {
51  public:
52  //------------------------------------------------------------------------
54  //------------------------------------------------------------------------
56  {
63  };
64 
65  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
69 
70  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  FileStateHandler( bool useVirtRedirector );
77 
78  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
82 
83  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  XRootDStatus Open( const std::string &url,
95  uint16_t flags,
96  uint16_t mode,
97  ResponseHandler *handler,
98  uint16_t timeout = 0 );
99 
100  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
109  uint16_t timeout = 0 );
110 
111  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  XRootDStatus Stat( bool force,
123  ResponseHandler *handler,
124  uint16_t timeout = 0 );
125 
126 
127  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  XRootDStatus Read( uint64_t offset,
144  uint32_t size,
145  void *buffer,
146  ResponseHandler *handler,
147  uint16_t timeout = 0 );
148 
149  //------------------------------------------------------------------------
159  //------------------------------------------------------------------------
160  XRootDStatus Write( uint64_t offset,
161  uint32_t size,
162  const void *buffer,
163  ResponseHandler *handler,
164  uint16_t timeout = 0 );
165 
166  //------------------------------------------------------------------------
176  //------------------------------------------------------------------------
177  XRootDStatus Write( uint64_t offset,
178  Buffer &&buffer,
179  ResponseHandler *handler,
180  uint16_t timeout = 0 );
181 
182  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  XRootDStatus Write( uint64_t offset,
197  uint32_t size,
198  Optional<uint64_t> fdoff,
199  int fd,
200  ResponseHandler *handler,
201  uint16_t timeout = 0 );
202 
203 
204  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
213  uint16_t timeout = 0 );
214 
215  //------------------------------------------------------------------------
223  //------------------------------------------------------------------------
224  XRootDStatus Truncate( uint64_t size,
225  ResponseHandler *handler,
226  uint16_t timeout = 0 );
227 
228  //------------------------------------------------------------------------
237  //------------------------------------------------------------------------
239  void *buffer,
240  ResponseHandler *handler,
241  uint16_t timeout = 0 );
242 
243  //------------------------------------------------------------------------
251  //------------------------------------------------------------------------
253  ResponseHandler *handler,
254  uint16_t timeout = 0 );
255 
256  //------------------------------------------------------------------------
266  //------------------------------------------------------------------------
267  XRootDStatus WriteV( uint64_t offset,
268  const struct iovec *iov,
269  int iovcnt,
270  ResponseHandler *handler,
271  uint16_t timeout = 0 );
272 
273  //------------------------------------------------------------------------
284  //------------------------------------------------------------------------
285  XRootDStatus Fcntl( const Buffer &arg,
286  ResponseHandler *handler,
287  uint16_t timeout = 0 );
288 
289  //------------------------------------------------------------------------
298  //------------------------------------------------------------------------
300  uint16_t timeout = 0 );
301 
302  //------------------------------------------------------------------------
313  //------------------------------------------------------------------------
314  XRootDStatus SetXAttr( const std::vector<xattr_t> &attrs,
315  ResponseHandler *handler,
316  uint16_t timeout = 0 );
317 
318  //------------------------------------------------------------------------
329  //------------------------------------------------------------------------
330  XRootDStatus GetXAttr( const std::vector<std::string> &attrs,
331  ResponseHandler *handler,
332  uint16_t timeout = 0 );
333 
334  //------------------------------------------------------------------------
345  //------------------------------------------------------------------------
346  XRootDStatus DelXAttr( const std::vector<std::string> &attrs,
347  ResponseHandler *handler,
348  uint16_t timeout = 0 );
349 
350  //------------------------------------------------------------------------
360  //------------------------------------------------------------------------
362  uint16_t timeout = 0 );
363 
364  //------------------------------------------------------------------------
366  //------------------------------------------------------------------------
367  void OnOpen( const XRootDStatus *status,
368  const OpenInfo *openInfo,
369  const HostList *hostList );
370 
371  //------------------------------------------------------------------------
373  //------------------------------------------------------------------------
374  void OnClose( const XRootDStatus *status );
375 
376  //------------------------------------------------------------------------
378  //------------------------------------------------------------------------
379  void OnStateError( XRootDStatus *status,
380  Message *message,
381  ResponseHandler *userHandler,
382  MessageSendParams &sendParams );
383 
384  //------------------------------------------------------------------------
386  //------------------------------------------------------------------------
387  void OnStateRedirection( const std::string &redirectUrl,
388  Message *message,
389  ResponseHandler *userHandler,
390  MessageSendParams &sendParams );
391 
392  //------------------------------------------------------------------------
394  //------------------------------------------------------------------------
396  Message *message,
397  AnyObject *response,
398  HostList *hostList );
399 
400  //------------------------------------------------------------------------
402  //------------------------------------------------------------------------
403  bool IsOpen() const;
404 
405  //------------------------------------------------------------------------
409  //------------------------------------------------------------------------
410  bool SetProperty( const std::string &name, const std::string &value );
411 
412  //------------------------------------------------------------------------
416  //------------------------------------------------------------------------
417  bool GetProperty( const std::string &name, std::string &value ) const;
418 
419  //------------------------------------------------------------------------
421  //------------------------------------------------------------------------
422  void Lock()
423  {
424  pMutex.Lock();
425  }
426 
427  //------------------------------------------------------------------------
429  //------------------------------------------------------------------------
430  void UnLock()
431  {
432  pMutex.UnLock();
433  }
434 
435  //------------------------------------------------------------------------
437  //------------------------------------------------------------------------
438  void Tick( time_t now );
439 
440  //------------------------------------------------------------------------
442  //------------------------------------------------------------------------
443  void TimeOutRequests( time_t now );
444 
445  //------------------------------------------------------------------------
447  //------------------------------------------------------------------------
449 
450  private:
451  //------------------------------------------------------------------------
452  // Helper for queuing messages
453  //------------------------------------------------------------------------
454  struct RequestData
455  {
458  const MessageSendParams &p ):
459  request(r), handler(h), params(p) {}
463  };
464  typedef std::list<RequestData> RequestList;
465 
466  //------------------------------------------------------------------------
473  //------------------------------------------------------------------------
474  template<typename T>
476  kXR_char options,
477  const std::vector<T> &attrs,
478  ResponseHandler *handler,
479  uint16_t timeout = 0 );
480 
481  //------------------------------------------------------------------------
483  //------------------------------------------------------------------------
484  Status SendOrQueue( const URL &url,
485  Message *msg,
486  ResponseHandler *handler,
487  MessageSendParams &sendParams );
488 
489  //------------------------------------------------------------------------
491  //------------------------------------------------------------------------
492  bool IsRecoverable( const XRootDStatus &stataus ) const;
493 
494  //------------------------------------------------------------------------
500  //------------------------------------------------------------------------
501  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
502 
503  //------------------------------------------------------------------------
505  //------------------------------------------------------------------------
507 
508  //------------------------------------------------------------------------
509  // Send a close and ignore the response
510  //------------------------------------------------------------------------
511  XRootDStatus SendClose( uint16_t timeout );
512 
513  //------------------------------------------------------------------------
515  //------------------------------------------------------------------------
516  bool IsReadOnly() const;
517 
518  //------------------------------------------------------------------------
520  //------------------------------------------------------------------------
521  XRootDStatus ReOpenFileAtServer( const URL &url, uint16_t timeout );
522 
523  //------------------------------------------------------------------------
525  //------------------------------------------------------------------------
527 
528  //------------------------------------------------------------------------
530  //------------------------------------------------------------------------
532 
533  //------------------------------------------------------------------------
535  //------------------------------------------------------------------------
537 
538  //------------------------------------------------------------------------
540  //------------------------------------------------------------------------
542 
543  //------------------------------------------------------------------------
545  //------------------------------------------------------------------------
547  {
548  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
549  pRBytes = 0;
550  pVRBytes = 0;
551  pWBytes = 0;
552  pVSegs = 0;
553  pRCount = 0;
554  pVRCount = 0;
555  pWCount = 0;
556  pCloseReason = Status();
557  }
558 
559  //------------------------------------------------------------------------
561  //------------------------------------------------------------------------
562  void MonitorClose( const XRootDStatus *status );
563 
564  //------------------------------------------------------------------------
570  //------------------------------------------------------------------------
572  Message *msg,
573  ResponseHandler *handler,
574  MessageSendParams &sendParams );
575 
584  uint8_t *pFileHandle;
585  uint16_t pOpenMode;
586  uint16_t pOpenFlags;
588  std::set<Message*> pInTheFly;
589  uint64_t pSessionId;
594 
595  //------------------------------------------------------------------------
596  // Monitoring variables
597  //------------------------------------------------------------------------
598  timeval pOpenTime;
599  uint64_t pRBytes;
600  uint64_t pVRBytes;
601  uint64_t pWBytes;
602  uint64_t pVWBytes;
603  uint64_t pVSegs;
604  uint64_t pRCount;
605  uint64_t pVRCount;
606  uint64_t pWCount;
607  uint64_t pVWCount;
609 
610  //------------------------------------------------------------------------
611  // Holds the OpenHanlder used to issue reopen
612  // (there is only only OpenHandler reopening a file at a time)
613  //------------------------------------------------------------------------
614  ResponseHandlerHolder *pReOpenHandler;
615 
616  //------------------------------------------------------------------------
617  // Responsible for file:// operations on the local filesystem
618  //------------------------------------------------------------------------
620  };
621 }
622 
623 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
Definition: XrdClAnyObject.hh:33
Binary blob representation.
Definition: XrdClBuffer.hh:34
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:50
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:599
void OnStateRedirection(const std::string &redirectUrl, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle stateful redirect.
Status SendOrQueue(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
Send a message to a host or put it in the recovery queue.
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:614
URL * pDataServer
Definition: XrdClFileStateHandler.hh:581
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:588
void AfterForkChild()
Called in the child process after the fork.
XRootDStatus SetXAttr(const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:583
void TimeOutRequests(time_t now)
Declare timeout on requests being recovered.
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0)
void ReWriteFileHandle(Message *msg)
Re-write file handle.
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:590
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
void Tick(time_t now)
Tick.
bool IsReadOnly() const
Check if the file is open for read only.
Status XAttrOperationImpl(kXR_char subcode, kXR_char options, const std::vector< T > &attrs, ResponseHandler *handler, uint16_t timeout=0)
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:592
void FailQueuedMessages(XRootDStatus status)
Fail queued messages.
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:464
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus IssueRequest(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
XRootDStatus DelXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:602
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:586
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:576
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:582
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
FileStateHandler(bool useVirtRedirector)
uint64_t pVSegs
Definition: XrdClFileStateHandler.hh:603
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:579
FileStatus
State of the file.
Definition: XrdClFileStateHandler.hh:56
@ OpenInProgress
Opening is in progress.
Definition: XrdClFileStateHandler.hh:61
@ CloseInProgress
Closing operation is in progress.
Definition: XrdClFileStateHandler.hh:62
@ Closed
The file is closed.
Definition: XrdClFileStateHandler.hh:57
@ Opened
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:58
@ Error
Opening has failed.
Definition: XrdClFileStateHandler.hh:59
@ Recovering
Recovering from an error.
Definition: XrdClFileStateHandler.hh:60
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:430
XRootDStatus Write(uint64_t offset, uint32_t size, Optional< uint64_t > fdoff, int fd, ResponseHandler *handler, uint16_t timeout=0)
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:587
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:546
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:608
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:607
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:600
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:589
bool SetProperty(const std::string &name, const std::string &value)
XRootDStatus SendClose(uint16_t timeout)
XRootDStatus GetXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
Status RunRecovery()
Run the recovery procedure if appropriate.
void OnClose(const XRootDStatus *status)
Process the results of the closing operation.
void OnStateError(XRootDStatus *status, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle an error while sending a stateful message.
XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout=0)
void OnStateResponse(XRootDStatus *status, Message *message, AnyObject *response, HostList *hostList)
Handle stateful response.
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:585
XRootDStatus Write(uint64_t offset, Buffer &&buffer, ResponseHandler *handler, uint16_t timeout=0)
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:584
XRootDStatus ListXAttr(ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
void OnOpen(const XRootDStatus *status, const OpenInfo *openInfo, const HostList *hostList)
Process the results of the opening operation.
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:604
void MonitorClose(const XRootDStatus *status)
Dispatch monitoring information on close.
Status RecoverMessage(RequestData rd, bool callbackOnFailure=true)
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:591
bool IsRecoverable(const XRootDStatus &stataus) const
Check if the stateful error is recoverable.
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:605
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0)
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:601
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:578
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
void FailMessage(RequestData rd, XRootDStatus status)
Fail a message.
~FileStateHandler()
Destructor.
bool GetProperty(const std::string &name, std::string &value) const
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:619
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:606
FileStateHandler()
Constructor.
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:577
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:593
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:598
bool IsOpen() const
Check if the file is open.
XRootDStatus ReOpenFileAtServer(const URL &url, uint16_t timeout)
Re-open the current file at a given server.
void ReSendQueuedMessages()
Re-send queued messages.
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:422
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:580
Definition: XrdClLocalFileHandler.hh:33
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:834
Definition: XrdClOptional.hh:44
Handle an async response.
Definition: XrdClXRootDResponses.hh:975
Object stat info.
Definition: XrdClXRootDResponses.hh:396
URL representation.
Definition: XrdClURL.hh:31
Request status.
Definition: XrdClXRootDResponses.hh:215
Definition: XrdSysPthread.hh:166
void Lock()
Definition: XrdSysPthread.hh:220
void UnLock()
Definition: XrdSysPthread.hh:222
Definition: XrdClAnyObject.hh:26
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:969
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:904
Definition: XrdClFileStateHandler.hh:455
RequestData()
Definition: XrdClFileStateHandler.hh:456
Message * request
Definition: XrdClFileStateHandler.hh:460
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:457
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:461
MessageSendParams params
Definition: XrdClFileStateHandler.hh:462
Definition: XrdClMessageUtils.hh:131
Procedure execution status.
Definition: XrdClStatus.hh:111