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 Tick( time_t now );
269 
270  //------------------------------------------------------------------------
272  //------------------------------------------------------------------------
273  void TimeOutRequests( time_t now );
274 
275  //------------------------------------------------------------------------
277  //------------------------------------------------------------------------
278  void AfterForkChild();
279 
280  private:
281  //------------------------------------------------------------------------
282  // Helper for queuing messages
283  //------------------------------------------------------------------------
284  struct RequestData
285  {
288  const MessageSendParams &p ):
289  request(r), handler(h), params(p) {}
293  };
294  typedef std::list<RequestData> RequestList;
295 
296  //------------------------------------------------------------------------
298  //------------------------------------------------------------------------
299  Status SendOrQueue( const URL &url,
300  Message *msg,
301  ResponseHandler *handler,
302  MessageSendParams &sendParams );
303 
304  //------------------------------------------------------------------------
306  //------------------------------------------------------------------------
307  bool IsRecoverable( const XRootDStatus &stataus ) const;
308 
309  //------------------------------------------------------------------------
315  //------------------------------------------------------------------------
316  Status RecoverMessage( RequestData rd, bool callbackOnFailure = true );
317 
318  //------------------------------------------------------------------------
320  //------------------------------------------------------------------------
322 
323  //------------------------------------------------------------------------
325  //------------------------------------------------------------------------
326  bool IsReadOnly() const;
327 
328  //------------------------------------------------------------------------
330  //------------------------------------------------------------------------
331  Status ReOpenFileAtServer( const URL &url, uint16_t timeout );
332 
333  //------------------------------------------------------------------------
335  //------------------------------------------------------------------------
336  void FailMessage( RequestData rd, XRootDStatus status );
337 
338  //------------------------------------------------------------------------
340  //------------------------------------------------------------------------
341  void FailQueuedMessages( XRootDStatus status );
342 
343  //------------------------------------------------------------------------
345  //------------------------------------------------------------------------
346  void ReSendQueuedMessages();
347 
348  //------------------------------------------------------------------------
350  //------------------------------------------------------------------------
351  void ReWriteFileHandle( Message *msg );
352 
353  //------------------------------------------------------------------------
355  //------------------------------------------------------------------------
357  {
358  pOpenTime.tv_sec = 0; pOpenTime.tv_usec = 0;
359  pRBytes = 0;
360  pVBytes = 0;
361  pWBytes = 0;
362  pVSegs = 0;
363  pRCount = 0;
364  pVCount = 0;
365  pWCount = 0;
366  pCloseReason = Status();
367  }
368 
369  //------------------------------------------------------------------------
371  //------------------------------------------------------------------------
372  void MonitorClose( const XRootDStatus *status );
373 
382  uint8_t *pFileHandle;
383  uint16_t pOpenMode;
384  uint16_t pOpenFlags;
386  std::set<Message*> pInTheFly;
387  uint64_t pSessionId;
390 
391  //------------------------------------------------------------------------
392  // Monitoring variables
393  //------------------------------------------------------------------------
394  timeval pOpenTime;
395  uint64_t pRBytes;
396  uint64_t pVBytes;
397  uint64_t pWBytes;
398  uint64_t pVSegs;
399  uint64_t pRCount;
400  uint64_t pVCount;
401  uint64_t pWCount;
403  };
404 }
405 
406 #endif // __XRD_CL_FILE_STATE_HANDLER_HH__