Skip to content

Commit

Permalink
Merge pull request #904 from osschar/pfc-concurrent-ioactive-fix
Browse files Browse the repository at this point in the history
[pfc] Fix crash when all remaining IO objects disconnect within a short time frame.
  • Loading branch information
abh3 committed Feb 6, 2019
2 parents 5cfa68a + d0fcbee commit 442a084
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -60,6 +60,7 @@ File::File(const std::string& path, long long iOffset, long long iFileSize) :
m_offset(iOffset),
m_fileSize(iFileSize),
m_current_io(m_io_map.end()),
m_ios_in_detach(0),
m_non_flushed_cnt(0),
m_in_sync(false),
m_downloadCond(0),
Expand Down Expand Up @@ -143,14 +144,26 @@ bool File::ioActive(IO *io)

// On last IO, consider write queue blocks. Note, this also contains
// blocks being prefetched.
if (m_io_map.size() == 1)
// For multiple IOs the ioActive queries can occur in order before
// any of them are actually removed / detached.

bool io_active_result;

if (m_io_map.size() - m_ios_in_detach == 1)
{
return ! m_block_map.empty();
io_active_result = ! m_block_map.empty();
}
else
{
return mi->second.m_active_prefetches > 0;
io_active_result = mi->second.m_active_prefetches > 0;
}

if (io_active_result == false)
{
++m_ios_in_detach;
}

return io_active_result;
}
else
{
Expand Down Expand Up @@ -239,6 +252,7 @@ void File::RemoveIO(IO *io)
}

m_io_map.erase(mi);
--m_ios_in_detach;

if (m_io_map.empty() && m_prefetchState != kStopped && m_prefetchState != kComplete)
{
Expand Down
3 changes: 2 additions & 1 deletion src/XrdFileCache/XrdFileCacheFile.hh
Expand Up @@ -241,7 +241,8 @@ private:
typedef IoMap_t::iterator IoMap_i;

IoMap_t m_io_map;
IoMap_i m_current_io; //!< IO object to be used for prefetching.
IoMap_i m_current_io; //!< IO object to be used for prefetching.
int m_ios_in_detach; //!< Number of IO objects to which we replied false to ioActive() and will be removed soon.

// fsync
std::vector<int> m_writes_during_sync;
Expand Down

0 comments on commit 442a084

Please sign in to comment.