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 <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  //------------------------------------------------------------------------
200  void *buffer,
201  ResponseHandler *handler,
202  uint16_t timeout = 0 );
203 
204  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
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  //------------------------------------------------------------------------
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  //------------------------------------------------------------------------
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  //------------------------------------------------------------------------
411 
412  //------------------------------------------------------------------------
414  //------------------------------------------------------------------------
416 
417  //------------------------------------------------------------------------
419  //------------------------------------------------------------------------
421 
422  //------------------------------------------------------------------------
424  //------------------------------------------------------------------------
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  //------------------------------------------------------------------------
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__
XrdCl::FileStateHandler::SetProperty
bool SetProperty(const std::string &name, const std::string &value)
XrdClFileSystem.hh
XrdCl::FileStateHandler::Truncate
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::MessageSendParams
Definition: XrdClMessageUtils.hh:129
XrdClXRootDResponses.hh
XrdCl::ResponseHandler
Handle an async response.
Definition: XrdClXRootDResponses.hh:855
XrdCl::FileStateHandler::Stat
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::RunRecovery
Status RunRecovery()
Run the recovery procedure if appropriate.
XrdClPostMasterInterfaces.hh
XrdSysMutex
Definition: XrdSysPthread.hh:166
XrdCl::LocalFileHandler
Definition: XrdClLocalFileHandler.hh:33
XrdCl::FileStateHandler::pStatus
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:462
XrdCl::FileStateHandler::pCloseReason
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:492
XrdCl::FileStateHandler::Tick
void Tick(time_t now)
Tick.
XrdCl::FileStateHandler::~FileStateHandler
~FileStateHandler()
Destructor.
XrdSysPthread.hh
XrdCl::FileStateHandler::IsOpen
bool IsOpen() const
Check if the file is open.
XrdCl::FileStateHandler::RequestData::RequestData
RequestData()
Definition: XrdClFileStateHandler.hh:355
XrdCl::FileStateHandler::FailMessage
void FailMessage(RequestData rd, XRootDStatus status)
Fail a message.
XrdCl::FileStateHandler::Write
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XrdClLocalFileHandler.hh
XrdCl::FileStateHandler::Sync
XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::pLoadBalancer
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:466
XrdCl::FileStateHandler::pWBytes
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:485
XrdCl::FileStateHandler
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:48
XrdCl::FileStateHandler::pFileState
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:461
XrdCl::FileStateHandler::pDataServer
URL * pDataServer
Definition: XrdClFileStateHandler.hh:465
XrdCl::FileStateHandler::IsReadOnly
bool IsReadOnly() const
Check if the file is open for read only.
XrdCl::FileStateHandler::pReOpenHandler
ResponseHandlerHolder * pReOpenHandler
Definition: XrdClFileStateHandler.hh:498
XrdCl::FileStateHandler::ResetMonitoringVars
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:430
XrdCl::FileStateHandler::pToBeRecovered
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:471
XrdCl::FileStateHandler::pFileHandle
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:468
XrdCl::FileStateHandler::RequestData::handler
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:360
XrdCl::FileStateHandler::IssueRequest
XRootDStatus IssueRequest(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
XrdCl::FileStateHandler::OpenInProgress
@ OpenInProgress
Opening is in progress.
Definition: XrdClFileStateHandler.hh:59
XrdCl::Message
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
XrdCl::FileStateHandler::pVSegs
uint64_t pVSegs
Definition: XrdClFileStateHandler.hh:487
XrdCl::FileStateHandler::pFollowRedirects
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:476
XrdCl::FileStateHandler::pVRBytes
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:484
XrdCl::FileStateHandler::OnStateError
void OnStateError(XRootDStatus *status, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle an error while sending a stateful message.
XrdCl::FileStateHandler::ReSendQueuedMessages
void ReSendQueuedMessages()
Re-send queued messages.
XrdCl::FileStateHandler::pVWCount
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:491
XrdCl::FileStateHandler::Fcntl
XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::RequestData
Definition: XrdClFileStateHandler.hh:354
XrdCl::FileStateHandler::OnStateResponse
void OnStateResponse(XRootDStatus *status, Message *message, AnyObject *response, HostList *hostList)
Handle stateful response.
XrdCl::FileStateHandler::Closed
@ Closed
The file is closed.
Definition: XrdClFileStateHandler.hh:55
XrdCl::FileStateHandler::GetProperty
bool GetProperty(const std::string &name, std::string &value) const
XrdCl::XRootDStatus
Request status.
Definition: XrdClXRootDResponses.hh:213
XrdCl::FileStateHandler::RequestData::request
Message * request
Definition: XrdClFileStateHandler.hh:359
XrdCl::ChunkList
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:784
XrdCl::FileStateHandler::pStatInfo
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:463
XrdCl::FileStateHandler::pDoRecoverRead
bool pDoRecoverRead
Definition: XrdClFileStateHandler.hh:474
XrdCl::FileStateHandler::pLFileHandler
LocalFileHandler * pLFileHandler
Definition: XrdClFileStateHandler.hh:503
XrdCl::FileStateHandler::pRBytes
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:483
XrdCl::FileStateHandler::pSessionId
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:473
XrdCl::FileStateHandler::RequestData::RequestData
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:356
XrdCl::FileStateHandler::CloseInProgress
@ CloseInProgress
Closing operation is in progress.
Definition: XrdClFileStateHandler.hh:60
XrdCl::FileStateHandler::RequestData::params
MessageSendParams params
Definition: XrdClFileStateHandler.hh:361
XrdCl::FileStateHandler::Read
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::OnOpen
void OnOpen(const XRootDStatus *status, const OpenInfo *openInfo, const HostList *hostList)
Process the results of the opening operation.
XrdCl::FileStateHandler::pOpenTime
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:482
XrdCl::FileStateHandler::Opened
@ Opened
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:56
XrdCl::FileStateHandler::Open
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::OnStateRedirection
void OnStateRedirection(const std::string &redirectUrl, Message *message, ResponseHandler *userHandler, MessageSendParams &sendParams)
Handle stateful redirect.
XrdCl::FileStateHandler::IsRecoverable
bool IsRecoverable(const XRootDStatus &stataus) const
Check if the stateful error is recoverable.
XrdCl::FileStateHandler::FileStatus
FileStatus
State of the file.
Definition: XrdClFileStateHandler.hh:54
XrdCl::FileStateHandler::FileStateHandler
FileStateHandler(bool useVirtRedirector)
XrdCl::FileStateHandler::AfterForkChild
void AfterForkChild()
Called in the child process after the fork.
XrdCl::FileStateHandler::VectorRead
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::Lock
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:321
XrdCl::FileStateHandler::pStateRedirect
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:467
XrdCl::FileStateHandler::SendOrQueue
Status SendOrQueue(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams)
Send a message to a host or put it in the recovery queue.
XrdCl::FileStateHandler::Recovering
@ Recovering
Recovering from an error.
Definition: XrdClFileStateHandler.hh:58
XrdCl::FileStateHandler::MonitorClose
void MonitorClose(const XRootDStatus *status)
Dispatch monitoring information on close.
XrdCl::FileStateHandler::pUseVirtRedirector
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:477
XrdCl::FileStateHandler::Error
@ Error
Opening has failed.
Definition: XrdClFileStateHandler.hh:57
XrdCl::FileStateHandler::WriteV
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
XrdCl
Definition: XrdClAnyObject.hh:26
XrdCl::FileStateHandler::pDoRecoverWrite
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:475
XrdCl::FileStateHandler::pFileUrl
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:464
XrdCl::FileStateHandler::pVWBytes
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:486
XrdCl::FileStateHandler::TimeOutRequests
void TimeOutRequests(time_t now)
Declare timeout on requests being recovered.
XrdCl::FileStateHandler::Close
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::FailQueuedMessages
void FailQueuedMessages(XRootDStatus status)
Fail queued messages.
XrdCl::HostList
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:849
XrdCl::FileStateHandler::UnLock
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:329
XrdCl::FileStateHandler::pInTheFly
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:472
XrdSysMutex::UnLock
void UnLock()
Definition: XrdSysPthread.hh:222
XrdCl::FileStateHandler::pWCount
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:490
XrdCl::FileStateHandler::ReOpenFileAtServer
Status ReOpenFileAtServer(const URL &url, uint16_t timeout)
Re-open the current file at a given server.
XrdClMessageUtils.hh
XrdCl::FileStateHandler::pOpenMode
uint16_t pOpenMode
Definition: XrdClFileStateHandler.hh:469
XrdCl::FileStateHandler::pVRCount
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:489
XrdCl::StatInfo
Object stat info.
Definition: XrdClXRootDResponses.hh:333
XrdCl::FileStateHandler::RequestList
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:363
XrdCl::FileStateHandler::ReWriteFileHandle
void ReWriteFileHandle(Message *msg)
Re-write file handle.
XrdSysMutex::Lock
void Lock()
Definition: XrdSysPthread.hh:220
XrdCl::OpenInfo
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:714
XrdCl::Status
Procedure execution status.
Definition: XrdClStatus.hh:110
XrdCl::URL
URL representation.
Definition: XrdClURL.hh:31
XrdCl::FileStateHandler::Visa
XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::RecoverMessage
Status RecoverMessage(RequestData rd, bool callbackOnFailure=true)
XrdCl::Buffer
Binary blob representation.
Definition: XrdClBuffer.hh:34
XrdCl::FileStateHandler::pOpenFlags
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:470
XrdCl::FileStateHandler::pRCount
uint64_t pRCount
Definition: XrdClFileStateHandler.hh:488
XrdCl::FileStateHandler::pMutex
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:460
XrdCl::FileStateHandler::FileStateHandler
FileStateHandler()
Constructor.
XrdCl::AnyObject
Definition: XrdClAnyObject.hh:33
XrdCl::FileStateHandler::SendClose
Status SendClose(uint16_t timeout)
XrdCl::FileStateHandler::VectorWrite
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
XrdCl::FileStateHandler::OnClose
void OnClose(const XRootDStatus *status)
Process the results of the closing operation.