Skip to content

Commit

Permalink
Fix error in de-registering blocks from write queue at the distructio…
Browse files Browse the repository at this point in the history
…n time. This change solves bug #61.
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent b35fa36 commit 296534d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/XrdFileCache/XrdFileCache.cc
Expand Up @@ -136,7 +136,10 @@ void Cache::RemoveWriteQEntriesFor(File *iFile)
{
if ((*i)->m_file == iFile)
{

XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::Remove entries for %p path %s", (void*)(*i), iFile->lPath());
std::list<Block*>::iterator j = i++;
iFile->BlockRemovedFromWriteQ(*j);
s_writeQ.queue.erase(j);
--s_writeQ.size;
}
Expand All @@ -162,6 +165,7 @@ Cache::ProcessWriteTasks()
Block* block = s_writeQ.queue.front(); // AMT should not be back ???
s_writeQ.queue.pop_front();
s_writeQ.size--;
XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::ProcessWriteTasks for %p path %s", (void*)(block), block->m_file->lPath());
s_writeQ.condVar.UnLock();

block->m_file->WriteBlockToDisk(block);
Expand Down
18 changes: 13 additions & 5 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -96,6 +96,13 @@ m_prefetchCurrentCnt(0)
}
}

void File::BlockRemovedFromWriteQ(Block* b)
{
m_downloadCond.Lock();
dec_ref_count(b);
clLog()->Dump(XrdCl::AppMsg, "File::BlockRemovedFromWriteQ() check write queues %p %d...%s", (void*)b, b->m_offset/m_cfi.GetBufferSize(), lPath());
m_downloadCond.UnLock();
}

File::~File()
{
Expand All @@ -122,13 +129,9 @@ File::~File()
{
m_downloadCond.Lock();
// remove failed blocks
//for (BlockMap_i it = m_block_map.begin(); it != m_block_map.end();) {

BlockMap_i itr = m_block_map.begin();
while (itr != m_block_map.end()) {
bool dropWqOrError = itr->second->is_finished() && itr->second->m_refcnt == 1; // refcounf more than 1 if used by Read()
bool prefetchWCancel = itr->second->m_prefetch && itr->second->m_refcnt == 0 && itr->second->m_downloaded;
if (dropWqOrError || prefetchWCancel) {
if (itr->second->is_failed() && itr->second->m_refcnt == 1) {
BlockMap_i toErase = itr;
++itr;
free_block(toErase->second);
Expand Down Expand Up @@ -824,6 +827,11 @@ void File::ProcessBlockResponse(Block* b, XrdCl::XRootDStatus *status)
inc_ref_count(b);
cache()->AddWriteTask(b, true);
}
else {
// there is no refcount +/- to remove dropped prefetched blocks on destruction
if (b->m_prefetch && (b->m_refcnt == 0))
free_block(b);
}
}
else
{
Expand Down
8 changes: 5 additions & 3 deletions src/XrdFileCache/XrdFileCacheFile.hh
Expand Up @@ -141,6 +141,7 @@ namespace XrdFileCache
//------------------------------------------------------------------------
~File();

void BlockRemovedFromWriteQ(Block*);
//! Open file handle for data file and info file on local disk.
bool Open();

Expand Down Expand Up @@ -175,6 +176,10 @@ namespace XrdFileCache

void MarkPrefetch();



//! Log path
const char* lPath() const;
private:
Block* RequestBlock(int i, bool prefetch);

Expand All @@ -196,9 +201,6 @@ namespace XrdFileCache
XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }


//! Log path
const char* lPath() const;

void inc_ref_count(Block*);
void dec_ref_count(Block*);
void free_block(Block*);
Expand Down

0 comments on commit 296534d

Please sign in to comment.