Skip to content

Commit 987f94c

Browse files
committed
Add simple unit test
1 parent 221529a commit 987f94c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

db/db_compaction_test.cc

+36
Original file line numberDiff line numberDiff line change
@@ -10733,6 +10733,42 @@ TEST_F(DBCompactionTest, RecordNewestKeyTimeForTtlCompaction) {
1073310733
ASSERT_OK(dbfull()->TEST_WaitForCompact());
1073410734
ASSERT_EQ(NumTableFilesAtLevel(0), 0);
1073510735
}
10736+
10737+
TEST_F(DBCompactionTest, RecordNumberCompactionInputIterators) {
10738+
Options options;
10739+
SetTimeElapseOnlySleepOnReopen(&options);
10740+
options.env = CurrentOptions().env;
10741+
options.compaction_style = kCompactionStyleFIFO;
10742+
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
10743+
options.write_buffer_size = 10 << 10; // 10KB
10744+
options.arena_block_size = 4096;
10745+
options.compression = kNoCompression;
10746+
options.create_if_missing = true;
10747+
options.compaction_options_fifo.allow_compaction = true;
10748+
options.num_levels = 1;
10749+
env_->SetMockSleep();
10750+
options.env = env_;
10751+
options.ttl = 1 * 60 * 60; // 1 hour
10752+
ASSERT_OK(TryReopen(options));
10753+
10754+
// Generate and flush 4 files, each about 10KB
10755+
Random rnd(301);
10756+
for (int i = 0; i < 4; i++) {
10757+
for (int j = 0; j < 10; j++) {
10758+
ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
10759+
}
10760+
ASSERT_OK(Flush());
10761+
env_->MockSleepForSeconds(5);
10762+
}
10763+
ASSERT_OK(dbfull()->TEST_WaitForCompact());
10764+
ASSERT_EQ(NumTableFilesAtLevel(0), 1);
10765+
HistogramData num_compaction_input_iterators;
10766+
options.statistics->histogramData(NUM_COMPACTION_INPUT_ITERATORS,
10767+
&num_compaction_input_iterators);
10768+
ASSERT_EQ(num_compaction_input_iterators.sum, 4);
10769+
10770+
ASSERT_OK(options.statistics->Reset());
10771+
}
1073610772
} // namespace ROCKSDB_NAMESPACE
1073710773

1073810774
int main(int argc, char** argv) {

db/db_impl/db_impl_compaction_flush.cc

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool DBImpl::EnoughRoomForCompaction(
6464
size_t DBImpl::GetNumberCompactionInputIterators(Compaction* c) {
6565
assert(c);
6666
if (c->start_level() == 0) {
67+
assert(0 < c->num_input_levels());
6768
size_t num_l0_files = c->num_input_files(0);
6869
size_t num_non_l0_levels = c->num_input_levels() - 1;
6970
return num_l0_files + num_non_l0_levels;

0 commit comments

Comments
 (0)