Skip to content

Commit

Permalink
Move sync opearations from destructor to ioActive.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Oct 13, 2016
1 parent 5dad907 commit 2789d3c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/XrdFileCache/XrdFileCacheFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "XrdFileCacheFile.hh"
#include "XrdFileCacheIO.hh"
#include "XrdFileCacheTrace.hh"

#include <stdio.h>
#include <sstream>
#include <fcntl.h>
Expand Down Expand Up @@ -88,7 +87,8 @@ File::File(IO *io, std::string& disk_file_path, long long iOffset, long long iFi
m_prefetchState(kOff),
m_prefetchReadCnt(0),
m_prefetchHitCnt(0),
m_prefetchScore(1)
m_prefetchScore(1),
m_detachTimeIsLogged(false)
{
Open();
}
Expand All @@ -97,24 +97,15 @@ File::~File()
{
if (m_infoFile)
{
m_downloadCond.Lock();
bool need_sync = (!m_writes_during_sync.empty()) || m_non_flushed_cnt > 0;
m_downloadCond.UnLock();
if (need_sync)
Sync();

// write statistics in *cinfo file
m_cfi.WriteHeader(m_infoFile);
AppendIOStatToFileInfo();
m_infoFile->Fsync();

TRACEF(Debug, "File::~File() close info ");
m_infoFile->Close();
delete m_infoFile;
m_infoFile = NULL;
}

if (m_output)
{
TRACEF(Debug, "File::~File() close output ");
m_output->Close();
delete m_output;
m_output = NULL;
Expand Down Expand Up @@ -145,6 +136,9 @@ bool File::ioActive()

TRACEF(Debug, "File::ioActive start");

if (!m_is_open) return false;


// remove failed blocks and check if map is empty
m_downloadCond.Lock();

Expand Down Expand Up @@ -184,13 +178,38 @@ bool File::ioActive()

if (blockMapEmpty)
{
// file is not active when block map is empty and sync is done
XrdSysCondVarHelper _lck(&m_downloadCond);
if ( ! m_in_sync)
{
m_in_sync = true;
return false;
}
// file is not active when block map is empty and sync is done
bool schedule_sync = false;

{
XrdSysCondVarHelper _lck(m_downloadCond);

if (m_in_sync) return true;

if (m_writes_during_sync.empty() && m_non_flushed_cnt == 0)
{
if (!m_detachTimeIsLogged) {
AppendIOStatToFileInfo();
m_detachTimeIsLogged = true;
schedule_sync = true;
}
}
else
{
// write leftovers
schedule_sync = true;
}

if (schedule_sync)
m_in_sync = true;
}

if (schedule_sync) {
XrdPosixGlobals::schedP->Schedule(m_syncer);
}
else {
return false;
}
}

return true;
Expand Down
1 change: 1 addition & 0 deletions src/XrdFileCache/XrdFileCacheFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace XrdFileCache
int m_prefetchReadCnt;
int m_prefetchHitCnt;
float m_prefetchScore; //cached
bool m_detachTimeIsLogged;

static const char *m_traceID;

Expand Down

0 comments on commit 2789d3c

Please sign in to comment.