Skip to content

Commit

Permalink
Don't do memtable lookup in db_impl_readonly if memtables are empty w…
Browse files Browse the repository at this point in the history
…hile 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
  • Loading branch information
adyarshyam committed Aug 27, 2014
1 parent 9dcb75b commit b6fd781
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion db/db_impl_readonly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <stdint.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include "db/db_iter.h"
#include "db/dbformat.h"
#include "db/filename.h"
Expand Down
10 changes: 10 additions & 0 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/memtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b6fd781

Please sign in to comment.