Skip to content

Commit

Permalink
Put file size in the info file.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent ac137cd commit 87ea7dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/XrdFileCache/XrdFileCacheInfo.cc
Expand Up @@ -37,7 +37,7 @@ using namespace XrdFileCache;


Info::Info(long long iBufferSize) :
m_version(0),
m_version(1),
m_bufferSize(iBufferSize),
m_sizeInBits(0),
m_buff_fetched(0), m_buff_write_called(0), m_buff_prefetch(0),
Expand All @@ -53,6 +53,13 @@ Info::~Info()
if (m_buff_prefetch) free(m_buff_prefetch);
}

//______________________________________________________________________________
void Info::SetFileSize(long long fs)
{
m_fileSize = fs;
ResizeBits(m_fileSize/m_bufferSize);
}

//______________________________________________________________________________


Expand Down Expand Up @@ -82,15 +89,15 @@ int Info::Read(XrdOssDF* fp, bool init_prefetch_buff )
off += fp->Read(&m_bufferSize, off, sizeof(long long));
if (off <= 0) return off;

int sb;
off += fp->Read(&sb, off, sizeof(int));
ResizeBits(sb);

off += fp->Read(&m_fileSize, off, sizeof(long long));
ResizeBits(m_fileSize/m_bufferSize);

off += fp->Read(m_buff_fetched, off, GetSizeInBytes());
assert (off == GetHeaderSize());

memcpy(m_buff_write_called, m_buff_fetched, GetSizeInBytes());
m_complete = IsAnythingEmptyInRng(0, sb-1) ? false : true;
m_complete = IsAnythingEmptyInRng(0, m_sizeInBits - 1) ? false : true;


off += fp->Read(&m_accessCnt, off, sizeof(int));
Expand All @@ -110,8 +117,8 @@ int Info::Read(XrdOssDF* fp, bool init_prefetch_buff )

int Info::GetHeaderSize() const
{
// version + buffersize + download-status-array-size + download-status-array
return sizeof(int) + sizeof(long long) + sizeof(int) + GetSizeInBytes();
// version + buffersize + file-size + download-status-array
return sizeof(int) + sizeof(long long) + sizeof(long long) + GetSizeInBytes();
}

//______________________________________________________________________________
Expand All @@ -124,8 +131,8 @@ void Info::WriteHeader(XrdOssDF* fp)
off += fp->Write(&m_version, off, sizeof(int));
off += fp->Write(&m_bufferSize, off, sizeof(long long));

int nb = GetSizeInBits();
off += fp->Write(&nb, off, sizeof(int));

off += fp->Write(&m_fileSize, off, sizeof(long long));
off += fp->Write(m_buff_write_called, off, GetSizeInBytes());

flr = XrdOucSxeq::Release(fp->getFD());
Expand Down
12 changes: 12 additions & 0 deletions src/XrdFileCache/XrdFileCacheInfo.hh
Expand Up @@ -85,6 +85,7 @@ namespace XrdFileCache
//---------------------------------------------------------------------
void SetBitPrefetch(int i);

void SetFileSize(long long);

//---------------------------------------------------------------------
//! \brief Reserve buffer for fileSize/bufferSize bytes
Expand Down Expand Up @@ -127,6 +128,11 @@ namespace XrdFileCache
//---------------------------------------------------------------------
int GetSizeInBits() const;

//---------------------------------------------------------------------
//! Get file size
//---------------------------------------------------------------------
long long GetFileSize() const;

//----------------------------------------------------------------------
//! Get header size.
//----------------------------------------------------------------------
Expand Down Expand Up @@ -195,6 +201,7 @@ namespace XrdFileCache

int m_version; //!< info version
long long m_bufferSize; //!< prefetch buffer size
long long m_fileSize; //!< number of file blocks
int m_sizeInBits; //!< number of file blocks
unsigned char *m_buff_fetched; //!< download state vector
unsigned char *m_buff_write_called; //!< disk written state vector
Expand Down Expand Up @@ -246,6 +253,11 @@ namespace XrdFileCache
return m_sizeInBits;
}

inline long long Info::GetFileSize() const
{
return m_fileSize;
}

inline bool Info::IsComplete() const
{
return m_complete;
Expand Down
4 changes: 2 additions & 2 deletions src/XrdFileCache/XrdFileCachePrint.cc
Expand Up @@ -71,8 +71,8 @@ void Print::printFile(const std::string& path)
int cntd = 0;
for (int i = 0; i < cfi.GetSizeInBits(); ++i) if (cfi.TestBit(i)) cntd++;

printf("version == %d, bufferSize %lld nBlocks %d nDownloaded %d %s\n",
cfi.GetVersion(), cfi.GetBufferSize(), cfi.GetSizeInBits(), cntd,
printf("version == %d, fileSize %lld, bufferSize %lld nBlocks %d nDownloaded %d %s\n",
cfi.GetVersion(), cfi.GetFileSize(),cfi.GetBufferSize(), cfi.GetSizeInBits(), cntd,
(cfi.GetSizeInBits() == cntd) ? "complete" : "");

if (m_verbose) {
Expand Down

0 comments on commit 87ea7dd

Please sign in to comment.