XRootD
XrdClCheckpointOperation.hh
Go to the documentation of this file.
1 /*
2  * XrdClCheckpointOperation.hh
3  *
4  * Created on: 31 May 2021
5  * Author: simonm
6  */
7 
8 #ifndef SRC_XRDCL_XRDCLCHECKPOINTOPERATION_HH_
9 #define SRC_XRDCL_XRDCLCHECKPOINTOPERATION_HH_
10 
12 
13 namespace XrdCl
14 {
15  //----------------------------------------------------------------------------
17  //----------------------------------------------------------------------------
18  enum ChkPtCode
19  {
21  };
22 
23  //----------------------------------------------------------------------------
25  //----------------------------------------------------------------------------
26  template<bool HasHndl>
27  class CheckpointImpl: public FileOperation<CheckpointImpl, HasHndl, Resp<void>,
28  Arg<ChkPtCode>>
29  {
30  public:
31 
32  //------------------------------------------------------------------------
34  //------------------------------------------------------------------------
37 
38  //------------------------------------------------------------------------
40  //------------------------------------------------------------------------
41  enum { CodeArg };
42 
43  //------------------------------------------------------------------------
45  //------------------------------------------------------------------------
46  std::string ToString()
47  {
48  return "Checkpoint";
49  }
50 
51  protected:
52 
53  //------------------------------------------------------------------------
59  //------------------------------------------------------------------------
60  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
61  {
62  ChkPtCode code = std::get<CodeArg>( this->args ).Get();
63  uint16_t timeout = pipelineTimeout < this->timeout ?
64  pipelineTimeout : this->timeout;
65  return this->file->Checkpoint( code, handler, timeout );
66  }
67  };
68 
69  //----------------------------------------------------------------------------
71  //----------------------------------------------------------------------------
72  inline CheckpointImpl<false> Checkpoint( Ctx<File> file, Arg<ChkPtCode> code, uint16_t timeout = 0 )
73  {
74  return CheckpointImpl<false>( std::move( file ), std::move( code ) ).Timeout( timeout );
75  }
76 
77 
78  //----------------------------------------------------------------------------
80  //----------------------------------------------------------------------------
81  template<bool HasHndl>
82  class ChkptWrtImpl: public FileOperation<ChkptWrtImpl, HasHndl, Resp<void>,
83  Arg<uint64_t>, Arg<uint32_t>, Arg<const void*>>
84  {
85  public:
86 
87  //------------------------------------------------------------------------
89  //------------------------------------------------------------------------
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  enum { OffArg, LenArg, BufArg };
97 
98  //------------------------------------------------------------------------
100  //------------------------------------------------------------------------
101  std::string ToString()
102  {
103  return "ChkptWrt";
104  }
105 
106  protected:
107 
108  //------------------------------------------------------------------------
114  //------------------------------------------------------------------------
115  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
116  {
117  uint64_t off = std::get<OffArg>( this->args ).Get();
118  uint32_t len = std::get<LenArg>( this->args ).Get();
119  const void* buf = std::get<BufArg>( this->args ).Get();
120  uint16_t timeout = pipelineTimeout < this->timeout ?
121  pipelineTimeout : this->timeout;
122  return this->file->ChkptWrt( off, len, buf, handler, timeout );
123  }
124  };
125 
126  //----------------------------------------------------------------------------
128  //----------------------------------------------------------------------------
130  Arg<uint32_t> size, Arg<const void*> buffer,
131  uint16_t timeout = 0 )
132  {
133  return ChkptWrtImpl<false>( std::move( file ), std::move( offset ),
134  std::move( size ), std::move( buffer ) ).Timeout( timeout );
135  }
136 
137 
138  //----------------------------------------------------------------------------
140  //----------------------------------------------------------------------------
141  template<bool HasHndl>
142  class ChkptWrtVImpl: public FileOperation<ChkptWrtVImpl, HasHndl, Resp<void>,
143  Arg<uint64_t>, Arg<std::vector<iovec>>>
144  {
145  public:
146 
147  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
152 
153  //------------------------------------------------------------------------
155  //------------------------------------------------------------------------
156  enum { OffArg, IovecArg, };
157 
158  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  std::string ToString()
162  {
163  return "ChkptWrtV";
164  }
165 
166  protected:
167 
168  //------------------------------------------------------------------------
174  //------------------------------------------------------------------------
175  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
176  {
177  uint64_t off = std::get<OffArg>( this->args ).Get();
178  std::vector<iovec> &stdiov = std::get<IovecArg>( this->args ).Get();
179  uint16_t timeout = pipelineTimeout < this->timeout ?
180  pipelineTimeout : this->timeout;
181 
182  int iovcnt = stdiov.size();
183  iovec iov[iovcnt];
184  for( size_t i = 0; i < stdiov.size(); ++i )
185  {
186  iov[i].iov_base = stdiov[i].iov_base;
187  iov[i].iov_len = stdiov[i].iov_len;
188  }
189 
190  return this->file->ChkptWrtV( off, iov, iovcnt, handler, timeout );
191  }
192  };
193 
194  //----------------------------------------------------------------------------
196  //----------------------------------------------------------------------------
198  Arg<std::vector<iovec>> iov,
199  uint16_t timeout = 0 )
200  {
201  return ChkptWrtVImpl<false>( std::move( file ), std::move( offset ),
202  std::move( iov ) ).Timeout( timeout );
203  }
204 }
205 
206 #endif /* SRC_XRDCL_XRDCLCHECKPOINTOPERATION_HH_ */
static const int kXR_ckpRollback
Definition: XProtocol.hh:215
static const int kXR_ckpCommit
Definition: XProtocol.hh:213
static const int kXR_ckpBegin
Definition: XProtocol.hh:212
Checkpoint operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Checkpointed write operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Checkpointed WriteV operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
std::tuple< Args... > args
Operation arguments.
uint16_t timeout
Operation timeout.
Derived< HasHndl > Timeout(uint16_t timeout)
Set operation timeout.
std::unique_ptr< PipelineHandler > handler
Operation handler.
CheckpointImpl< false > Checkpoint(Ctx< File > file, Arg< ChkPtCode > code, uint16_t timeout=0)
Factory for creating ReadImpl objects.
ChkptWrtImpl< false > ChkptWrt(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
ChkptWrtVImpl< false > ChkptWrtV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, uint16_t timeout=0)
Factory for creating ChkptWrtVImpl objects.
ChkPtCode
Checkpoint operation code.
Utility class for storing a pointer to operation context.
Definition: XrdClCtx.hh:39