diff --git a/db/db_sst_test.cc b/db/db_sst_test.cc index 595668891..d30ef67dd 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 12b267f3c..90c1e751e 100644 --- a/util/delete_scheduler.cc +++ b/util/delete_scheduler.cc @@ -148,6 +148,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; }