Skip to content

Commit

Permalink
BackupCommands and BackupStoreContext: use GetAccountIdentifier()
Browse files Browse the repository at this point in the history
Generalises account identification from bbstored to S3.
  • Loading branch information
qris committed Jun 7, 2018
1 parent 5e0a55a commit 9b9ec82
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
23 changes: 10 additions & 13 deletions lib/backupstore/BackupCommands.cpp
Expand Up @@ -161,8 +161,8 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtoc
// See if the context will get the lock
if(!rContext.AttemptToGetWriteLock())
{
BOX_WARNING("Failed to get write lock for Client ID " <<
BOX_FORMAT_ACCOUNT(mClientID));
BOX_WARNING("Failed to get write lock for account " <<
rContext.GetAccountIdentifier());
return PROTOCOL_ERROR(Err_CannotLockStoreForWriting);
}

Expand All @@ -175,8 +175,8 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtoc

if(!rContext.GetBackupStoreInfo().IsAccountEnabled())
{
BOX_WARNING("Refused login from disabled client ID " <<
BOX_FORMAT_ACCOUNT(mClientID));
BOX_WARNING("Refused login from disabled account " <<
rContext.GetAccountIdentifier());
return PROTOCOL_ERROR(Err_DisabledAccount);
}

Expand All @@ -187,12 +187,9 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtoc
rContext.SetPhase(BackupStoreContext::Phase_Commands);

// Log login
BOX_NOTICE("Login from Client ID " <<
BOX_FORMAT_ACCOUNT(mClientID) << " "
"(name=" << rContext.GetAccountName() << "): " <<
(((mFlags & Flags_ReadOnly) != Flags_ReadOnly)
?"Read/Write":"Read-only") << " from " <<
rContext.GetConnectionDetails());
BOX_NOTICE("Login for account " << rContext.GetAccountIdentifier() << ": " <<
(((mFlags & Flags_ReadOnly) != Flags_ReadOnly) ? "Read/Write" : "Read-only") << " "
"from " << rContext.GetConnectionDetails());

// Get the usage info for reporting to the client
int64_t blocksUsed = 0, blocksSoftLimit = 0, blocksHardLimit = 0;
Expand All @@ -214,9 +211,9 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolFinished::DoCommand(BackupPro
{
// can be called in any phase

BOX_NOTICE("Session finished for Client ID " <<
BOX_FORMAT_ACCOUNT(rContext.GetClientID()) << " "
"(name=" << rContext.GetAccountName() << ")");
BOX_NOTICE("Session finished for account " << rContext.GetAccountIdentifier() << ": " <<
(((mFlags & Flags_ReadOnly) != Flags_ReadOnly) ? "Read/Write" : "Read-only") << " "
"from " << rContext.GetConnectionDetails());

// Let the context know about it
rContext.CleanUp();
Expand Down
21 changes: 19 additions & 2 deletions lib/backupstore/BackupStoreContext.cpp
Expand Up @@ -315,7 +315,7 @@ void BackupStoreContext::LoadStoreInfo()
// backup data.
THROW_EXCEPTION_MESSAGE(BackupStoreException,
CorruptReferenceCountDatabase, "Account " <<
BOX_FORMAT_ACCOUNT(mClientID) << " reference count database is "
mpFileSystem->GetAccountIdentifier() << " reference count database is "
"missing or corrupted, cannot safely open account. Housekeeping "
"will fix this automatically when it next runs.");
}
Expand Down Expand Up @@ -1566,7 +1566,7 @@ std::vector<int64_t> BackupStoreContext::GetPatchChain(int64_t ObjectID, int64_t
PatchChainInfoBadInDirectory,
"Object " << BOX_FORMAT_OBJECTID(ObjectID) <<
" in dir " << BOX_FORMAT_OBJECTID(InDirectory) <<
" for account " << BOX_FORMAT_ACCOUNT(mClientID) <<
" for account " << mpFileSystem->GetAccountIdentifier() <<
" references object " << BOX_FORMAT_OBJECTID(id) <<
" which does not exist in dir");
}
Expand Down Expand Up @@ -1658,6 +1658,23 @@ std::auto_ptr<IOStream> BackupStoreContext::GetBlockIndexReconstructed(int64_t O
}
}

std::string BackupStoreContext::GetAccountIdentifier()
{
if(mpFileSystem != NULL)
{
return mpFileSystem->GetAccountIdentifier();
}
else
{
// This can happen if this BackupStoreContext was constructed without a
// BackupFileSystem, in which case mClientID is the account number from the SSL
// certificate.
std::ostringstream oss;
oss << "unknown (" << BOX_FORMAT_ACCOUNT(mClientID) << ")";
return oss.str();
}
}

// --------------------------------------------------------------------------
//
// Function
Expand Down
1 change: 1 addition & 0 deletions lib/backupstore/BackupStoreContext.h
Expand Up @@ -202,6 +202,7 @@ class BackupStoreContext
// Info
int32_t GetClientID() const {return mClientID;}
const std::string& GetConnectionDetails() { return mConnectionDetails; }
std::string GetAccountIdentifier();
virtual int GetBlockSize() { return mpFileSystem->GetBlockSize(); }

// This is not an API, but it's useful in tests with multiple contexts, to allow
Expand Down

0 comments on commit 9b9ec82

Please sign in to comment.