Skip to content

Commit

Permalink
Make sure file-block mode also works, needs further fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
osschar committed Jun 29, 2016
1 parent 0d6e9c8 commit 9d60d67
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/XrdFileCache/XrdFileCacheFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ bool File::Open()
return false;
}

if (fileExisted && m_cfi.Read(m_infoFile))
if (fileExisted && m_cfi.Read(m_infoFile, ifn))
{
TRACEF(Debug, "Read existing info file.");
}
Expand Down
54 changes: 34 additions & 20 deletions src/XrdFileCache/XrdFileCacheIOFileBlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ File* IOFileBlock::newBlockFile(long long off, int blocksize)
file = new File(this, fname, off, blocksize);
Cache::GetInstance().AddActive(this, file);
}

return file;
}


//______________________________________________________________________________
int IOFileBlock::FStat(struct stat &sbuff)
{
// local stat is create in constructor. if file was on disk before
// attach that the only way stat was not successful is becuse there
// were info file read errors
if (!m_localStat) return -1;
if ( ! m_localStat) return -1;

memcpy(&sbuff, m_localStat, sizeof(struct stat));
return 0;
Expand All @@ -129,7 +128,7 @@ int IOFileBlock::FStat(struct stat &sbuff)
//______________________________________________________________________________
long long IOFileBlock::FSize()
{
if (!m_localStat) return -1;
if ( ! m_localStat) return -1;

return m_localStat->st_size;
}
Expand All @@ -146,50 +145,63 @@ int IOFileBlock::initLocalStat()
XrdOucEnv myEnv;

// try to read from existing file
if (m_cache.GetOss()->Stat(path.c_str(), &tmpStat) == XrdOssOK) {
if (m_cache.GetOss()->Stat(path.c_str(), &tmpStat) == XrdOssOK)
{
XrdOssDF* infoFile = m_cache.GetOss()->newFile(m_cache.RefConfiguration().m_username.c_str());
if (infoFile->Open(path.c_str(), O_RDONLY, 0600, myEnv) == XrdOssOK) {
if (infoFile->Open(path.c_str(), O_RDONLY, 0600, myEnv) == XrdOssOK)
{
Info info(m_cache.GetTrace());
if (info.Read(infoFile, path))
{
tmpStat.st_size = info.GetFileSize();
TRACEIO(Info, "IOFileBlock::initCachedStat successfuly read size from existing info file = " << tmpStat.st_size);
res = 0;
}
else {
else
{
// file exist but can't read it
TRACEIO(Error, "IOFileBlock::initCachedStat failed to read file size from info file");
TRACEIO(Error, "IOFileBlock::initCachedStat failed to read file size from info file");
// MT-XXXX need to close the file!
}
}
}

// if there is no local info file, try to read from clinet and then save stat into a new *cinfo file
if (res) {
if (res)
{
res = GetInput()->Fstat(tmpStat);
TRACEIO(Debug, "IOFileBlock::initCachedStat get stat from client res= " << res << "size = " << tmpStat.st_size);
if (res == 0) {
if (m_cache.GetOss()->Create(m_cache.RefConfiguration().m_username.c_str(), path.c_str(), 0600, myEnv, XRDOSS_mkpath) == XrdOssOK) {
if (res == 0)
{
if (m_cache.GetOss()->Create(m_cache.RefConfiguration().m_username.c_str(), path.c_str(), 0600, myEnv, XRDOSS_mkpath) == XrdOssOK)
{
XrdOssDF* infoFile = m_cache.GetOss()->newFile(m_cache.RefConfiguration().m_username.c_str());
if (infoFile->Open(path.c_str(), O_RDWR, 0600, myEnv) == XrdOssOK) {
if (infoFile->Open(path.c_str(), O_RDWR, 0600, myEnv) == XrdOssOK)
{
// MT-XXXX This is writing the top-level cinfo?
// Why is it writing out block info?
// Reading this back consistently fails, reading too few bytes, it seems ...
// which is still a successful read from posix point of view so errno = 0.
Info cfi(m_cache.GetTrace(), false);
cfi.SetBufferSize(m_cache.RefConfiguration().m_bufferSize);
cfi.SetFileSize(tmpStat.st_size);
cfi.WriteHeader(infoFile);
infoFile->Fsync();
infoFile->Close();
}
else {
else
{
TRACEIO(Error, "IOFileBlock::initCachedStat can't open info file path");
}
delete infoFile;
}
else {
TRACEIO(Error, "IOFileBlock::initCachedStat can't create info file path");
else
{
TRACEIO(Error, "IOFileBlock::initCachedStat can't create info file path");
}
}
}


if (res == 0)
{
std::cerr << "local stat created \n";
Expand All @@ -200,7 +212,6 @@ int IOFileBlock::initLocalStat()
return res;
}


//______________________________________________________________________________
void IOFileBlock::RelinquishFile(File* f)
{
Expand All @@ -223,11 +234,12 @@ bool IOFileBlock::ioActive()
{
XrdSysMutexHelper lock(&m_mutex);

for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it) {
for (std::map<int, File*>::iterator it = m_blocks.begin(); it != m_blocks.end(); ++it)
{
if (it->second->ioActive())
return true;
}

return false;
}

Expand Down Expand Up @@ -299,12 +311,14 @@ int IOFileBlock::Read (char *buff, long long off, int size)
readBlockSize = m_blocksize;
}
}
// MT-XXXX
assert(readBlockSize);

TRACEIO(Dump, "IOFileBlock::Read() block[ " << blockIdx << "] read-block-size[" << readBlockSize << "], offset[" << readBlockSize << "] off = " << off );

long long min = blockIdx*m_blocksize;
if ( off < min) { assert(0); }
if ( off < min) { assert(0); } // MT-XXXX
// MT-XXXX
assert(off+readBlockSize <= (min + m_blocksize));
int retvalBlock = fb->Read(buff, off, readBlockSize);

Expand Down
14 changes: 8 additions & 6 deletions src/XrdFileCache/XrdFileCacheInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace
const char *m_traceID;
std::string f_ttext;

XrdOucTrace* GetTrace() const {return f_trace;}
XrdOucTrace* GetTrace() const { return f_trace; }

FpHelper(XrdOssDF* fp, off_t off,
XrdOucTrace *trace, const char *tid, const std::string &ttext) :
Expand All @@ -57,7 +57,8 @@ namespace
ssize_t ret = f_fp->Read(buf, f_off, size);
if (ret != size)
{
TRACE(Warning, f_trace << " error=" << strerror(errno));
TRACE(Warning, f_ttext << " off=" << f_off << " size=" << size
<< " ret=" << ret << " error=" << ((ret < 0) ? strerror(errno) : "<no error>"));
return true;
}
f_off += ret;
Expand All @@ -75,7 +76,8 @@ namespace
ssize_t ret = f_fp->Write(buf, f_off, size);
if (ret != size)
{
TRACE(Warning, f_trace << " error=" << strerror(errno));
TRACE(Warning, f_ttext << " off=" << f_off << " size=" << size
<< " ret=" << ret << " error=" << ((ret < 0) ? strerror(errno) : "<no error>"));
return true;
}
f_off += ret;
Expand All @@ -87,8 +89,6 @@ namespace
return Write(&loc, sizeof(T));
}
};


}

using namespace XrdFileCache;
Expand Down Expand Up @@ -181,7 +181,9 @@ bool Info::Read(XrdOssDF* fp, const std::string &fname)
memcpy(m_buff_write_called, m_buff_fetched, GetSizeInBytes());
m_complete = ! IsAnythingEmptyInRng(0, m_sizeInBits);

if (r.Read(m_accessCnt)) return false;
// MT-XXXX it sucks to have this here! Unless it is written out in WriteHeader().
// Now hacking it to set access count to 0 on failure.
if (r.Read(m_accessCnt)) m_accessCnt = 0; // was: return false;
TRACE(Dump, trace_pfx << " complete "<< m_complete << " access_cnt " << m_accessCnt);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/XrdFileCache/XrdFileCacheInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace XrdFileCache
//!
//! @return true on success
//---------------------------------------------------------------------
bool Read(XrdOssDF* fp, const std::string &fname="<unknown>");
bool Read(XrdOssDF* fp, const std::string &fname="<unknown>");

//---------------------------------------------------------------------
//! Write number of blocks and read buffer size
Expand Down
2 changes: 1 addition & 1 deletion src/XrdFileCache/XrdFileCachePrint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Print::printFile(const std::string& path)

XrdSysLogger log;
XrdSysError err(&log);
XrdOucTrace tr(&err); tr.What = 1;
XrdOucTrace tr(&err); tr.What = 2;
Info cfi(&tr);

if ( ! cfi.Read(fh, path))
Expand Down

0 comments on commit 9d60d67

Please sign in to comment.