diff --git a/lib/backupstore/BackupFileSystem.cpp b/lib/backupstore/BackupFileSystem.cpp index 61323a723..911b09490 100644 --- a/lib/backupstore/BackupFileSystem.cpp +++ b/lib/backupstore/BackupFileSystem.cpp @@ -56,6 +56,8 @@ #include "MemLeakFindOn.h" +const FileSystemCategory BackupFileSystem::LOCKING("Locking"); + void BackupFileSystem::GetLock(int max_tries) { if(HaveLock()) @@ -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; } } @@ -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()) diff --git a/lib/backupstore/BackupFileSystem.h b/lib/backupstore/BackupFileSystem.h index b19273cf0..297aed1f3 100644 --- a/lib/backupstore/BackupFileSystem.h +++ b/lib/backupstore/BackupFileSystem.h @@ -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 @@ -151,6 +160,8 @@ class BackupFileSystem return mapPermanentRefCountDatabase.get(); } + static const FileSystemCategory LOCKING; + protected: virtual void TryGetLock() = 0; virtual std::auto_ptr GetBackupStoreInfoInternal(bool ReadOnly) = 0;