diff --git a/db/column_family.cc b/db/column_family.cc index 8abad2941f..b5364ed15d 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -901,7 +901,11 @@ uint64_t GetPendingCompactionBytesForCompactionSpeedup( return slowdown_threshold; } - uint64_t size_threshold = bottommost_files_size / kBottommostSizeDivisor; + // Prevent a small CF from triggering parallel compactions for other CFs. + // Require compaction debt to be more than a full L0 to Lbase compaction. + const uint64_t kMinDebtSize = 2 * mutable_cf_options.max_bytes_for_level_base; + uint64_t size_threshold = + std::max(bottommost_files_size / kBottommostSizeDivisor, kMinDebtSize); return std::min(size_threshold, slowdown_threshold); } diff --git a/db/column_family_test.cc b/db/column_family_test.cc index d7751992b5..e7baa28ada 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -3012,19 +3012,25 @@ TEST_P(ColumnFamilyTest, CompactionSpeedupForCompactionDebt) { ASSERT_OK(db_->Flush(FlushOptions())); { - // 1MB debt is way bigger than bottommost data so definitely triggers - // speedup. VersionStorageInfo* vstorage = cfd->current()->storage_info(); - vstorage->TEST_set_estimated_compaction_needed_bytes(1048576 /* 1MB */, - dbmu); - RecalculateWriteStallConditions(cfd, mutable_cf_options); - ASSERT_EQ(6, dbfull()->TEST_BGCompactionsAllowed()); - // Eight bytes is way smaller than bottommost data so definitely does not // trigger speedup. vstorage->TEST_set_estimated_compaction_needed_bytes(8, dbmu); RecalculateWriteStallConditions(cfd, mutable_cf_options); ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed()); + + // 1MB is much larger than bottommost level size. However, since it's too + // small in terms of absolute size, it does not trigger parallel compaction + // in this case (see GetPendingCompactionBytesForCompactionSpeedup()). + vstorage->TEST_set_estimated_compaction_needed_bytes(1048576 /* 1MB */, + dbmu); + RecalculateWriteStallConditions(cfd, mutable_cf_options); + ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed()); + + vstorage->TEST_set_estimated_compaction_needed_bytes( + 2 * mutable_cf_options.max_bytes_for_level_base, dbmu); + RecalculateWriteStallConditions(cfd, mutable_cf_options); + ASSERT_EQ(6, dbfull()->TEST_BGCompactionsAllowed()); } } diff --git a/db/import_column_family_test.cc b/db/import_column_family_test.cc index 89fdbb7e30..c659ba6aed 100644 --- a/db/import_column_family_test.cc +++ b/db/import_column_family_test.cc @@ -951,6 +951,8 @@ TEST_F(ImportColumnFamilyTest, AssignEpochNumberToMultipleCF) { Options options = CurrentOptions(); options.level_compaction_dynamic_level_bytes = true; options.max_background_jobs = 8; + // Always allow parallel compaction + options.soft_pending_compaction_bytes_limit = 10; env_->SetBackgroundThreads(2, Env::LOW); env_->SetBackgroundThreads(0, Env::BOTTOM); CreateAndReopenWithCF({"CF1", "CF2"}, options); diff --git a/unreleased_history/behavior_changes/parallel-compaction.md b/unreleased_history/behavior_changes/parallel-compaction.md new file mode 100644 index 0000000000..87f5bb76e6 --- /dev/null +++ b/unreleased_history/behavior_changes/parallel-compaction.md @@ -0,0 +1 @@ +* Fix an issue in level compaction where a small CF with small compaction debt can cause the DB to allow parallel compactions. (#13054) \ No newline at end of file