Skip to content

Commit

Permalink
BackupStoreCheck: fix failure to compare refcounts of last object ID
Browse files Browse the repository at this point in the history
Fix test that would randomly detect an extra change to the refcount of an
object, depending if the test broke the object with the highest unused object
ID (which depended on upload order).

Add ability to ignore changes to a specific object ID, and use it to ignore
changes to any newly-created lost+found directory, as these are expected.

(cherry picked from commit b911cb8)
(cherry picked from commit b416481)
  • Loading branch information
qris committed May 14, 2019
1 parent ab4c10a commit cbea196
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/backupstore/BackupStoreCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ void BackupStoreCheck::Check()

try
{
// We should be able to load a reference to the old refcount database
// (read-only) at the same time that we have a reference to the new one
// (temporary) open but not yet committed.
std::auto_ptr<BackupStoreRefCountDatabase> apOldRefs =
BackupStoreRefCountDatabase::Load(account, false);
mNumberErrorsFound += mapNewRefs->ReportChangesTo(*apOldRefs);

// If we have created a new lost+found directory (and thus allocated it a nonzero
// object ID) then it's not surprising that the previous refcount DB did not have
// a reference to this directory, and not an error, so ignore it.
mNumberErrorsFound += mapNewRefs->ReportChangesTo(*apOldRefs,
mLostAndFoundDirectoryID); // ignore_object_id
}
catch(BoxException &e)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/backupstore/BackupStoreCheck2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int64_t BackupStoreCheck::GetLostAndFoundDirID()
if(!mFixErrors)
{
// The result will never be used anyway if errors aren't being fixed
return 1;
return 0;
}

// Load up the root directory
Expand Down
11 changes: 8 additions & 3 deletions lib/backupstore/BackupStoreRefCountDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,22 @@ bool BackupStoreRefCountDatabase::RemoveReference(int64_t ObjectID)
return (refcount > 0);
}

int BackupStoreRefCountDatabase::ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs)
int BackupStoreRefCountDatabase::ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs,
int64_t ignore_object_id)
{
int ErrorCount = 0;
int64_t MaxOldObjectId = rOldRefs.GetLastObjectIDUsed();
int64_t MaxNewObjectId = GetLastObjectIDUsed();

for (int64_t ObjectID = BACKUPSTORE_ROOT_DIRECTORY_ID;
ObjectID < std::max(MaxOldObjectId, MaxNewObjectId);
ObjectID <= std::max(MaxOldObjectId, MaxNewObjectId);
ObjectID++)
{
typedef BackupStoreRefCountDatabase::refcount_t refcount_t;
if(ObjectID == ignore_object_id)
{
continue;
}

refcount_t OldRefs = (ObjectID <= MaxOldObjectId) ?
rOldRefs.GetRefCount(ObjectID) : 0;
refcount_t NewRefs = (ObjectID <= MaxNewObjectId) ?
Expand Down
3 changes: 2 additions & 1 deletion lib/backupstore/BackupStoreRefCountDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class BackupStoreRefCountDatabase
void AddReference(int64_t ObjectID);
// RemoveReference returns false if refcount drops to zero
bool RemoveReference(int64_t ObjectID);
int ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs);
int ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs,
int64_t ignore_object_id = 0);

private:
static std::string GetFilename(const BackupStoreAccountDatabase::Entry&
Expand Down

0 comments on commit cbea196

Please sign in to comment.