Skip to content

Commit

Permalink
Refactor BackupStoreCheck to use BackupFileSystem, part 1
Browse files Browse the repository at this point in the history
Pass the BackupFileSystem from BackupAccountControl to BackupStoreCheck, and
use it for locking the account (actually a no-op because it's already locked).
Trivial, but it's a start.
  • Loading branch information
qris committed Oct 7, 2017
1 parent c5466cc commit 7b8a48f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/backupstore/BackupAccountControl.cpp
Expand Up @@ -443,7 +443,7 @@ int BackupStoreAccountControl::CheckAccount(bool FixErrors, bool Quiet,
OPEN_ACCOUNT(FixErrors); // readWrite

// Check it
BackupStoreCheck check(mRootDir, mDiscSetNum, mAccountID, FixErrors, Quiet);
BackupStoreCheck check(*mapFileSystem, mRootDir, mDiscSetNum, FixErrors, Quiet);
check.Check();

if(ReturnNumErrorsFound)
Expand Down
28 changes: 16 additions & 12 deletions lib/backupstore/BackupStoreCheck.cpp
Expand Up @@ -17,6 +17,7 @@
#endif

#include "autogen_BackupStoreException.h"
#include "BackupFileSystem.h"
#include "BackupStoreAccountDatabase.h"
#include "BackupStoreCheck.h"
#include "BackupStoreConstants.h"
Expand All @@ -38,21 +39,25 @@
// --------------------------------------------------------------------------
//
// Function
// Name: BackupStoreCheck::BackupStoreCheck(const std::string &, int, int32_t, bool, bool)
// Name: BackupStoreCheck::BackupStoreCheck(const std::string &,
// int, int32_t, bool, bool)
// Purpose: Constructor
// Created: 21/4/04
//
// --------------------------------------------------------------------------
BackupStoreCheck::BackupStoreCheck(const std::string &rStoreRoot, int DiscSetNumber, int32_t AccountID, bool FixErrors, bool Quiet)
BackupStoreCheck::BackupStoreCheck(BackupFileSystem& FileSystem,
const std::string &rStoreRoot, int DiscSetNumber, bool FixErrors,
bool Quiet)
: mStoreRoot(rStoreRoot),
mDiscSetNumber(DiscSetNumber),
mAccountID(AccountID),
mAccountID(FileSystem.GetAccountID()), // will be 0 for S3BackupFileSystem
mFixErrors(FixErrors),
mQuiet(Quiet),
mNumberErrorsFound(0),
mLastIDInInfo(0),
mpInfoLastBlock(0),
mInfoLastBlockEntries(0),
mrFileSystem(FileSystem),
mLostDirNameSerial(0),
mLostAndFoundDirectoryID(0),
mBlocksUsed(0),
Expand Down Expand Up @@ -114,9 +119,8 @@ void BackupStoreCheck::Check()
{
if(mFixErrors)
{
std::string writeLockFilename;
StoreStructure::MakeWriteLockFilename(mStoreRoot, mDiscSetNumber, writeLockFilename);
ASSERT(FileExists(writeLockFilename));
// Will throw an exception if it doesn't manage to get a lock:
mrFileSystem.TryGetLock();
}

if(!mQuiet && mFixErrors)
Expand Down Expand Up @@ -164,8 +168,8 @@ void BackupStoreCheck::Check()
// Phase 1, check objects
if(!mQuiet)
{
BOX_INFO("Checking store account ID " <<
BOX_FORMAT_ACCOUNT(mAccountID) << "...");
BOX_INFO("Checking account " << mrFileSystem.GetAccountIdentifier() <<
"...");
BOX_INFO("Phase 1, check objects...");
}
CheckObjects();
Expand Down Expand Up @@ -232,8 +236,8 @@ void BackupStoreCheck::Check()

if(mNumberErrorsFound > 0)
{
BOX_WARNING("Finished checking store account ID " <<
BOX_FORMAT_ACCOUNT(mAccountID) << ": " <<
BOX_WARNING("Finished checking account " <<
mrFileSystem.GetAccountIdentifier() << ": " <<
mNumberErrorsFound << " errors found");

if(!mFixErrors)
Expand Down Expand Up @@ -266,8 +270,8 @@ void BackupStoreCheck::Check()
}
else
{
BOX_NOTICE("Finished checking store account ID " <<
BOX_FORMAT_ACCOUNT(mAccountID) << ": "
BOX_NOTICE("Finished checking account " <<
mrFileSystem.GetAccountIdentifier() << ": " <<
"no errors found");
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/backupstore/BackupStoreCheck.h
Expand Up @@ -15,11 +15,10 @@
#include <vector>
#include <set>

#include "NamedLock.h"
#include "BackupStoreDirectory.h"

class IOStream;
class BackupStoreFilename;
class BackupFileSystem;
class BackupStoreRefCountDatabase;

/*
Expand Down Expand Up @@ -74,7 +73,8 @@ typedef int64_t BackupStoreCheck_Size_t;
class BackupStoreCheck
{
public:
BackupStoreCheck(const std::string &rStoreRoot, int DiscSetNumber, int32_t AccountID, bool FixErrors, bool Quiet);
BackupStoreCheck(BackupFileSystem& rFileSystem, const std::string &rStoreRoot,
int DiscSetNumber, bool FixErrors, bool Quiet);
~BackupStoreCheck();

private:
Expand Down Expand Up @@ -180,9 +180,6 @@ class BackupStoreCheck

int64_t mNumberErrorsFound;

// Lock for the store account
NamedLock mAccountLock;

// Storage for ID data
typedef std::map<BackupStoreCheck_ID_t, IDBlock*> Info_t;
Info_t mInfo;
Expand All @@ -202,6 +199,9 @@ class BackupStoreCheck
// The refcount database, being reconstructed as the check/fix progresses
std::auto_ptr<BackupStoreRefCountDatabase> mapNewRefs;

// Abstracted interface to software-RAID filesystem
BackupFileSystem& mrFileSystem;

// Misc stuff
int32_t mLostDirNameSerial;
int64_t mLostAndFoundDirectoryID;
Expand Down
1 change: 1 addition & 0 deletions lib/backupstore/BackupStoreCheck2.cpp
Expand Up @@ -13,6 +13,7 @@
#include <string.h>

#include "autogen_BackupStoreException.h"
#include "BackupFileSystem.h"
#include "BackupStoreCheck.h"
#include "BackupStoreConstants.h"
#include "BackupStoreDirectory.h"
Expand Down

0 comments on commit 7b8a48f

Please sign in to comment.