XRootD
XrdEc::WrtBuff Class Reference

#include <XrdEcWrtBuff.hh>

+ Collaboration diagram for XrdEc::WrtBuff:

Public Member Functions

 WrtBuff (const ObjCfg &objcfg)
 
 WrtBuff (WrtBuff &&wrtbuff)
 Move constructor. More...
 
 ~WrtBuff ()
 
bool Complete ()
 True if the buffer if full, false otherwise. More...
 
bool Empty ()
 True if there are no data in the buffer, false otherwise. More...
 
void Encode ()
 Calculate the parity for the data stripes and the crc32cs. More...
 
uint32_t GetBlkSize ()
 Get size of the data in the buffer. More...
 
uint32_t GetCrc32c (size_t strpnb)
 
char * GetStrpBuff (uint8_t strpnb)
 
uint32_t GetStrpSize (uint8_t strp)
 
void Pad (uint32_t size)
 
uint32_t Write (uint32_t size, const char *buffer)
 

Detailed Description

Write cache, accumulates full block and then calculates parity and all of it to the storage

Definition at line 132 of file XrdEcWrtBuff.hh.

Constructor & Destructor Documentation

◆ WrtBuff() [1/2]

XrdEc::WrtBuff::WrtBuff ( const ObjCfg objcfg)
inline

Constructor

Parameters
objcfg: data object configuration

Definition at line 140 of file XrdEcWrtBuff.hh.

140  : objcfg( objcfg ),
141  wrtbuff( BufferPool::Instance().Create( objcfg ) )
142  {
143  stripes.reserve( objcfg.nbchunks );
144  memset( wrtbuff.GetBuffer(), 0, wrtbuff.GetSize() );
145  }
bool Create
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
uint32_t GetSize() const
Get the size of the message.
Definition: XrdClBuffer.hh:132
static BufferPool & Instance()
Singleton access to the object.
Definition: XrdEcWrtBuff.hh:55
const uint8_t nbchunks
Definition: XrdEcObjCfg.hh:85

References XrdCl::Buffer::GetBuffer(), XrdCl::Buffer::GetSize(), and XrdEc::ObjCfg::nbchunks.

+ Here is the call graph for this function:

◆ WrtBuff() [2/2]

XrdEc::WrtBuff::WrtBuff ( WrtBuff &&  wrtbuff)
inline

Move constructor.

Definition at line 149 of file XrdEcWrtBuff.hh.

149  : objcfg( wrtbuff.objcfg ),
150  wrtbuff( std::move( wrtbuff.wrtbuff ) ),
151  stripes( std::move( wrtbuff.stripes ) ),
152  cksums( std::move( wrtbuff.cksums ) )
153  {
154  }

◆ ~WrtBuff()

XrdEc::WrtBuff::~WrtBuff ( )
inline

Definition at line 158 of file XrdEcWrtBuff.hh.

159  {
160  BufferPool::Instance().Recycle( std::move( wrtbuff ) );
161  }
void Recycle(XrdCl::Buffer &&buffer)
Give back a buffer to the poool.
Definition: XrdEcWrtBuff.hh:98

References XrdEc::BufferPool::Instance(), and XrdEc::BufferPool::Recycle().

+ Here is the call graph for this function:

Member Function Documentation

◆ Complete()

bool XrdEc::WrtBuff::Complete ( )
inline

True if the buffer if full, false otherwise.

Definition at line 243 of file XrdEcWrtBuff.hh.

244  {
245  return wrtbuff.GetCursor() == objcfg.datasize;
246  }
uint32_t GetCursor() const
Get append cursor.
Definition: XrdClBuffer.hh:140
const uint64_t datasize
Definition: XrdEcObjCfg.hh:88

References XrdEc::ObjCfg::datasize, and XrdCl::Buffer::GetCursor().

+ Here is the call graph for this function:

◆ Empty()

bool XrdEc::WrtBuff::Empty ( )
inline

True if there are no data in the buffer, false otherwise.

Definition at line 250 of file XrdEcWrtBuff.hh.

251  {
252  return ( wrtbuff.GetSize() == 0 || wrtbuff.GetCursor() == 0 );
253  }

References XrdCl::Buffer::GetCursor(), and XrdCl::Buffer::GetSize().

+ Here is the call graph for this function:

◆ Encode()

void XrdEc::WrtBuff::Encode ( )
inline

Calculate the parity for the data stripes and the crc32cs.

Definition at line 257 of file XrdEcWrtBuff.hh.

258  {
259  // first calculate the parity
260  uint8_t i ;
261  for( i = 0; i < objcfg.nbchunks; ++i )
262  stripes.emplace_back( wrtbuff.GetBuffer( i * objcfg.chunksize ), i < objcfg.nbdata );
263  Config &cfg = Config::Instance();
264  cfg.GetRedundancy( objcfg ).compute( stripes );
265  // then calculate the checksums
266  cksums.reserve( objcfg.nbchunks );
267  for( uint8_t strpnb = 0; strpnb < objcfg.nbchunks; ++strpnb )
268  {
269  size_t chunksize = GetStrpSize( strpnb );
270  std::future<uint32_t> ftr = ThreadPool::Instance().Execute( objcfg.digest, 0, stripes[strpnb].buffer, chunksize );
271  cksums.emplace_back( std::move( ftr ) );
272  }
273  }
static Config & Instance()
Singleton access.
Definition: XrdEcConfig.hh:46
static ThreadPool & Instance()
Singleton access.
std::future< std::invoke_result_t< FUNC, ARGs... > > Execute(FUNC func, ARGs... args)
Schedule a functional (together with its arguments) for execution.
uint32_t GetStrpSize(uint8_t strp)
XrdCmsConfig Config
const uint8_t nbdata
Definition: XrdEcObjCfg.hh:87
uint32_t(* digest)(uint32_t, void const *, size_t)
Definition: XrdEcObjCfg.hh:96
const uint64_t chunksize
Definition: XrdEcObjCfg.hh:89

References XrdEc::ObjCfg::chunksize, XrdEc::RedundancyProvider::compute(), XrdEc::ObjCfg::digest, XrdEc::ThreadPool::Execute(), XrdCl::Buffer::GetBuffer(), XrdEc::Config::GetRedundancy(), GetStrpSize(), XrdEc::Config::Instance(), XrdEc::ThreadPool::Instance(), XrdEc::ObjCfg::nbchunks, and XrdEc::ObjCfg::nbdata.

+ Here is the call graph for this function:

◆ GetBlkSize()

uint32_t XrdEc::WrtBuff::GetBlkSize ( )
inline

Get size of the data in the buffer.

Definition at line 236 of file XrdEcWrtBuff.hh.

237  {
238  return wrtbuff.GetCursor();
239  }

References XrdCl::Buffer::GetCursor().

+ Here is the call graph for this function:

◆ GetCrc32c()

uint32_t XrdEc::WrtBuff::GetCrc32c ( size_t  strpnb)
inline

Calculate the crc32c for given data stripe

Parameters
strpnb: number of the stripe
Returns
: the crc32c of the data stripe

Definition at line 280 of file XrdEcWrtBuff.hh.

281  {
282  return cksums[strpnb].get();
283  }

◆ GetStrpBuff()

char* XrdEc::WrtBuff::GetStrpBuff ( uint8_t  strpnb)
inline

Return buffer corresponding to given stripe

Parameters
strpnb: number of the stripe

Definition at line 202 of file XrdEcWrtBuff.hh.

203  {
204  return stripes[strpnb].buffer;
205  }

◆ GetStrpSize()

uint32_t XrdEc::WrtBuff::GetStrpSize ( uint8_t  strp)
inline

Return size of the data in the given stripe

Parameters
strp: number of the stripe

Definition at line 211 of file XrdEcWrtBuff.hh.

212  {
213  // Check if it is a data chunk?
214  if( strp < objcfg.nbdata )
215  {
216  // If the cursor is at least at the expected size
217  // it means we have the full chunk.
218  uint64_t expsize = ( strp + 1) * objcfg.chunksize;
219  if( expsize <= wrtbuff.GetCursor() )
220  return objcfg.chunksize;
221  // If the cursor is of by less than the chunk size
222  // it means we have a partial chunk
223  uint64_t delta = expsize - wrtbuff.GetCursor();
224  if( delta < objcfg.chunksize )
225  return objcfg.chunksize - delta;
226  // otherwise we are handling an empty chunk
227  return 0;
228  }
229  // It is a parity chunk so its size has to be equal
230  // to the size of the first chunk
231  return GetStrpSize( 0 );
232  }

References XrdEc::ObjCfg::chunksize, XrdCl::Buffer::GetCursor(), and XrdEc::ObjCfg::nbdata.

Referenced by Encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Pad()

void XrdEc::WrtBuff::Pad ( uint32_t  size)
inline

Pad the buffer with zeros.

Parameters
size: number of zeros to be written into the buffer

Definition at line 183 of file XrdEcWrtBuff.hh.

184  {
185  // if the buffer exist we only need to move the cursor
186  if( wrtbuff.GetSize() != 0 )
187  {
188  wrtbuff.AdvanceCursor( size );
189  return;
190  }
191  // otherwise we allocate the buffer and set the cursor
192  wrtbuff.Allocate( objcfg.datasize );
193  memset( wrtbuff.GetBuffer(), 0, wrtbuff.GetSize() );
194  wrtbuff.SetCursor( size );
195  return;
196  }
void AdvanceCursor(uint32_t delta)
Advance the cursor.
Definition: XrdClBuffer.hh:156
void Allocate(uint32_t size)
Allocate the buffer.
Definition: XrdClBuffer.hh:110
void SetCursor(uint32_t cursor)
Set the cursor.
Definition: XrdClBuffer.hh:148

References XrdCl::Buffer::AdvanceCursor(), XrdCl::Buffer::Allocate(), XrdEc::ObjCfg::datasize, XrdCl::Buffer::GetBuffer(), XrdCl::Buffer::GetSize(), and XrdCl::Buffer::SetCursor().

+ Here is the call graph for this function:

◆ Write()

uint32_t XrdEc::WrtBuff::Write ( uint32_t  size,
const char *  buffer 
)
inline

Write data into the buffer

Parameters
size: number of bytes to be written
buffer: buffer with data to be written
Returns
: number of bytes accepted by the buffer

Definition at line 169 of file XrdEcWrtBuff.hh.

170  {
171  uint64_t bytesAccepted = size; // bytes accepted by the buffer
172  if( wrtbuff.GetCursor() + bytesAccepted > objcfg.datasize )
173  bytesAccepted = objcfg.datasize - wrtbuff.GetCursor();
174  memcpy( wrtbuff.GetBufferAtCursor(), buffer, bytesAccepted );
175  wrtbuff.AdvanceCursor( bytesAccepted );
176  return bytesAccepted;
177  }
char * GetBufferAtCursor()
Get the buffer pointer at the append cursor.
Definition: XrdClBuffer.hh:189

References XrdCl::Buffer::AdvanceCursor(), XrdEc::ObjCfg::datasize, XrdCl::Buffer::GetBufferAtCursor(), and XrdCl::Buffer::GetCursor().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: