diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-02-07 23:05:04 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-02-07 23:05:04 +0000 |
commit | 58f09a365624705b25d29aa3caeefa0d97d1c9ba (patch) | |
tree | 3953575fa781527d604b2a03d64db6ecc551a849 /lib/backupstore/BackupStoreRefCountDatabase.h | |
parent | b8d2733b33c1dd2491c60fe9f68f612e6de503e4 (diff) |
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).
Diffstat (limited to 'lib/backupstore/BackupStoreRefCountDatabase.h')
-rw-r--r-- | lib/backupstore/BackupStoreRefCountDatabase.h | 36 |
1 files changed, 16 insertions, 20 deletions
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 <vector> #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<FileStream> 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<BackupStoreRefCountDatabase> Create + (const BackupStoreAccountDatabase::Entry& rAccount); + void Commit(); + void Discard(); // Load it from the store static std::auto_ptr<BackupStoreRefCountDatabase> 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<FileStream> mapDatabaseFile; + + bool NeedsCommitOrDiscard() + { + return mapDatabaseFile.get() && mIsModified && mIsTemporaryFile; + } }; #endif // BACKUPSTOREREFCOUNTDATABASE__H |