From: Andrew Kryczka Date: Wed, 8 Sep 2021 20:37:59 +0000 (-0700) Subject: prevent stranded LATEST_BACKUP in BackupEngineTest.NoDeleteWithReadOnly (#8887) X-Git-Tag: v6.25.1~47 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dd092c2d11f74ef2005c75e6168323d4f30c644a;p=rocksdb.git 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 --- diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index fc515a36b..2d4cfc1f0 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -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;