From 6c5ec920708ae8dc11c7a6c76a0beaeb67f144f3 Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Mon, 21 Nov 2022 17:08:50 -0800 Subject: [PATCH] Set correct temperature for range tombstone only file in penultimate level (#10972) Summary: before this PR, if there is a range tombstone-only file generated in penultimate level, it is marked the `last_level_temperature`. This PR fixes this issue. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10972 Test Plan: added unit test for this scenario. Reviewed By: ajkr Differential Revision: D41449215 Pulled By: cbi42 fbshipit-source-id: 1e06b5ae3bc0183db2991a45965a9807a7e8be0c --- db/compaction/subcompaction_state.h | 3 +++ db/compaction/tiered_compaction_test.cc | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/db/compaction/subcompaction_state.h b/db/compaction/subcompaction_state.h index 13e63120f..c748be31b 100644 --- a/db/compaction/subcompaction_state.h +++ b/db/compaction/subcompaction_state.h @@ -196,8 +196,11 @@ class SubcompactionState { const CompactionFileCloseFunc& close_file_func) { // Call FinishCompactionOutputFile() even if status is not ok: it needs to // close the output file. + // CloseOutput() may open new compaction output files. + is_current_penultimate_level_ = true; Status s = penultimate_level_outputs_.CloseOutput( curr_status, open_file_func, close_file_func); + is_current_penultimate_level_ = false; s = compaction_outputs_.CloseOutput(s, open_file_func, close_file_func); return s; } diff --git a/db/compaction/tiered_compaction_test.cc b/db/compaction/tiered_compaction_test.cc index aaebcfd94..b541b1d10 100644 --- a/db/compaction/tiered_compaction_test.cc +++ b/db/compaction/tiered_compaction_test.cc @@ -663,8 +663,19 @@ TEST_P(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { cro.bottommost_level_compaction = BottommostLevelCompaction::kForce; ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); - ASSERT_EQ(GetSstSizeHelper(Temperature::kUnknown), - 0); // tombstone has no size, even it's in hot tier + // range tombstone is not in cold tier + ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); + std::vector> level_to_files; + dbfull()->TEST_GetFilesMetaData(dbfull()->DefaultColumnFamily(), + &level_to_files); + // range tombstone is in the penultimate level + const int penultimate_level = kNumLevels - 2; + ASSERT_EQ(level_to_files[penultimate_level].size(), 1); + ASSERT_EQ(level_to_files[penultimate_level][0].num_entries, 1); + ASSERT_EQ(level_to_files[penultimate_level][0].num_deletions, 1); + ASSERT_EQ(level_to_files[penultimate_level][0].temperature, + Temperature::kUnknown); + ASSERT_GT(GetSstSizeHelper(Temperature::kCold), 0); ASSERT_EQ("0,1,10", FilesPerLevel()); // one file is at the penultimate level which