Skip to content

Commit

Permalink
[XrdEc] Allow use of crc32 implementation from isal.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal authored and gganis committed Nov 23, 2021
1 parent e23d274 commit 7dd099e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 19 deletions.
10 changes: 9 additions & 1 deletion src/XrdCl/XrdClEcHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@ namespace XrdCl
if( cosc && itr == params.end() ) return nullptr;
std::string ckstype = itr->second;

XrdEc::ObjCfg *objcfg = new XrdEc::ObjCfg( objid, nbdta, nbprt, blksz / nbdta );
std::string chdigest;
itr = params.find( "xrdec.chdigest" );
if( itr == params.end() )
chdigest = "crc32c";
else
chdigest = itr->second;
bool usecrc32c = ( chdigest == "crc32c" );

XrdEc::ObjCfg *objcfg = new XrdEc::ObjCfg( objid, nbdta, nbprt, blksz / nbdta, usecrc32c );
objcfg->plgr = std::move( plgr );
objcfg->dtacgi = std::move( dtacgi );
objcfg->mdtacgi = std::move( mdtacgi );
Expand Down
22 changes: 19 additions & 3 deletions src/XrdEc/XrdEcObjCfg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef SRC_XRDEC_XRDECOBJCFG_HH_
#define SRC_XRDEC_XRDECOBJCFG_HH_

#include "XrdOuc/XrdOucCRC32C.hh"

#include "isa-l/crc.h"

#include <cstdlib>
#include <string>
#include <vector>
Expand All @@ -16,11 +20,20 @@

namespace XrdEc
{
//---------------------------------------------------------------------------
//! ISAL crc32 implementation
//---------------------------------------------------------------------------
inline static uint32_t isal_crc32(uint32_t crc, void const *buf, size_t len)
{
const unsigned char* buffer = reinterpret_cast<const unsigned char*>( buf );
return crc32_gzip_refl( crc, buffer, len );
}

struct ObjCfg
{
ObjCfg() = delete;

ObjCfg( const std::string &obj, uint8_t nbdata, uint8_t nbparity, uint64_t chunksize ) :
ObjCfg( const std::string &obj, uint8_t nbdata, uint8_t nbparity, uint64_t chunksize, bool usecrc32c ) :
obj( obj ),
nbchunks( nbdata + nbparity ),
nbparity( nbparity ),
Expand All @@ -30,7 +43,7 @@ namespace XrdEc
paritysize( nbparity * chunksize ),
blksize( datasize + paritysize )
{

digest = usecrc32c ? crc32c : isal_crc32;
}

ObjCfg( const ObjCfg &objcfg ) : obj( objcfg.obj ),
Expand All @@ -41,7 +54,8 @@ namespace XrdEc
chunksize( objcfg.chunksize ),
paritysize( objcfg.paritysize ),
blksize( objcfg.blksize ),
plgr( objcfg.plgr )
plgr( objcfg.plgr ),
digest( objcfg.digest )
{
}

Expand Down Expand Up @@ -76,6 +90,8 @@ namespace XrdEc
std::vector<std::string> plgr;
std::vector<std::string> dtacgi;
std::vector<std::string> mdtacgi;

uint32_t (*digest)(uint32_t, void const*, size_t);
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/XrdEc/XrdEcReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ namespace XrdEc
buffer.resize( rdsize );
// issue the read request
XrdCl::Async( XrdCl::ReadFrom( *zipptr, fn, 0, buffer.size(), buffer.data() ) >>
[zipptr, fn, cb]( XrdCl::XRootDStatus &st, XrdCl::ChunkInfo &ch )
[zipptr, fn, cb, this]( XrdCl::XRootDStatus &st, XrdCl::ChunkInfo &ch )
{
//---------------------------------------------------
// If read failed there's nothing to do, just pass the
Expand Down Expand Up @@ -635,7 +635,7 @@ namespace XrdEc
//---------------------------------------------------
// Verify data integrity
//---------------------------------------------------
uint32_t cksum = crc32c( 0, ch.buffer, ch.length );
uint32_t cksum = objcfg.digest( 0, ch.buffer, ch.length );
if( orgcksum != cksum )
{
cb( XrdCl::XRootDStatus( XrdCl::stError, XrdCl::errDataError ), 0 );
Expand Down Expand Up @@ -735,7 +735,7 @@ namespace XrdEc
buffer += lfh.lfhSize;
length -= lfh.lfhSize;
// verify the checksum
uint32_t crc32val = crc32c( 0, buffer, lfh.uncompressedSize );
uint32_t crc32val = objcfg.digest( 0, buffer, lfh.uncompressedSize );
if( crc32val != lfh.ZCRC32 ) return false;
// keep the metadata
std::string url = objcfg.GetDataUrl( std::stoull( lfh.filename ) );
Expand Down
16 changes: 8 additions & 8 deletions src/XrdEc/XrdEcStrmWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ namespace XrdEc
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
for( size_t i = 0; i < cdcnt; ++i )
{
std::string fn = std::to_string( i ); // file name (URL of the data archive)
buffer_t buff( dataarchs[i]->GetCD() ); // raw data buffer (central directory of the data archive)
uint32_t cksum = crc32c( 0, buff.data(), buff.size() ); // crc32c of the buffer
lfhs.emplace_back( fn, cksum, buff.size(), time( 0 ) ); // LFH record for the buffer
std::string fn = std::to_string( i ); // file name (URL of the data archive)
buffer_t buff( dataarchs[i]->GetCD() ); // raw data buffer (central directory of the data archive)
uint32_t cksum = objcfg.digest( 0, buff.data(), buff.size() ); // digest (crc) of the buffer
lfhs.emplace_back( fn, cksum, buff.size(), time( 0 ) ); // LFH record for the buffer
LFH &lfh = lfhs.back();
cdfhs.emplace_back( &lfh, mode, offset ); // CDFH record for the buffer
offset += LFH::lfhBaseSize + fn.size() + buff.size(); // shift the offset
cdsize += cdfhs.back().cdfhSize; // update central directory size
buffs.emplace_back( std::move( buff ) ); // keep the buffer for later
cdfhs.emplace_back( &lfh, mode, offset ); // CDFH record for the buffer
offset += LFH::lfhBaseSize + fn.size() + buff.size(); // shift the offset
cdsize += cdfhs.back().cdfhSize; // update central directory size
buffs.emplace_back( std::move( buff ) ); // keep the buffer for later
}

uint64_t zipsize = offset + cdsize + EOCD::eocdBaseSize;
Expand Down
2 changes: 0 additions & 2 deletions src/XrdEc/XrdEcUtilities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
#define SRC_XRDEC_XRDECUTILITIES_HH_

#include "XrdEc/XrdEcObjCfg.hh"

#include "XrdCl/XrdClXRootDResponses.hh"
#include "XrdCl/XrdClFileSystem.hh"

#include "XrdCl/XrdClUtils.hh"

#include <exception>
Expand Down
2 changes: 1 addition & 1 deletion src/XrdEc/XrdEcWrtBuff.hh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace XrdEc
for( uint8_t strpnb = 0; strpnb < objcfg.nbchunks; ++strpnb )
{
size_t chunksize = GetStrpSize( strpnb );
std::future<uint32_t> ftr = ThreadPool::Instance().Execute( crc32c, 0, stripes[strpnb].buffer, chunksize );
std::future<uint32_t> ftr = ThreadPool::Instance().Execute( objcfg.digest, 0, stripes[strpnb].buffer, chunksize );
cksums.emplace_back( std::move( ftr ) );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/XrdOuc/XrdOucCRC32C.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Copyright (C) 2015 Mark Adler
// See crc32c.c for the license.

#include <cstddef>
#include <cstdint>

// Return the CRC-32C of buf[0..len-1] given the starting CRC crc. This can be
Expand Down
3 changes: 3 additions & 0 deletions tests/XrdEcTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
include( XRootDCommon )
include_directories( ${CPPUNIT_INCLUDE_DIRS} ../common )

link_directories( ${ISAL_LIBDIR} )
include_directories( ${ISAL_INCDIR} )

add_library(
XrdEcTests MODULE
MicroTest.cc
Expand Down
2 changes: 1 addition & 1 deletion tests/XrdEcTests/MicroTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MicroTest );

void MicroTest::Init()
{
objcfg.reset( new ObjCfg( "test.txt", nbdata, nbparity, chsize ) );
objcfg.reset( new ObjCfg( "test.txt", nbdata, nbparity, chsize, true ) );
rawdata.clear();

char cwdbuff[1024];
Expand Down

0 comments on commit 7dd099e

Please sign in to comment.