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
34#include <list>
35#include <set>
36
37#include <sys/uio.h>
38
39namespace 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 //------------------------------------------------------------------------
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 //------------------------------------------------------------------------
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 //------------------------------------------------------------------------
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;
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__
Definition: XrdClAnyObject.hh:33
Binary blob representation.
Definition: XrdClBuffer.hh:34
Handle the stateful operations.
Definition: XrdClFileStateHandler.hh:48
uint64_t pRBytes
Definition: XrdClFileStateHandler.hh:483
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:498
URL * pDataServer
Definition: XrdClFileStateHandler.hh:465
std::set< Message * > pInTheFly
Definition: XrdClFileStateHandler.hh:472
void AfterForkChild()
Called in the child process after the fork.
URL * pStateRedirect
Definition: XrdClFileStateHandler.hh:467
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:474
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.
bool pFollowRedirects
Definition: XrdClFileStateHandler.hh:476
void FailQueuedMessages(XRootDStatus status)
Fail queued messages.
std::list< RequestData > RequestList
Definition: XrdClFileStateHandler.hh:363
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)
uint64_t pVWBytes
Definition: XrdClFileStateHandler.hh:486
uint16_t pOpenFlags
Definition: XrdClFileStateHandler.hh:470
XrdSysMutex pMutex
Definition: XrdClFileStateHandler.hh:460
URL * pLoadBalancer
Definition: XrdClFileStateHandler.hh:466
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:487
StatInfo * pStatInfo
Definition: XrdClFileStateHandler.hh:463
FileStatus
State of the file.
Definition: XrdClFileStateHandler.hh:54
@ OpenInProgress
Opening is in progress.
Definition: XrdClFileStateHandler.hh:59
@ CloseInProgress
Closing operation is in progress.
Definition: XrdClFileStateHandler.hh:60
@ Closed
The file is closed.
Definition: XrdClFileStateHandler.hh:55
@ Opened
Opening has succeeded.
Definition: XrdClFileStateHandler.hh:56
@ Error
Opening has failed.
Definition: XrdClFileStateHandler.hh:57
@ Recovering
Recovering from an error.
Definition: XrdClFileStateHandler.hh:58
void UnLock()
Unlock the internal lock.
Definition: XrdClFileStateHandler.hh:329
RequestList pToBeRecovered
Definition: XrdClFileStateHandler.hh:471
void ResetMonitoringVars()
Reset monitoring vars.
Definition: XrdClFileStateHandler.hh:430
XRootDStatus pCloseReason
Definition: XrdClFileStateHandler.hh:492
uint64_t pVWCount
Definition: XrdClFileStateHandler.hh:491
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
uint64_t pVRBytes
Definition: XrdClFileStateHandler.hh:484
uint64_t pSessionId
Definition: XrdClFileStateHandler.hh:473
bool SetProperty(const std::string &name, const std::string &value)
Status ReOpenFileAtServer(const URL &url, uint16_t timeout)
Re-open the current file at a given server.
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:469
uint8_t * pFileHandle
Definition: XrdClFileStateHandler.hh:468
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:488
void MonitorClose(const XRootDStatus *status)
Dispatch monitoring information on close.
Status RecoverMessage(RequestData rd, bool callbackOnFailure=true)
bool pDoRecoverWrite
Definition: XrdClFileStateHandler.hh:475
bool IsRecoverable(const XRootDStatus &stataus) const
Check if the stateful error is recoverable.
uint64_t pVRCount
Definition: XrdClFileStateHandler.hh:489
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0)
uint64_t pWBytes
Definition: XrdClFileStateHandler.hh:485
XRootDStatus pStatus
Definition: XrdClFileStateHandler.hh:462
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
Status SendClose(uint16_t timeout)
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:503
uint64_t pWCount
Definition: XrdClFileStateHandler.hh:490
FileStateHandler()
Constructor.
FileStatus pFileState
Definition: XrdClFileStateHandler.hh:461
bool pUseVirtRedirector
Definition: XrdClFileStateHandler.hh:477
timeval pOpenTime
Definition: XrdClFileStateHandler.hh:482
bool IsOpen() const
Check if the file is open.
void ReSendQueuedMessages()
Re-send queued messages.
void Lock()
Lock the internal lock.
Definition: XrdClFileStateHandler.hh:321
URL * pFileUrl
Definition: XrdClFileStateHandler.hh:464
Definition: XrdClLocalFileHandler.hh:33
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
Information returned by file open operation.
Definition: XrdClXRootDResponses.hh:714
Handle an async response.
Definition: XrdClXRootDResponses.hh:855
Object stat info.
Definition: XrdClXRootDResponses.hh:333
URL representation.
Definition: XrdClURL.hh:31
Request status.
Definition: XrdClXRootDResponses.hh:213
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:849
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:784
Definition: XrdClFileStateHandler.hh:354
RequestData()
Definition: XrdClFileStateHandler.hh:355
Message * request
Definition: XrdClFileStateHandler.hh:359
RequestData(Message *r, ResponseHandler *h, const MessageSendParams &p)
Definition: XrdClFileStateHandler.hh:356
ResponseHandler * handler
Definition: XrdClFileStateHandler.hh:360
MessageSendParams params
Definition: XrdClFileStateHandler.hh:361
Definition: XrdClMessageUtils.hh:129
Procedure execution status.
Definition: XrdClStatus.hh:110