From 58f09a365624705b25d29aa3caeefa0d97d1c9ba Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 7 Feb 2014 23:05:04 +0000 Subject: Create new refcount database atomically during account check. Use a temporary refcount db for check instead of an in-memory vector. This avoid the memory usage problems created by using the vector on large accounts, but may require us to improve the efficiency of the refcount database itself to avoid large numbers of small I/O operations. That is very doable now that we're using a class for it. Fix some inconsistencies and mistakes in handling reference counts and info counters during account checks (more to come). --- lib/backupstore/BackupStoreRefCountDatabase.h | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'lib/backupstore/BackupStoreRefCountDatabase.h') diff --git a/lib/backupstore/BackupStoreRefCountDatabase.h b/lib/backupstore/BackupStoreRefCountDatabase.h index 93c79afb..f0c1222f 100644 --- a/lib/backupstore/BackupStoreRefCountDatabase.h +++ b/lib/backupstore/BackupStoreRefCountDatabase.h @@ -15,6 +15,7 @@ #include #include "BackupStoreAccountDatabase.h" +#include "BackupStoreConstants.h" #include "FileStream.h" class BackupStoreCheck; @@ -59,17 +60,17 @@ public: private: // Creation through static functions only BackupStoreRefCountDatabase(const BackupStoreAccountDatabase::Entry& - rAccount); + rAccount, bool ReadOnly, bool Temporary, + std::auto_ptr apDatabaseFile); // No copying allowed BackupStoreRefCountDatabase(const BackupStoreRefCountDatabase &); public: - // Create a new database for a new account. This method will refuse - // to overwrite any existing file. - static void CreateNew(const BackupStoreAccountDatabase::Entry& rAccount) - { - Create(rAccount, false); - } + // Create a new database for a new account. + static std::auto_ptr Create + (const BackupStoreAccountDatabase::Entry& rAccount); + void Commit(); + void Discard(); // Load it from the store static std::auto_ptr Load(const @@ -87,20 +88,9 @@ public: bool RemoveReference(int64_t ObjectID); private: - // Create a new database for an existing account. Used during - // account checking if opening the old database throws an exception. - // This method will overwrite any existing file. - static void CreateForRegeneration(const - BackupStoreAccountDatabase::Entry& rAccount) - { - Create(rAccount, true); - } - - static void Create(const BackupStoreAccountDatabase::Entry& rAccount, - bool AllowOverwrite); - static std::string GetFilename(const BackupStoreAccountDatabase::Entry& - rAccount); + rAccount, bool Temporary); + IOStream::pos_type GetSize() const { return mapDatabaseFile->GetPosition() + @@ -122,7 +112,13 @@ private: std::string mFilename; bool mReadOnly; bool mIsModified; + bool mIsTemporaryFile; std::auto_ptr mapDatabaseFile; + + bool NeedsCommitOrDiscard() + { + return mapDatabaseFile.get() && mIsModified && mIsTemporaryFile; + } }; #endif // BACKUPSTOREREFCOUNTDATABASE__H -- cgit v1.2.3