Skip to content

Commit

Permalink
Include cksum in info file.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Aug 29, 2016
1 parent 9d3c147 commit 072c2cf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
67 changes: 45 additions & 22 deletions src/XrdFileCache/XrdFileCacheInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <sys/stat.h>

#include "XrdOss/XrdOss.hh"
#include "XrdCks/XrdCksCalcmd5.hh"
#include "XrdOuc/XrdOucSxeq.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdCl/XrdClLog.hh"
Expand Down Expand Up @@ -93,8 +94,9 @@ namespace

using namespace XrdFileCache;

const char* Info::m_infoExtension = ".cinfo";
const char* Info::m_traceID = "Cinfo";
const char* Info::m_infoExtension = ".cinfo";
const char* Info::m_traceID = "Cinfo";
const int Info::m_defaultVersion = 2;

//------------------------------------------------------------------------------

Expand Down Expand Up @@ -152,6 +154,7 @@ void Info::ResizeBits(int s)
}
}


//------------------------------------------------------------------------------

bool Info::Read(XrdOssDF* fp, const std::string &fname)
Expand All @@ -164,35 +167,48 @@ bool Info::Read(XrdOssDF* fp, const std::string &fname)

FpHelper r(fp, 0, m_trace, m_traceID, trace_pfx + "oss read failed");

int version;
if (r.Read(version)) return false;
if (abs(version) != abs(m_store.m_version))
{
TRACE(Warning, trace_pfx << " incompatible file version " << version);
return false;
if (r.Read(m_store.m_version)) return false;

if (m_store.m_version == 0) {
TRACE(Warning, trace_pfx << " File version 0 non supported");
}
m_store.m_version = version;

if (r.Read(m_store.m_bufferSize)) return false;

long long fs;
if (r.Read(fs)) return false;
SetFileSize(fs);

if (m_store.m_version > 0)
if (r.Read(m_store.m_buff_synced, GetSizeInBytes())) return false;
memcpy(m_buff_written, m_store.m_buff_synced, GetSizeInBytes());

if (m_store.m_version > 1)
{
if (r.Read(m_buff_written, GetSizeInBytes())) return false;
memcpy(m_store.m_buff_synced, m_buff_written, GetSizeInBytes());
if (r.Read(m_store.m_cksum)) return false;
char tmpCksum[16];
GetCksum(m_store.m_buff_synced, &tmpCksum[0]);
if (tmpCksum != m_store.m_cksum) {
TRACE(Warning, trace_pfx << " buffer cksum and saved cksum don't match \n");
}
}

if (r.Read(m_store.m_accessCnt)) m_store.m_accessCnt = 0; // was: return false;

m_complete = ! IsAnythingEmptyInRng(0, m_sizeInBits);

if (r.Read(m_store.m_accessCnt)) m_store.m_accessCnt = 0; // was: return false;
TRACE(Dump, trace_pfx << " complete "<< m_complete << " access_cnt " << m_store.m_accessCnt);

return true;
}


//------------------------------------------------------------------------------
void Info::GetCksum( unsigned char* buff, char* digest)
{
XrdCksCalcmd5 calc;
calc.Update((const char*)buff, GetSizeInBits());
memcpy(digest, calc.Final(), 16);
}

//------------------------------------------------------------------------------
void Info::DisableDownloadStatus()
{
Expand All @@ -202,8 +218,15 @@ void Info::DisableDownloadStatus()

int Info::GetHeaderSize() const
{
// version + buffersize + file-size + download-status-array
return sizeof(int) + sizeof(long long) + sizeof(long long) + GetSizeInBytes();
if (m_store.m_version == 1) {
// version + buffersize + file-size + download-status-array
return sizeof(int) + sizeof(long long) + sizeof(long long) + GetSizeInBytes();
}
else // if (m_store.m_version == 2)
{
// version + buffersize + file-size + download-status-array + hash value
return sizeof(int) + sizeof(long long) + sizeof(long long) + GetSizeInBytes() + 16;
}
}

//------------------------------------------------------------------------------
Expand All @@ -225,12 +248,12 @@ bool Info::WriteHeader(XrdOssDF* fp, const std::string &fname)
if (w.Write(m_store.m_bufferSize)) return false;
if (w.Write(m_store.m_fileSize)) return false;

if ( m_store.m_version >= 0 )
{
if (w.Write(m_store.m_buff_synced, GetSizeInBytes()))
return false;
}
if (w.Write(m_store.m_buff_synced, GetSizeInBytes())) return false;

GetCksum(m_store.m_buff_synced, &m_store.m_cksum[0]);
if (w.Write(m_store.m_cksum)) return false;


// Can this really fail?
if (XrdOucSxeq::Release(fp->getFD()))
{
Expand Down
13 changes: 10 additions & 3 deletions src/XrdFileCache/XrdFileCacheInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class XrdOucTrace;
#include "XrdCl/XrdClDefaultEnv.hh"

class XrdOssDF;
class XrdCksCalc;

namespace XrdCl
{
Expand All @@ -50,12 +51,11 @@ namespace XrdFileCache
long long m_bufferSize; //!< prefetch buffer size
long long m_fileSize; //!< number of file blocks
unsigned char *m_buff_synced; //!< disk written state vector
char m_cksum[16];
int m_accessCnt; //!< number of written AStat structs

Store () : m_version(1), m_bufferSize(-1), m_fileSize(0), m_buff_synced(0), m_accessCnt(0) {
}


};

// !Access statistics
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace XrdFileCache
//---------------------------------------------------------------------
void SetBitSynced(int i);

//! \brief Mark block as written from prefetch
//! \brief Mark block as written from prefetchxs
//!
//! @param i block index
//---------------------------------------------------------------------
Expand Down Expand Up @@ -209,8 +209,14 @@ namespace XrdFileCache
int GetVersion() { return m_store.m_version; }


//---------------------------------------------------------------------
//! Get md5 cksum
//---------------------------------------------------------------------
void GetCksum( unsigned char* buff, char* digest);

const static char* m_infoExtension;
const static char* m_traceID;
const static int m_defaultVersion;

XrdOucTrace* GetTrace() const {return m_trace;}

Expand All @@ -227,6 +233,7 @@ namespace XrdFileCache

private:
inline unsigned char cfiBIT(int n) const { return 1 << n; }
XrdCksCalc* m_cksCalc;
};

inline bool Info::TestBit(int i) const
Expand Down

0 comments on commit 072c2cf

Please sign in to comment.