Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent open files leak fix #2

Merged
merged 4 commits into from Feb 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions stringtools.cpp
Expand Up @@ -1727,6 +1727,8 @@ std::string PrettyPrintTime(int64 ms)
unsigned int c_h=c_m*60;
unsigned int c_d=c_h*24;

int64 orig = ms;

if( ms>c_d)
{
int64 t=ms/c_d;
Expand Down Expand Up @@ -1759,5 +1761,11 @@ std::string PrettyPrintTime(int64 ms)
ms-=t*c_s;
}

if( orig < c_s)
{
if(!ret.empty()) ret+=" ";
ret+=nconvert(ms)+"ms";
}

return ret;
}
48 changes: 39 additions & 9 deletions urbackupclient/ChangeJournalWatcher.cpp
Expand Up @@ -1040,7 +1040,10 @@ void ChangeJournalWatcher::update(std::wstring vol_str)
{
for(std::map<std::wstring, bool>::iterator it=local_open_write_files.begin();it!=local_open_write_files.end();++it)
{
open_write_files.add(it->first);
if(!it->second)
{
open_write_files.add(it->first);
}
}
open_write_files.flushf();
db->EndTransaction();
Expand All @@ -1049,6 +1052,7 @@ void ChangeJournalWatcher::update(std::wstring vol_str)

void ChangeJournalWatcher::update_longliving(void)
{
db->BeginTransaction();
if(!freeze_open_write_files)
{
std::vector<std::wstring> files = open_write_files.get();
Expand All @@ -1064,6 +1068,8 @@ void ChangeJournalWatcher::update_longliving(void)
listener->On_FileModified(it->first, true);
}
}
db->EndTransaction();

for(size_t i=0;i<error_dirs.size();++i)
{
listener->On_ResetAll(error_dirs[i]);
Expand Down Expand Up @@ -1143,7 +1149,23 @@ void ChangeJournalWatcher::logEntry(const std::wstring &vol, const UsnInt *UsnRe
Server->Log(lstr, LL_DEBUG);
}

const DWORD watch_flags=USN_REASON_DATA_EXTEND | USN_REASON_EA_CHANGE | USN_REASON_HARD_LINK_CHANGE | USN_REASON_NAMED_DATA_EXTEND | USN_REASON_NAMED_DATA_OVERWRITE| USN_REASON_NAMED_DATA_TRUNCATION| USN_REASON_REPARSE_POINT_CHANGE| USN_REASON_SECURITY_CHANGE| USN_REASON_STREAM_CHANGE| USN_REASON_DATA_TRUNCATION | USN_REASON_BASIC_INFO_CHANGE | USN_REASON_DATA_OVERWRITE | USN_REASON_FILE_CREATE | USN_REASON_FILE_DELETE | USN_REASON_RENAME_NEW_NAME | USN_REASON_TRANSACTED_CHANGE;
const DWORD watch_flags=\
USN_REASON_BASIC_INFO_CHANGE | \
USN_REASON_DATA_EXTEND | \
USN_REASON_DATA_OVERWRITE | \
USN_REASON_DATA_TRUNCATION | \
USN_REASON_EA_CHANGE | \
USN_REASON_FILE_CREATE | \
USN_REASON_FILE_DELETE | \
USN_REASON_HARD_LINK_CHANGE | \
USN_REASON_NAMED_DATA_EXTEND | \
USN_REASON_NAMED_DATA_OVERWRITE | \
USN_REASON_NAMED_DATA_TRUNCATION | \
USN_REASON_RENAME_NEW_NAME | \
USN_REASON_REPARSE_POINT_CHANGE| \
USN_REASON_SECURITY_CHANGE | \
USN_REASON_STREAM_CHANGE | \
USN_REASON_TRANSACTED_CHANGE;

void ChangeJournalWatcher::updateWithUsn(const std::wstring &vol, const SChangeJournal &cj, const UsnInt *UsnRecord, bool fallback_to_mft, std::map<std::wstring, bool>& local_open_write_files)
{
Expand Down Expand Up @@ -1311,12 +1333,16 @@ void ChangeJournalWatcher::updateWithUsn(const std::wstring &vol, const SChangeJ
}
else
{
if(UsnRecord->Reason & USN_REASON_CLOSE)
if(UsnRecord->Reason & (USN_REASON_CLOSE | USN_REASON_RENAME_OLD_NAME))
{
std::map<std::wstring, bool>::iterator it_rf=local_open_write_files.find(real_fn);

if(it_rf!=local_open_write_files.end())
{
if(it_rf->second)
{
open_write_files.remove(real_fn);
}
local_open_write_files.erase(it_rf);
}
else
Expand All @@ -1326,17 +1352,21 @@ void ChangeJournalWatcher::updateWithUsn(const std::wstring &vol, const SChangeJ
}
else if(UsnRecord->Reason & watch_flags)
{
local_open_write_files[real_fn]=true;
if(freeze_open_write_files)
std::map<std::wstring, bool>::iterator it_rf=local_open_write_files.find(real_fn);

if(it_rf==local_open_write_files.end())
{
open_write_files_frozen[real_fn]=true;
local_open_write_files[real_fn]=open_write_files.is_present(real_fn);

if(freeze_open_write_files)
{
open_write_files_frozen[real_fn]=true;
}
}
}
}

if( (UsnRecord->Reason & USN_REASON_RENAME_OLD_NAME)
|| (UsnRecord->Reason & watch_flags) )
if(UsnRecord->Reason & (watch_flags | USN_REASON_RENAME_OLD_NAME))
{
bool save_fn=false;
if( UsnRecord->Reason & USN_REASON_BASIC_INFO_CHANGE )
Expand Down
5 changes: 5 additions & 0 deletions urbackupclient/PersistentOpenFiles.cpp
Expand Up @@ -255,6 +255,11 @@ void PersistentOpenFiles::add( const std::wstring& fn )
}
}

bool PersistentOpenFiles::is_present( const std::wstring& fn )
{
return (open_files.find(fn)!=open_files.end());
}

PersistentOpenFiles::PersistentOpenFiles() : curr_id(0), bytes_written(0), bytes_deleted(0)
{
persistf = Server->openFile(persistent_open_files_fn, MODE_RW_CREATE);
Expand Down
2 changes: 2 additions & 0 deletions urbackupclient/PersistentOpenFiles.h
Expand Up @@ -23,6 +23,8 @@ class PersistentOpenFiles

void remove(const std::wstring& fn);

bool is_present(const std::wstring& fn);

std::vector<std::wstring> get();

bool flushf();
Expand Down