From 9089373a011e08b8a9116128bdcb3a8f2762c665 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Tue, 12 Dec 2017 18:15:15 -0800 Subject: [PATCH] Fix DeleteScheduler::MarkAsTrash() handling existing trash Summary: DeleteScheduler::MarkAsTrash() don't handle existing .trash files correctly This cause rocksdb to not being able to delete existing .trash files on restart Closes https://github.com/facebook/rocksdb/pull/3261 Differential Revision: D6548003 Pulled By: IslamAbdelRahman fbshipit-source-id: c3800639412e587a690062c63076a5a08881e0e6 --- db/db_sst_test.cc | 24 ++++++++++++++++++++++++ util/delete_scheduler.cc | 1 + 2 files changed, 25 insertions(+) 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; }