From ebde60968b129a92783b8eb9f04c001fa1df6bdc Mon Sep 17 00:00:00 2001 From: upstream svn Date: Sat, 27 Aug 2011 20:28:32 +0000 Subject: [PATCH] Don't write known.met after hashing 30 files For large files it's written anyway after 300MB, and for many small files it totally screws up the "hashing in the background" concept, because it's written in the foreground. Also initialize a variable and open then known file database in read-only mode. --- .svn-revision | 2 +- docs/Changelog | 1 + src/ThreadTasks.cpp | 48 ++++++++++++++++++++++++++++++------------------ src/amule.cpp | 9 +++------ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.svn-revision b/.svn-revision index 63836ad3..39021331 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10600 +10601 diff --git a/docs/Changelog b/docs/Changelog index 2747de8d..dd3327c5 100644 --- a/docs/Changelog +++ b/docs/Changelog @@ -240,6 +240,7 @@ Version 2.3.0 - The river knows. * Prevent creation of more than 99 categories, since that's the limit * Fixed saving of sort orders * Allow switching through files in file detail dialog + * Improve performance when many small files are hashed Vollstrecker: * Unify copyright lines diff --git a/src/ThreadTasks.cpp b/src/ThreadTasks.cpp index 259e5069..089ae8ff 100644 --- a/src/ThreadTasks.cpp +++ b/src/ThreadTasks.cpp @@ -273,16 +273,26 @@ void CAICHSyncTask::Entry() const CPath fullpath = CPath(theApp->ConfigDir + KNOWN2_MET_FILENAME); CFile file; - if (!file.Open(fullpath, (fullpath.FileExists() ? CFile::read_write : CFile::write))) { - AddDebugLogLineC( logAICHThread, wxT("Error, failed to open 'known2_64.met' file!") ); - return; - } - - uint32 nLastVerifiedPos = 0; - try { - if (file.Eof()) { + if (!fullpath.FileExists()) { + // File does not exist. Try to create it to see if it can be created at all (and don't start hashing otherwise). + if (!file.Open(fullpath, CFile::write)) { + AddDebugLogLineC( logAICHThread, wxT("Error, failed to open 'known2_64.met' file!") ); + return; + } + try { file.WriteUInt8(KNOWN2_MET_VERSION); - } else { + } catch (const CIOFailureException& e) { + AddDebugLogLineC(logAICHThread, wxT("IO failure while creating hashlist (Aborting): ") + e.what()); + return; + } + } else { + if (!file.Open(fullpath, CFile::read)) { + AddDebugLogLineC( logAICHThread, wxT("Error, failed to open 'known2_64.met' file!") ); + return; + } + + uint32 nLastVerifiedPos = 0; + try { if (file.ReadUInt8() != KNOWN2_MET_VERSION) { throw CEOFException(wxT("Invalid met-file header found, removing file.")); } @@ -300,17 +310,19 @@ void CAICHSyncTask::Entry() // skip the rest of this hashset nLastVerifiedPos = file.Seek(nHashCount * HASHSIZE, wxFromCurrent); } - } - } catch (const CEOFException&) { - AddDebugLogLineC(logAICHThread, wxT("Hashlist corrupted, truncating file.")); - file.SetLength(nLastVerifiedPos); - } catch (const CIOFailureException& e) { - AddDebugLogLineC(logAICHThread, wxT("IO failure while reading hashlist (Aborting): ") + e.what()); + } catch (const CEOFException&) { + AddDebugLogLineC(logAICHThread, wxT("Hashlist corrupted, truncating file.")); + file.Close(); + file.Reopen(CFile::read_write); + file.SetLength(nLastVerifiedPos); + } catch (const CIOFailureException& e) { + AddDebugLogLineC(logAICHThread, wxT("IO failure while reading hashlist (Aborting): ") + e.what()); - return; - } + return; + } - AddDebugLogLineN( logAICHThread, wxT("Masterhashes of known files have been loaded.") ); + AddDebugLogLineN( logAICHThread, wxT("Masterhashes of known files have been loaded.") ); + } // Now we check that all files which are in the sharedfilelist have a // corresponding hash in our list. Those how don't are queued for hashing. diff --git a/src/amule.cpp b/src/amule.cpp index 2db721ff..67c1882e 100644 --- a/src/amule.cpp +++ b/src/amule.cpp @@ -1268,22 +1268,19 @@ void CamuleApp::OnFinishedHashing(CHashingEvent& evt) dynamic_cast(owner)->PartFileHashFinished(result); } } else { - static int filecount; - static uint64 bytecount; + static uint64 bytecount = 0; if (knownfiles->SafeAddKFile(result, true)) { AddDebugLogLineN(logKnownFiles, CFormat(wxT("Safe adding file to sharedlist: %s")) % result->GetFileName()); sharedfiles->SafeAddKFile(result); - filecount++; bytecount += result->GetFileSize(); - // If we have added 30 files or files with a total size of ~300mb - if ( ( filecount == 30 ) || ( bytecount >= 314572800 ) ) { + // If we have added files with a total size of ~300mb + if (bytecount >= 314572800) { AddDebugLogLineN(logKnownFiles, wxT("Failsafe for crash on file hashing creation")); if ( m_app_state != APP_STATE_SHUTTINGDOWN ) { knownfiles->Save(); - filecount = 0; bytecount = 0; } } -- 2.11.4.GIT