From b6fd7811eb27fe2eb5ecf8a813c563598e42cfc9 Mon Sep 17 00:00:00 2001 From: Radheshyam Balasundaram Date: Tue, 26 Aug 2014 17:19:03 -0700 Subject: [PATCH] Don't do memtable lookup in db_impl_readonly if memtables are empty while opening db. Summary: In DBImpl::Recover method, while loading memtables, also check if memtables are empty. Use this in DBImplReadonly to determine whether to lookup memtable or not. Test Plan: db_test make check all Reviewers: sdong, yhchiang, ljin, igor Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D22281 --- Makefile | 1 - db/db_impl_readonly.cc | 1 - db/db_test.cc | 10 ++++++++++ db/memtable.cc | 5 +++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b380c6f585..c75274cd03 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,6 @@ TESTS = \ thread_local_test \ geodb_test \ rate_limiter_test \ - cuckoo_table_builder_test \ options_test \ cuckoo_table_builder_test \ cuckoo_table_reader_test \ diff --git a/db/db_impl_readonly.cc b/db/db_impl_readonly.cc index eae8379a9e..6c864aefd8 100644 --- a/db/db_impl_readonly.cc +++ b/db/db_impl_readonly.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include "db/db_iter.h" #include "db/dbformat.h" #include "db/filename.h" diff --git a/db/db_test.cc b/db/db_test.cc index 6dbbcb9887..f1933059d2 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1195,6 +1195,16 @@ TEST(DBTest, ReadOnlyDB) { } ASSERT_EQ(count, 2); delete iter; + Close(); + + // Reopen and flush memtable. + Reopen(); + Flush(); + Close(); + // Now check keys in read only mode. + ASSERT_OK(ReadOnlyReopen(&options)); + ASSERT_EQ("v3", Get("foo")); + ASSERT_EQ("v2", Get("bar")); } // Make sure that when options.block_cache is set, after a new table is diff --git a/db/memtable.cc b/db/memtable.cc index f9a17e19e8..523998c303 100644 --- a/db/memtable.cc +++ b/db/memtable.cc @@ -417,6 +417,11 @@ static bool SaveValue(void* arg, const char* entry) { bool MemTable::Get(const LookupKey& key, std::string* value, Status* s, MergeContext& merge_context, const Options& options) { + // The sequence number is updated synchronously in version_set.h + if (first_seqno_ == 0) { + // Avoiding recording stats for speed. + return false; + } PERF_TIMER_AUTO(get_from_memtable_time); Slice user_key = key.user_key();