Skip to content

Commit

Permalink
Negate info version to mark info file is top level file in hdfs healing.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Jul 1, 2016
1 parent 87c7a71 commit ca651b9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/XrdFileCache/XrdFileCacheIOFileBlock.cc
Expand Up @@ -196,6 +196,8 @@ int IOFileBlock::initLocalStat()
// This is writing the top-level cinfo
// The info file is used to get file size on defer open
// don't initalize buffer, it does not hold useful information in this case
m_info.SetBufferSize(m_cache.RefConfiguration().m_bufferSize);
m_info.DisableDownloadStatus();
m_info.SetFileSize(tmpStat.st_size);
m_info.WriteHeader(m_infoFile, path);
m_infoFile->Fsync();
Expand All @@ -214,7 +216,6 @@ int IOFileBlock::initLocalStat()

if (res == 0)
{
std::cerr << "local stat created \n";
m_localStat = new struct stat;
memcpy(m_localStat, &tmpStat, sizeof(struct stat));
}
Expand Down
15 changes: 10 additions & 5 deletions src/XrdFileCache/XrdFileCacheInfo.cc
Expand Up @@ -130,7 +130,7 @@ void Info::SetBufferSize(long long bs)
void Info::SetFileSize(long long fs)
{
m_fileSize = fs;
if (m_bufferSize > 0)
if (m_version >= 0)
ResizeBits((m_fileSize - 1)/m_bufferSize + 1) ;
}

Expand Down Expand Up @@ -165,19 +165,20 @@ bool Info::Read(XrdOssDF* fp, const std::string &fname)

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

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

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

if (m_bufferSize > 0)
if (m_version > 0)
{
if (r.Read(m_buff_fetched, GetSizeInBytes())) return false;
memcpy(m_buff_write_called, m_buff_fetched, GetSizeInBytes());
Expand All @@ -192,6 +193,11 @@ bool Info::Read(XrdOssDF* fp, const std::string &fname)
}

//------------------------------------------------------------------------------
void Info::DisableDownloadStatus()
{
// use version sign to skip downlaod status
m_version = -m_version;
}

int Info::GetHeaderSize() const
{
Expand All @@ -218,7 +224,7 @@ bool Info::WriteHeader(XrdOssDF* fp, const std::string &fname)
if (w.Write(m_bufferSize)) return false;
if (w.Write(m_fileSize)) return false;

if ( m_bufferSize > 0 )
if ( m_version >= 0 )
{
if (w.Write(m_buff_write_called, GetSizeInBytes()))
return false;
Expand Down Expand Up @@ -253,7 +259,6 @@ bool Info::AppendIOStat(AStat& as, XrdOssDF* fp, const std::string &fname)
FpHelper w(fp, GetHeaderSize(), m_trace, m_traceID, trace_pfx + "oss write failed");

if (w.Write(m_accessCnt)) return false;

w.f_off += (m_accessCnt-1)*sizeof(AStat);

if (w.Write(as)) return false;
Expand Down
5 changes: 5 additions & 0 deletions src/XrdFileCache/XrdFileCacheInfo.hh
Expand Up @@ -109,6 +109,11 @@ namespace XrdFileCache
//---------------------------------------------------------------------
bool WriteHeader(XrdOssDF* fp, const std::string &fname="<unknown>");

//---------------------------------------------------------------------
//! Disable allocating, writing, and reading of downlaod status
//---------------------------------------------------------------------
void DisableDownloadStatus();

//---------------------------------------------------------------------
//! Append access time, and cache statistics
//! @return true on success
Expand Down
74 changes: 40 additions & 34 deletions src/XrdFileCache/XrdFileCachePrint.cc
Expand Up @@ -80,42 +80,48 @@ void Print::printFile(const std::string& path)
statv.push_back(a);
}

int cntd = 0;
for (int i = 0; i < cfi.GetSizeInBits(); ++i) if (cfi.TestBit(i)) 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)
{
int n_db = 0;
{ int x = cfi.GetSizeInBits(); while (x) { x /= 10; ++n_db; } }
static const char *nums = "0123456789";
printf("printing %d blocks:\n", cfi.GetSizeInBits());
printf("%*s %10d%10d%10d%10d%10d%10d\n", n_db, "", 1, 2, 3, 4, 5, 6);
printf("%*s %s%s%s%s%s%s0123", n_db, "", nums, nums, nums, nums, nums, nums);
for (int i = 0; i < cfi.GetSizeInBits(); ++i)
{
if (i % 64 == 0)
printf("\n%*d ", n_db, i);
printf("%c", cfi.TestBit(i) ? 'x' : '.');
}
printf("\n");
if (cfi.GetVersion() < 0) {
// Top level info file for file block mode
printf("version == %d, fileSize %lld, bufferSize %lld \n",
abs(cfi.GetVersion()), cfi.GetFileSize(),cfi.GetBufferSize());
}

int n_da = 0;
{ int x = cfi.GetAccessCnt(); while (x) { x /= 10; ++n_da; } }
for (int i = 0; i < cfi.GetAccessCnt(); ++i)
{
printf("access %*d: ", n_da, i);
Info::AStat& a = statv[i];
char s[1000];
struct tm * p = localtime(&a.DetachTime);
strftime(s, 1000, "%c", p);
printf("[%s], bytesDisk=%lld, bytesRAM=%lld, bytesMissed=%lld\n", s, a.BytesDisk, a.BytesRam, a.BytesMissed);
else {
int cntd = 0;
for (int i = 0; i < cfi.GetSizeInBits(); ++i) if (cfi.TestBit(i)) 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)
{
int n_db = 0;
{ int x = cfi.GetSizeInBits(); while (x) { x /= 10; ++n_db; } }
static const char *nums = "0123456789";
printf("printing %d blocks:\n", cfi.GetSizeInBits());
printf("%*s %10d%10d%10d%10d%10d%10d\n", n_db, "", 1, 2, 3, 4, 5, 6);
printf("%*s %s%s%s%s%s%s0123", n_db, "", nums, nums, nums, nums, nums, nums);
for (int i = 0; i < cfi.GetSizeInBits(); ++i)
{
if (i % 64 == 0)
printf("\n%*d ", n_db, i);
printf("%c", cfi.TestBit(i) ? 'x' : '.');
}
printf("\n");
}

int n_da = 0;
{ int x = cfi.GetAccessCnt(); while (x) { x /= 10; ++n_da; } }
for (int i = 0; i < cfi.GetAccessCnt(); ++i)
{
printf("access %*d: ", n_da, i);
Info::AStat& a = statv[i];
char s[1000];
struct tm * p = localtime(&a.DetachTime);
strftime(s, 1000, "%c", p);
printf("[%s], bytesDisk=%lld, bytesRAM=%lld, bytesMissed=%lld\n", s, a.BytesDisk, a.BytesRam, a.BytesMissed);
}
}

delete fh;
printf("\n");
}
Expand Down

0 comments on commit ca651b9

Please sign in to comment.