Skip to content

Commit

Permalink
Handle case where new file is attached while a CacheIO object with th…
Browse files Browse the repository at this point in the history
…e same path is still ioActive
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent eec7cd8 commit 62d79be
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
31 changes: 30 additions & 1 deletion src/XrdFileCache/XrdFileCache.cc
Expand Up @@ -168,6 +168,16 @@ int Cache::isAttached()
void Cache::Detach(XrdOucCacheIO* io)
{
clLog()->Info(XrdCl::AppMsg, "Cache::Detach() %s", io->Path());
std::map<std::string, DiskNetIO>::iterator it = m_active.begin();
while (it != m_active.end() )
{
if (it->second.io == io) {
m_active.erase(it++);
}
else {
++it;
}
}

delete io;
}
Expand Down Expand Up @@ -265,6 +275,25 @@ Cache::RAMBlockReleased()
m_RAMblocks_used--;
}

//==============================================================================
//======================= File relinquish at process of dying ===================
//======================================================================
File* Cache::GetFileForLocalPath(std::string path, IO* io)
{
typedef std::map<std::string, DiskNetIO> ActiveMap_t;
ActiveMap_t::iterator it = m_active.find(path);
if (it == m_active.end())
{
return 0;
}
else {
File* file = it->second.file;
it->second.io->RelinquishFile(file);
return file;
}
}



//==============================================================================
//======================= PREFETCH ===================================
Expand Down Expand Up @@ -306,7 +335,7 @@ Cache::DeRegisterPrefetchFile(File* file)
// called from last line File::InitiateClose()

m_prefetch_condVar.Lock();
for (FileList::iterator it = m_prefetchList.begin(); it != m_prefetchList.end(); ++it) {
for (PrefetchList::iterator it = m_prefetchList.begin(); it != m_prefetchList.end(); ++it) {
if (*it == file) {
m_prefetchList.erase(it);
break;
Expand Down
13 changes: 11 additions & 2 deletions src/XrdFileCache/XrdFileCache.hh
Expand Up @@ -186,13 +186,14 @@ namespace XrdFileCache
XrdOss* GetOss() const { return m_output_fs; }

XrdSysError& GetSysError() { return m_log; }


File* GetFileForLocalPath(std::string, IO*);

private:
bool ConfigParameters(std::string, XrdOucStream&);
bool ConfigXeq(char *, XrdOucStream &);
bool xdlib(XrdOucStream &);
static Cache *m_factory; //!< this object
static Cache *m_factory; //!< this object

XrdSysError m_log; //!< XrdFileCache namespace logger
XrdOucCacheStats m_stats; //!<
Expand Down Expand Up @@ -222,6 +223,14 @@ namespace XrdFileCache

WriteQ m_writeQ;

struct DiskNetIO
{
IO* io;
File* file;
};

std::map<std::string, DiskNetIO> m_active;

// prefetching
typedef std::vector<File*> PrefetchList;
PrefetchList m_prefetchList;
Expand Down
4 changes: 3 additions & 1 deletion src/XrdFileCache/XrdFileCacheIO.hh
Expand Up @@ -32,7 +32,9 @@ namespace XrdFileCache
virtual int Write(char *Buffer, long long Offset, int Length)
{ errno = ENOTSUP; return -1; }

virtual void Update(XrdOucCacheIO2 &iocp) { m_io = &iocp; }
virtual void Update(XrdOucCacheIO2 &iocp) { m_io = &iocp; }

virtual void RelinquishFile(File*) {}

protected:
XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
Expand Down
31 changes: 23 additions & 8 deletions src/XrdFileCache/XrdFileCacheIOEntireFile.cc
Expand Up @@ -44,11 +44,16 @@ IOEntireFile::IOEntireFile(XrdOucCacheIO2 *io, XrdOucCacheStats &stats, Cache &
XrdCl::URL url(m_io->Path());
std::string fname = Cache::GetInstance().RefConfiguration().m_cache_dir + url.GetPath();

struct stat st;
Fstat(st);
m_file = new File(io, fname, 0, st.st_size);
if (!Cache::GetInstance().GetFileForLocalPath(fname, this))
{
struct stat st;
Fstat(st);
m_file = new File(io, fname, 0, st.st_size);
}
}



IOEntireFile::~IOEntireFile()
{

Expand All @@ -71,6 +76,12 @@ int IOEntireFile::Fstat(struct stat &sbuff)
}
}

void IOEntireFile::RelinquishFile(File* f)
{
assert(m_file == f);
m_file = 0;
}


struct stat* IOEntireFile::getValidLocalStat(const char* path)
{
Expand Down Expand Up @@ -100,17 +111,21 @@ struct stat* IOEntireFile::getValidLocalStat(const char* path)

bool IOEntireFile::ioActive()
{
return m_file->InitiateClose();
if (!m_file)
return false;
else
return m_file->InitiateClose();
}

XrdOucCacheIO *IOEntireFile::Detach()
{
m_statsGlobal.Add(m_file->GetStats());

XrdOucCacheIO * io = m_io;

delete m_file;
m_file = 0;
if (m_file) {
m_statsGlobal.Add(m_file->GetStats());
delete m_file;
m_file = 0;
}

// This will delete us!
m_cache.Detach(this);
Expand Down
1 change: 1 addition & 0 deletions src/XrdFileCache/XrdFileCacheIOEntireFile.hh
Expand Up @@ -97,6 +97,7 @@ namespace XrdFileCache

virtual int Fstat(struct stat &sbuff);

virtual void RelinquishFile(File*);

private:
File* m_file;
Expand Down

0 comments on commit 62d79be

Please sign in to comment.