From 532ff334d97f466a0d45ff4861029b00bb4d7734 Mon Sep 17 00:00:00 2001 From: anand76 Date: Thu, 30 Sep 2021 13:24:13 -0700 Subject: [PATCH] Don't ignore deletion rate limit if WAL dir is different (#8967) Summary: If WAL dir is different from the DB dir, we should still honor the SstFileManager deletion rate limit for SST files. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8967 Test Plan: Add a new unit test in db_sst_test Reviewed By: pdillinger Differential Revision: D31220116 Pulled By: anand1976 fbshipit-source-id: bcde8a53a7d728e15e597fb5d07ee86c1b38bd28 --- HISTORY.md | 1 + db/db_impl/db_impl.cc | 6 ++++-- db/db_impl/db_impl_files.cc | 8 +++++--- db/db_sst_test.cc | 20 ++++++++++++++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7ddb19c94..c23dc4dd7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased ### Bug Fixes * Fixes a bug in directed IO mode when calling MultiGet() for blobs in the same blob file. The bug is caused by not sorting the blob read requests by file offsets. +* Fix the incorrect disabling of SST rate limited deletion when the WAL and DB are in different directories. Only WAL rate limited deletion should be disabled if its in a different directory. ### New Features * Provided support for SingleDelete with user defined timestamp. diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index bac5e6c7f..385cd239b 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -4059,8 +4059,10 @@ Status DestroyDB(const std::string& dbname, const Options& options, del = DestroyDB(path_to_delete, options); } else if (type == kTableFile || type == kWalFile || type == kBlobFile) { - del = DeleteDBFile(&soptions, path_to_delete, dbname, - /*force_bg=*/false, /*force_fg=*/!wal_in_db_path); + del = DeleteDBFile( + &soptions, path_to_delete, dbname, + /*force_bg=*/false, + /*force_fg=*/(type == kWalFile) ? !wal_in_db_path : false); } else { del = env->DeleteFile(path_to_delete); } diff --git a/db/db_impl/db_impl_files.cc b/db/db_impl/db_impl_files.cc index a93267fbc..6ae170c69 100644 --- a/db/db_impl/db_impl_files.cc +++ b/db/db_impl/db_impl_files.cc @@ -330,9 +330,11 @@ void DBImpl::DeleteObsoleteFileImpl(int job_id, const std::string& fname, Status file_deletion_status; if (type == kTableFile || type == kBlobFile || type == kWalFile) { - file_deletion_status = - DeleteDBFile(&immutable_db_options_, fname, path_to_sync, - /*force_bg=*/false, /*force_fg=*/!wal_in_db_path_); + // Rate limit WAL deletion only if its in the DB dir + file_deletion_status = DeleteDBFile( + &immutable_db_options_, fname, path_to_sync, + /*force_bg=*/false, + /*force_fg=*/(type == kWalFile) ? !wal_in_db_path_ : false); } else { file_deletion_status = env_->DeleteFile(fname); } diff --git a/db/db_sst_test.cc b/db/db_sst_test.cc index 15596d494..51c9d5c3e 100644 --- a/db/db_sst_test.cc +++ b/db/db_sst_test.cc @@ -602,7 +602,14 @@ TEST_F(DBSSTTest, DBWithSstFileManagerForBlobFilesWithGC) { ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks(); } -TEST_F(DBSSTTest, RateLimitedDelete) { +class DBSSTTestRateLimit : public DBSSTTest, + public ::testing::WithParamInterface { + public: + DBSSTTestRateLimit() : DBSSTTest() {} + ~DBSSTTestRateLimit() override {} +}; + +TEST_P(DBSSTTestRateLimit, RateLimitedDelete) { Destroy(last_options_); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency({ {"DBSSTTest::RateLimitedDelete:1", @@ -640,11 +647,15 @@ TEST_F(DBSSTTest, RateLimitedDelete) { ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); + bool different_wal_dir = GetParam(); Options options = CurrentOptions(); SetTimeElapseOnlySleepOnReopen(&options); options.disable_auto_compactions = true; options.env = env_; options.statistics = CreateDBStatistics(); + if (different_wal_dir) { + options.wal_dir = alternative_wal_dir_; + } int64_t rate_bytes_per_sec = 1024 * 10; // 10 Kbs / Sec Status s; @@ -656,7 +667,9 @@ TEST_F(DBSSTTest, RateLimitedDelete) { sfm->delete_scheduler()->SetMaxTrashDBRatio(1.1); WriteOptions wo; - wo.disableWAL = true; + if (!different_wal_dir) { + wo.disableWAL = true; + } Reopen(options); // Create 4 files in L0 for (char v = 'a'; v <= 'd'; v++) { @@ -701,6 +714,9 @@ TEST_F(DBSSTTest, RateLimitedDelete) { ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); } +INSTANTIATE_TEST_CASE_P(RateLimitedDelete, DBSSTTestRateLimit, + ::testing::Bool()); + TEST_F(DBSSTTest, RateLimitedWALDelete) { Destroy(last_options_);