Skip to content

Commit

Permalink
Get rid of keys reshuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
mszeszko-meta committed Jan 29, 2025
1 parent 2e0dc21 commit 2a7b100
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::pair<std::string, std::string>> 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 [<smallestkey>, <largestkey>] range, we're effectively deleting
// that very single file and nothing more.
EXPECT_OK(dbfull()->DeleteFilesInRanges(dbfull()->DefaultColumnFamily(),
&ranges, true /* include_end */));
}
Expand Down
4 changes: 4 additions & 0 deletions db/db_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a7b100

Please sign in to comment.