diff --git a/db/db_sst_test.cc b/db/db_sst_test.cc index 2220d0d2c..8a6a81764 100644 --- a/db/db_sst_test.cc +++ b/db/db_sst_test.cc @@ -376,6 +376,30 @@ TEST_F(DBSSTTest, RateLimitedDelete) { rocksdb::SyncPoint::GetInstance()->DisableProcessing(); } +TEST_F(DBSSTTest, OpenDBWithExistingTrash) { + Options options = CurrentOptions(); + + options.sst_file_manager.reset( + NewSstFileManager(env_, nullptr, "", 1024 * 1024 /* 1 MB/sec */)); + auto sfm = static_cast(options.sst_file_manager.get()); + + Destroy(last_options_); + + // Add some trash files to the db directory so the DB can clean them up + env_->CreateDirIfMissing(dbname_); + ASSERT_OK(WriteStringToFile(env_, "abc", dbname_ + "/" + "001.sst.trash")); + ASSERT_OK(WriteStringToFile(env_, "abc", dbname_ + "/" + "002.sst.trash")); + ASSERT_OK(WriteStringToFile(env_, "abc", dbname_ + "/" + "003.sst.trash")); + + // Reopen the DB and verify that it deletes existing trash files + ASSERT_OK(TryReopen(options)); + sfm->WaitForEmptyTrash(); + ASSERT_NOK(env_->FileExists(dbname_ + "/" + "001.sst.trash")); + ASSERT_NOK(env_->FileExists(dbname_ + "/" + "002.sst.trash")); + ASSERT_NOK(env_->FileExists(dbname_ + "/" + "003.sst.trash")); +} + + // Create a DB with 2 db_paths, and generate multiple files in the 2 // db_paths using CompactRangeOptions, make sure that files that were // deleted from first db_path were deleted using DeleteScheduler and diff --git a/util/delete_scheduler.cc b/util/delete_scheduler.cc index ccebba964..ec7e2f4d2 100644 --- a/util/delete_scheduler.cc +++ b/util/delete_scheduler.cc @@ -151,6 +151,7 @@ Status DeleteScheduler::MarkAsTrash(const std::string& file_path, Status s; if (DeleteScheduler::IsTrashFile(file_path)) { // This is already a trash file + *trash_file = file_path; return s; }