Skip to content

Commit

Permalink
Fix writeback of refcount databases on BackupFileSystem destruction
Browse files Browse the repository at this point in the history
Call ReleaseLock in the child destructor (not the parent) to allow the refcount
database to clean itself up (normally involving calling
BackupFileSystem::SaveRefCountDatabase) before the BackupFileSystem is too
destroyed to be able to fulfil the request.
  • Loading branch information
qris committed Oct 7, 2017
1 parent c887635 commit 32a4c7b
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions lib/backupstore/BackupFileSystem.h
Expand Up @@ -54,7 +54,13 @@ class BackupFileSystem
virtual void ReleaseLock()
{
mapBackupStoreInfo.reset();
mapPotentialRefCountDatabase.reset();

if(mapPotentialRefCountDatabase.get())
{
mapPotentialRefCountDatabase->Discard();
mapPotentialRefCountDatabase.reset();
}

mapPermanentRefCountDatabase.reset();
}

Expand Down Expand Up @@ -183,26 +189,18 @@ class RaidBackupFileSystem : public BackupFileSystem
ASSERT(AccountRootDir[AccountRootDir.size() - 1] == '/' ||
AccountRootDir[AccountRootDir.size() - 1] == DIRECTORY_SEPARATOR_ASCHAR);
}
~RaidBackupFileSystem()
virtual ~RaidBackupFileSystem()
{
// Close any open refcount DBs before partially destroying the
// BackupFileSystem that they need to close down. Need to do this in the
// subclass to avoid calling SaveRefCountDatabase() when the subclass
// has already been partially destroyed.
// Call ReleaseLock() to close any open refcount DBs before
// partially destroying the BackupFileSystem that they need to
// close down. Need to do this in the subclass to avoid calling
// SaveRefCountDatabase() (from
// ~BackupStoreRefCountDatabaseWrapper) when the subclass has
// already been partially destroyed.
// http://stackoverflow.com/questions/10707286/how-to-resolve-pure-virtual-method-called
if(mapPotentialRefCountDatabase.get())
{
mapPotentialRefCountDatabase->Discard();
mapPotentialRefCountDatabase.reset();
}

mapPermanentRefCountDatabase.reset();

if(mWriteLock.GotLock())
{
ReleaseLock();
}
ReleaseLock();
}

virtual void TryGetLock();
virtual void ReleaseLock()
{
Expand Down Expand Up @@ -307,9 +305,19 @@ class S3BackupFileSystem : public BackupFileSystem
public:
S3BackupFileSystem(const Configuration& config, const std::string& BasePath,
const std::string& CacheDirectory, S3Client& rClient);
virtual ~S3BackupFileSystem()
{
// Call ReleaseLock() to close any open refcount DBs before
// partially destroying the BackupFileSystem that they need to
// close down. Need to do this in the subclass to avoid calling
// SaveRefCountDatabase() (from
// ~BackupStoreRefCountDatabaseWrapper) when the subclass has
// already been partially destroyed.
// http://stackoverflow.com/questions/10707286/how-to-resolve-pure-virtual-method-called
ReleaseLock();
}

virtual void TryGetLock() { }
virtual void ReleaseLock() { }
virtual bool HaveLock() { return false; }
virtual int GetBlockSize();
virtual void PutBackupStoreInfo(BackupStoreInfo& rInfo);
Expand Down

0 comments on commit 32a4c7b

Please sign in to comment.