Skip to content

Commit

Permalink
Add detailed logging of BackupFileSystem locks
Browse files Browse the repository at this point in the history
This logging is categorised, so it can be enabled with fine-tuning using the -L
command-line option.
  • Loading branch information
qris committed Nov 20, 2017
1 parent 2b5b65b commit 7a2572c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/backupstore/BackupFileSystem.cpp
Expand Up @@ -56,6 +56,8 @@

#include "MemLeakFindOn.h"

const FileSystemCategory BackupFileSystem::LOCKING("Locking");

void BackupFileSystem::GetLock(int max_tries)
{
if(HaveLock())
Expand All @@ -82,11 +84,36 @@ void BackupFileSystem::GetLock(int max_tries)
((i < max_tries - 1) || max_tries == KEEP_TRYING_FOREVER))
{
// Sleep a bit, and try again, as long as we have retries left.

if(i == 0)
{
BOX_LOG_CATEGORY(Log::INFO, LOCKING, "Failed to lock "
"account " << GetAccountIdentifier() << ", "
"still trying...");
}
else if(i == 30)
{
BOX_LOG_CATEGORY(Log::WARNING, LOCKING, "Failed to lock "
"account " << GetAccountIdentifier() << " for "
"30 seconds, still trying...");
}

ShortSleep(MilliSecondsToBoxTime(1000), true);
// Will try again
}
else if(EXCEPTION_IS_TYPE(e, BackupStoreException,
CouldNotLockStoreAccount))
{
BOX_LOG_CATEGORY(Log::INFO, LOCKING, "Failed to lock account " <<
GetAccountIdentifier() << " after " << (i + 1) << " "
"attempts, giving up");
throw;
}
else
{
BOX_LOG_CATEGORY(Log::INFO, LOCKING, "Failed to lock account " <<
GetAccountIdentifier() << " " "with unexpected error: " <<
e.what());
throw;
}
}
Expand All @@ -100,6 +127,12 @@ void BackupFileSystem::GetLock(int max_tries)

void BackupFileSystem::ReleaseLock()
{
if(HaveLock())
{
BOX_LOG_CATEGORY(Log::TRACE, LOCKING, "Releasing lock on account " <<
GetAccountIdentifier());
}

mapBackupStoreInfo.reset();

if(mapPotentialRefCountDatabase.get())
Expand Down
11 changes: 11 additions & 0 deletions lib/backupstore/BackupFileSystem.h
Expand Up @@ -26,6 +26,15 @@ class BackupStoreInfo;
class Configuration;
class IOStream;

class FileSystemCategory : public Log::Category
{
public:
FileSystemCategory(const std::string& name)
: Log::Category(std::string("FileSystem/") + name)
{ }
};


// --------------------------------------------------------------------------
//
// Class
Expand Down Expand Up @@ -151,6 +160,8 @@ class BackupFileSystem
return mapPermanentRefCountDatabase.get();
}

static const FileSystemCategory LOCKING;

protected:
virtual void TryGetLock() = 0;
virtual std::auto_ptr<BackupStoreInfo> GetBackupStoreInfoInternal(bool ReadOnly) = 0;
Expand Down

0 comments on commit 7a2572c

Please sign in to comment.