XRootD
Loading...
Searching...
No Matches
XrdEc::WrtBuff Class Reference

#include <XrdEcWrtBuff.hh>

+ Collaboration diagram for XrdEc::WrtBuff:

Public Member Functions

 WrtBuff (const ObjCfg &objcfg)
 
 WrtBuff (WrtBuff &&wrtbuff)
 Move constructor.
 
 ~WrtBuff ()
 
bool Complete ()
 True if the buffer if full, false otherwise.
 
bool Empty ()
 True if there are no data in the buffer, false otherwise.
 
void Encode ()
 Calculate the parity for the data stripes and the crc32cs.
 
uint32_t GetBlkSize ()
 Get size of the data in the buffer.
 
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
static BufferPool & Instance()
Singleton access to the object.

References Create.

Referenced by WrtBuff().

+ Here is the caller 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 }

References WrtBuff().

+ Here is the call graph for this function:

◆ ~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.

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 }

◆ 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 }

◆ 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.
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

References XrdEc::RedundancyProvider::compute(), XrdEc::ThreadPool::Execute(), XrdEc::Config::GetRedundancy(), GetStrpSize(), XrdEc::Config::Instance(), and XrdEc::ThreadPool::Instance().

+ 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 }

◆ 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 GetStrpSize().

Referenced by Encode(), and GetStrpSize().

+ 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 }

◆ 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 }

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