From 7d9067991e27e5670d5278d1817f437f7fc4acb5 Mon Sep 17 00:00:00 2001 From: Sagar Vemuri Date: Thu, 5 Apr 2018 06:27:11 -0700 Subject: [PATCH] Ttl-triggered and snapshot-release-triggered compactions should not be manual compactions Summary: Ttl-triggered and snapshot-release-triggered compactions should not be considered as manual compactions. This is a bug. Closes https://github.com/facebook/rocksdb/pull/3678 Differential Revision: D7498151 Pulled By: sagar0 fbshipit-source-id: a2d5bed05268a4dc93d54ea97a9ae44b366df15d --- db/compaction_picker.cc | 2 +- db/db_compaction_test.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 713da4266..738de1724 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -1172,11 +1172,11 @@ void LevelCompactionBuilder::SetupInitialFiles() { // if we didn't find a compaction, check if there are any files marked for // compaction if (start_level_inputs_.empty()) { - is_manual_ = true; parent_index_ = base_index_ = -1; PickFilesMarkedForCompaction(); if (!start_level_inputs_.empty()) { + is_manual_ = true; compaction_reason_ = CompactionReason::kFilesMarkedForCompaction; return; } diff --git a/db/db_compaction_test.cc b/db/db_compaction_test.cc index 70c2ea937..47b7a1e56 100644 --- a/db/db_compaction_test.cc +++ b/db/db_compaction_test.cc @@ -3091,6 +3091,13 @@ TEST_F(DBCompactionTest, CompactBottomLevelFilesWithDeletions) { // compactions should be triggered, which reduce the size of each bottom-level // file without changing file count. db_->ReleaseSnapshot(snapshot); + rocksdb::SyncPoint::GetInstance()->SetCallBack( + "LevelCompactionPicker::PickCompaction:Return", [&](void* arg) { + Compaction* compaction = reinterpret_cast(arg); + ASSERT_TRUE(compaction->compaction_reason() == + CompactionReason::kBottommostFiles); + }); + rocksdb::SyncPoint::GetInstance()->EnableProcessing(); dbfull()->TEST_WaitForCompact(); db_->GetLiveFilesMetaData(&post_release_metadata); ASSERT_EQ(pre_release_metadata.size(), post_release_metadata.size()); @@ -3104,6 +3111,7 @@ TEST_F(DBCompactionTest, CompactBottomLevelFilesWithDeletions) { // deletion markers/deleted keys. ASSERT_LT(post_file.size, pre_file.size); } + rocksdb::SyncPoint::GetInstance()->DisableProcessing(); } TEST_F(DBCompactionTest, LevelCompactExpiredTtlFiles) { @@ -3153,9 +3161,16 @@ TEST_F(DBCompactionTest, LevelCompactExpiredTtlFiles) { // compacted. ASSERT_OK(Put("a", "1")); Flush(); + rocksdb::SyncPoint::GetInstance()->SetCallBack( + "LevelCompactionPicker::PickCompaction:Return", [&](void* arg) { + Compaction* compaction = reinterpret_cast(arg); + ASSERT_TRUE(compaction->compaction_reason() == CompactionReason::kTtl); + }); + rocksdb::SyncPoint::GetInstance()->EnableProcessing(); dbfull()->TEST_WaitForCompact(); // All non-L0 files are deleted, as they contained only deleted data. ASSERT_EQ("1", FilesPerLevel()); + rocksdb::SyncPoint::GetInstance()->DisableProcessing(); } TEST_F(DBCompactionTest, CompactRangeDelayedByL0FileCount) { -- GitLab