Skip to content

Commit

Permalink
Implement RefCountDatabase methods in S3BackupFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Nov 11, 2017
1 parent 5560491 commit 02c1cf8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
43 changes: 42 additions & 1 deletion lib/backupstore/BackupFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,13 +1263,54 @@ BackupStoreRefCountDatabase& S3BackupFileSystem::GetPermanentRefCountDatabase(

BackupStoreRefCountDatabase& S3BackupFileSystem::GetPotentialRefCountDatabase()
{
if(mapPotentialRefCountDatabase.get())
{
return *mapPotentialRefCountDatabase;
}

// Creating the "official" temporary refcount DB is actually a change
// to the cache, even if you don't commit it, because it's in the same
// directory and would conflict with another process trying to do the
// same thing, so it requires that you hold the write lock.
GetCacheLock();

// It's dangerous to have two read-write databases open at the same time (it would
// be too easy to update the refcounts in the wrong one by mistake), and temporary
// databases are always read-write, so if a permanent database is already open
// then it must be a read-only one.
ASSERT(!mapPermanentRefCountDatabase.get() ||
mapPermanentRefCountDatabase->IsReadOnly());

// The temporary database cannot be on the remote server, so there is no need to
// download it into the cache. Just create one and return it.
std::string local_path = GetRefCountDatabaseCachePath();

// We deliberately do not give the caller control of the
// reuse_existing_file parameter to Create(), because that would make
// it easy to bypass the restriction of only one (committable)
// temporary database at a time, and to accidentally overwrite the main
// refcount DB.
std::auto_ptr<BackupStoreRefCountDatabase> ap_new_db =
BackupStoreRefCountDatabase::Create(local_path, S3_FAKE_ACCOUNT_ID);
mapPotentialRefCountDatabase.reset(
new BackupStoreRefCountDatabaseWrapper(ap_new_db, *this));

return *mapPotentialRefCountDatabase;
}


void S3BackupFileSystem::SaveRefCountDatabase(BackupStoreRefCountDatabase& refcount_db)
{
ASSERT(false);
// You can only save the permanent database.
ASSERT(&refcount_db == mapPermanentRefCountDatabase.get());

std::string local_path = GetRefCountDatabaseCachePath();
FileStream fs(local_path, O_RDONLY);

// Try to upload it to the remote server.
HTTPResponse response = mrClient.PutObject(GetMetadataURI(S3_REFCOUNT_FILE_NAME),
fs);
mrClient.CheckResponse(response, "Failed to upload refcount db to S3");
}


Expand Down
4 changes: 4 additions & 0 deletions lib/backupstore/BackupFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ class S3BackupFileSystem : public BackupFileSystem
{
return (bytes + S3_NOTIONAL_BLOCK_SIZE - 1) / S3_NOTIONAL_BLOCK_SIZE;
}
std::string GetRefCountDatabaseCachePath()
{
return mCacheDirectory + DIRECTORY_SEPARATOR + S3_REFCOUNT_FILE_NAME;
}
void GetCacheLock();

public:
Expand Down

0 comments on commit 02c1cf8

Please sign in to comment.