diff --git a/src/XrdFileCache/XrdFileCache.cc b/src/XrdFileCache/XrdFileCache.cc index 7765f743ab0..09d092ec5aa 100644 --- a/src/XrdFileCache/XrdFileCache.cc +++ b/src/XrdFileCache/XrdFileCache.cc @@ -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::iterator j = i++; + iFile->BlockRemovedFromWriteQ(*j); s_writeQ.queue.erase(j); --s_writeQ.size; } @@ -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); diff --git a/src/XrdFileCache/XrdFileCacheFile.cc b/src/XrdFileCache/XrdFileCacheFile.cc index a5bc4120e49..223526b3eab 100644 --- a/src/XrdFileCache/XrdFileCacheFile.cc +++ b/src/XrdFileCache/XrdFileCacheFile.cc @@ -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() { @@ -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); @@ -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 { diff --git a/src/XrdFileCache/XrdFileCacheFile.hh b/src/XrdFileCache/XrdFileCacheFile.hh index 4ab4f91af0a..58cd0626e48 100644 --- a/src/XrdFileCache/XrdFileCacheFile.hh +++ b/src/XrdFileCache/XrdFileCacheFile.hh @@ -141,6 +141,7 @@ namespace XrdFileCache //------------------------------------------------------------------------ ~File(); + void BlockRemovedFromWriteQ(Block*); //! Open file handle for data file and info file on local disk. bool Open(); @@ -175,6 +176,10 @@ namespace XrdFileCache void MarkPrefetch(); + + + //! Log path + const char* lPath() const; private: Block* RequestBlock(int i, bool prefetch); @@ -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*);