prevent stranded LATEST_BACKUP in BackupEngineTest.NoDeleteWithReadOnly (#8887)

Summary:
A "LATEST_BACKUP" file was left in the backup directory by
"BackupEngineTest.NoDeleteWithReadOnly" test, affecting future test
runs. In particular, it caused "BackupEngineTest.IOStats" to fail since
it relies on backup directory containing only data written by its
`BackupEngine`.

The fix is to promote "LATEST_BACKUP" to an explicitly managed file so
it is deleted in `BackupEngineTest` constructor if it exists.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8887

Test Plan:
below command used to fail. Now it passes:

```
$ TEST_TMPDIR=/dev/shm ./backupable_db_test --gtest_filter='BackupEngineTest.NoDeleteWithReadOnly:BackupEngineTest.IOStats'
```

Reviewed By: pdillinger

Differential Revision: D30812336

Pulled By: ajkr

fbshipit-source-id: 32dfbe1368ebdab872e610764bfea5daf9a2af09
This commit is contained in:
Andrew Kryczka 2021-09-08 13:37:59 -07:00 committed by Facebook GitHub Bot
parent 91b95cadee
commit dd092c2d11

View File

@ -616,6 +616,7 @@ class BackupEngineTest : public testing::Test {
EXPECT_OK(Env::Default()->CreateDirIfMissing(backup_chroot));
dbname_ = "/tempdb";
backupdir_ = "/tempbk";
latest_backup_ = backupdir_ + "/LATEST_BACKUP";
// set up envs
db_chroot_env_.reset(NewChrootEnv(Env::Default(), db_chroot));
@ -663,6 +664,10 @@ class BackupEngineTest : public testing::Test {
// delete old files in db
DestroyDB(dbname_, options_);
// delete old LATEST_BACKUP file, which some tests create for compatibility
// testing.
backup_chroot_env_->DeleteFile(latest_backup_).PermitUncheckedError();
}
DB* OpenDB() {
@ -943,6 +948,7 @@ class BackupEngineTest : public testing::Test {
// files
std::string dbname_;
std::string backupdir_;
std::string latest_backup_;
// logger_ must be above backup_engine_ such that the engine's destructor,
// which uses a raw pointer to the logger, executes first.
@ -1853,7 +1859,7 @@ TEST_F(BackupEngineTest, NoDeleteWithReadOnly) {
ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), !!(rnd.Next() % 2)));
}
CloseDBAndBackupEngine();
ASSERT_OK(file_manager_->WriteToFile(backupdir_ + "/LATEST_BACKUP", "4"));
ASSERT_OK(file_manager_->WriteToFile(latest_backup_, "4"));
backupable_options_->destroy_old_data = false;
BackupEngineReadOnly* read_only_backup_engine;