]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
add db_test for changing memtable size
authorLei Jin <lei@fb.com>
Tue, 7 Oct 2014 17:40:45 +0000 (10:40 -0700)
committerLei Jin <lei@fb.com>
Tue, 7 Oct 2014 17:40:45 +0000 (10:40 -0700)
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

index d402a357856e3ec637fe2202064c9c3d8a9e02b2..c67c45786de773cd8047b0b3c7c1b2123703df81 100644 (file)
@@ -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<std::string> 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;