From 25f6a852e41a6dfa80b37b738bbb029a69b77c76 Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Tue, 7 Oct 2014 10:40:45 -0700 Subject: [PATCH] add db_test for changing memtable size Summary: The test only covers changing write_buffer_size. Other changable parameters such bloom bits/probes are not obvious how to test. Suggestions are welcome Test Plan: db_test Reviewers: sdong, yhchiang, igor Reviewed By: igor Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D24429 --- db/db_test.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/db/db_test.cc b/db/db_test.cc index d402a3578..c67c45786 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -8538,6 +8538,57 @@ TEST(DBTest, DisableDataSyncTest) { } } +TEST(DBTest, DynamicMemtableOptions) { + const uint64_t k64KB = 1 << 16; + const uint64_t k128KB = 1 << 17; + const uint64_t k5KB = 5 * 1024; + Options options; + options.env = env_; + options.create_if_missing = true; + options.compression = kNoCompression; + options.max_background_compactions = 4; + options.max_mem_compaction_level = 0; + options.write_buffer_size = k64KB; + options.max_write_buffer_number = 2; + // Don't trigger compact/slowdown/stop + options.level0_file_num_compaction_trigger = 1024; + options.level0_slowdown_writes_trigger = 1024; + options.level0_stop_writes_trigger = 1024; + DestroyAndReopen(&options); + + auto gen_l0_kb = [this](int size) { + Random rnd(301); + std::vector values; + for (int i = 0; i < size; i++) { + values.push_back(RandomString(&rnd, 1024)); + ASSERT_OK(Put(Key(i), values[i])); + } + dbfull()->TEST_WaitForFlushMemTable(); + }; + + gen_l0_kb(64); + ASSERT_EQ(NumTableFilesAtLevel(0), 1); + ASSERT_TRUE(SizeAtLevel(0) < k64KB + k5KB); + ASSERT_TRUE(SizeAtLevel(0) > k64KB - k5KB); + + // Clean up L0 + dbfull()->CompactRange(nullptr, nullptr); + ASSERT_EQ(NumTableFilesAtLevel(0), 0); + + // Increase buffer size + ASSERT_TRUE(dbfull()->SetOptions({ + {"write_buffer_size", "131072"}, + })); + + // The existing memtable is still 64KB in size, after it becomes immutable, + // the next memtable will be 128KB in size. Write 256KB total, we should + // have a 64KB L0 file, a 128KB L0 file, and a memtable with 64KB data + gen_l0_kb(256); + ASSERT_EQ(NumTableFilesAtLevel(0), 2); + ASSERT_TRUE(SizeAtLevel(0) < k128KB + k64KB + 2 * k5KB); + ASSERT_TRUE(SizeAtLevel(0) > k128KB + k64KB - 2 * k5KB); +} + TEST(DBTest, DynamicCompactionOptions) { const uint64_t k64KB = 1 << 16; const uint64_t k128KB = 1 << 17;