diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 713da42662c5fa24742520f40f49a66c3429668a..738de1724a36939fd7eb6e44a5a352816609767d 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 70c2ea937d809cc019e8940a314aee61f4d82f86..47b7a1e56d80d22fe0dd4385a12daa09421819cb 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) {