From 2a7b100bdaae8daf42d71425b9d9a4fbfab6a908 Mon Sep 17 00:00:00 2001 From: Maciej Szeszko Date: Wed, 29 Jan 2025 13:39:49 -0800 Subject: [PATCH] Get rid of keys reshuffling --- db/db_test.cc | 21 ++++++++++++++++++++- db/db_test_util.h | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/db/db_test.cc b/db/db_test.cc index 6bb900bc811..80c773b0aac 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -5290,7 +5290,6 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel) { for (int i = 0; i < kNKeys; i++) { keys[i] = i; } - RandomShuffle(std::begin(keys), std::end(keys)); Random rnd(301); Options options; @@ -5367,10 +5366,30 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel) { })); ColumnFamilyMetaData cf_meta; db_->GetColumnFamilyMetaData(&cf_meta); + + // Ensure that files are non-overlapping and encompass full key range + // between 'smallestkey' and 'largestkey' recorded in CF file metadata. + std::vector> no_overlap_intervals; + for (size_t i = 0; i < cf_meta.levels.size(); i++) { + for (const auto& file : cf_meta.levels[i].files) { + auto smallest_int_key = IdFromKey(file.smallestkey); + auto largest_int_key = IdFromKey(file.largestkey); + ASSERT_EQ(file.num_entries, largest_int_key - smallest_int_key + 1); + + for (const auto& interval: no_overlap_intervals) { + ASSERT_FALSE(file.smallestkey <= interval.second && file.largestkey >= interval.first); + } + no_overlap_intervals.emplace_back(std::make_pair(file.smallestkey, file.largestkey)); + } + } + for (const auto& file : cf_meta.levels[4].files) { listener->SetExpectedFileName(dbname_ + file.name); Slice start(file.smallestkey), limit(file.largestkey); const RangePtr ranges(&start, &limit); + // Given verification from above, we're guaranteed that by deleting all the + // files in [, ] range, we're effectively deleting + // that very single file and nothing more. EXPECT_OK(dbfull()->DeleteFilesInRanges(dbfull()->DefaultColumnFamily(), &ranges, true /* include_end */)); } diff --git a/db/db_test_util.h b/db/db_test_util.h index 4b5bc48450d..8be174fac68 100644 --- a/db/db_test_util.h +++ b/db/db_test_util.h @@ -1106,6 +1106,10 @@ class DBTestBase : public testing::Test { return std::string(buf); } + static int IdFromKey(const std::string& key) { + return std::stoi(key.substr(3)); + } + static bool ShouldSkipOptions(int option_config, int skip_mask = kNoSkip); // Switch to a fresh database with the next option configuration to