Skip to content

Commit

Permalink
Fix possible crash when scheduler calls disk sync at the time of dest…
Browse files Browse the repository at this point in the history
…ruction.
  • Loading branch information
alja authored and abh3 committed Jun 30, 2016
1 parent 4701b80 commit 68daa46
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/XrdFileCache/XrdFileCacheFile.cc
Expand Up @@ -110,21 +110,6 @@ File::~File()
clLog()->Debug(XrdCl::AppMsg, "File::~File() enter %p %s", (void*)this, lPath());


// Wait disk sync
bool do_sync = false;
{
XrdSysMutexHelper _lck(&m_syncStatusMutex);
if (m_non_flushed_cnt > 0 || !m_writes_during_sync.empty())
{
do_sync = true;
m_in_sync = true;
clLog()->Info(XrdCl::AppMsg, "File::~File sync unflushed %d\n", m_non_flushed_cnt);
}
}
if (do_sync)
{
Sync();
}
// write statistics in *cinfo file
AppendIOStatToFileInfo();

Expand All @@ -142,7 +127,11 @@ File::~File()
delete m_infoFile;
m_infoFile = NULL;
}
delete m_syncer;

m_syncStatusMutex.Lock();
bool syncEmpty = m_writes_during_sync.empty();
m_syncStatusMutex.UnLock();
if (!syncEmpty) Sync();

// print just for curiosity
clLog()->Debug(XrdCl::AppMsg, "File::~File() ended, prefetch score ...%d/%d=%.2f", m_prefetchHitCnt, m_prefetchReadCnt, m_prefetchScore);
Expand Down Expand Up @@ -192,7 +181,15 @@ bool File::InitiateClose()
m_downloadCond.UnLock();

if ( blockMapEmpty)
return false;
{
// file is not active when block map is empty and sync is done
XrdSysMutexHelper _lck(&m_syncStatusMutex);
if (m_in_sync) {
delete m_syncer;
m_syncer = NULL;
return false;
}
}
}

return true;
Expand Down Expand Up @@ -724,13 +721,13 @@ void File::WriteBlockToDisk(Block* b)
{
m_cfi.SetBitWriteCalled(pfIdx);
++m_non_flushed_cnt;
}
if (m_non_flushed_cnt >= 100 )
{
schedule_sync = true;
m_in_sync = true;
m_non_flushed_cnt = 0;
}

if (m_non_flushed_cnt >= 100 )
{
schedule_sync = true;
m_in_sync = true;
m_non_flushed_cnt = 0;
}
}

Expand Down

0 comments on commit 68daa46

Please sign in to comment.