From bf89edf78b8bb73b96a04f7bded67d71c58c93f5 Mon Sep 17 00:00:00 2001 From: Haobo Xu Date: Fri, 4 Oct 2013 15:17:54 -0700 Subject: [PATCH] [RocksDB] Added a property "leveldb.num-immutable-mem-table" so that Flush can be called without blocking, and application still has a way to check when it's done also without blocking. Summary: as title Test Plan: DBTest.NumImmutableMemTable Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D13305 --- db/db_impl.cc | 3 +++ db/db_test.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/db/db_impl.cc b/db/db_impl.cc index be1aaff68..6760963f4 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3039,6 +3039,9 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) { } else if (in == "sstables") { *value = versions_->current()->DebugString(); return true; + } else if (in == "num-immutable-mem-table") { + *value = std::to_string(imm_.size()); + return true; } return false; diff --git a/db/db_test.cc b/db/db_test.cc index 1e83ab799..34b3f3a58 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1422,6 +1422,37 @@ TEST(DBTest, FlushMultipleMemtable) { } while (ChangeCompactOptions()); } +TEST(DBTest, NumImmutableMemTable) { + do { + Options options = CurrentOptions(); + WriteOptions writeOpt = WriteOptions(); + writeOpt.disableWAL = true; + options.max_write_buffer_number = 4; + options.min_write_buffer_number_to_merge = 3; + options.write_buffer_size = 1000000; + Reopen(&options); + + std::string big_value(1000000, 'x'); + std::string num; + + ASSERT_OK(dbfull()->Put(writeOpt, "k1", big_value)); + ASSERT_TRUE(dbfull()->GetProperty("leveldb.num-immutable-mem-table", &num)); + ASSERT_EQ(num, "0"); + + ASSERT_OK(dbfull()->Put(writeOpt, "k2", big_value)); + ASSERT_TRUE(dbfull()->GetProperty("leveldb.num-immutable-mem-table", &num)); + ASSERT_EQ(num, "1"); + + ASSERT_OK(dbfull()->Put(writeOpt, "k3", big_value)); + ASSERT_TRUE(dbfull()->GetProperty("leveldb.num-immutable-mem-table", &num)); + ASSERT_EQ(num, "2"); + + dbfull()->Flush(FlushOptions()); + ASSERT_TRUE(dbfull()->GetProperty("leveldb.num-immutable-mem-table", &num)); + ASSERT_EQ(num, "0"); + } while (ChangeCompactOptions()); +} + TEST(DBTest, FLUSH) { do { Options options = CurrentOptions();