From 7ccb8d6ef3f8f60354e79dd6b3fef776a8970842 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 5 May 2016 17:20:22 -0700 Subject: [PATCH] BlockBasedTable::Get() not to use prefix bloom if read_options.total_order_seek = true Summary: This is to provide a way for users to skip prefix bloom in point look-up. Test Plan: Add a new unit test scenario. Reviewers: IslamAbdelRahman Subscribers: leveldb, andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D57747 --- db/db_bloom_filter_test.cc | 4 ++++ include/rocksdb/options.h | 3 +++ table/block_based_table_reader.cc | 7 ++++--- table/block_based_table_reader.h | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/db/db_bloom_filter_test.cc b/db/db_bloom_filter_test.cc index b9a86c31f..4bc9453ad 100644 --- a/db/db_bloom_filter_test.cc +++ b/db/db_bloom_filter_test.cc @@ -160,6 +160,10 @@ TEST_F(DBBloomFilterTest, GetFilterByPrefixBloom) { ASSERT_EQ("NOT_FOUND", Get("foobarbar")); ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 2); + + ro.total_order_seek = true; + ASSERT_TRUE(db_->Get(ro, "foobarbar", &value).IsNotFound()); + ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 2); } TEST_F(DBBloomFilterTest, WholeKeyFilterProp) { diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index 982bd16c6..9853d7d01 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -1458,6 +1458,9 @@ struct ReadOptions { // Enable a total order seek regardless of index format (e.g. hash index) // used in the table. Some table format (e.g. plain table) may not support // this option. + // If true when calling Get(), we also skip prefix bloom when reading from + // block based table. It provides a way to read exisiting data after + // changing implementation of prefix extractor. bool total_order_seek; // Enforce that the iterator only iterates over the same prefix as the seek. diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index 849813c41..82c9903fa 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -1332,7 +1332,8 @@ InternalIterator* BlockBasedTable::NewIterator(const ReadOptions& read_options, NewIndexIterator(read_options), arena); } -bool BlockBasedTable::FullFilterKeyMayMatch(FilterBlockReader* filter, +bool BlockBasedTable::FullFilterKeyMayMatch(const ReadOptions& read_options, + FilterBlockReader* filter, const Slice& internal_key) const { if (filter == nullptr || filter->IsBlockBased()) { return true; @@ -1341,7 +1342,7 @@ bool BlockBasedTable::FullFilterKeyMayMatch(FilterBlockReader* filter, if (!filter->KeyMayMatch(user_key)) { return false; } - if (rep_->ioptions.prefix_extractor && + if (!read_options.total_order_seek && rep_->ioptions.prefix_extractor && rep_->ioptions.prefix_extractor->InDomain(user_key) && !filter->PrefixMayMatch( rep_->ioptions.prefix_extractor->Transform(user_key))) { @@ -1361,7 +1362,7 @@ Status BlockBasedTable::Get(const ReadOptions& read_options, const Slice& key, // First check the full filter // If full filter not useful, Then go into each block - if (!FullFilterKeyMayMatch(filter, key)) { + if (!FullFilterKeyMayMatch(read_options, filter, key)) { RecordTick(rep_->ioptions.statistics, BLOOM_FILTER_USEFUL); } else { BlockIter iiter; diff --git a/table/block_based_table_reader.h b/table/block_based_table_reader.h index 8f55f119b..45b303e0e 100644 --- a/table/block_based_table_reader.h +++ b/table/block_based_table_reader.h @@ -207,7 +207,8 @@ class BlockBasedTable : public TableReader { IndexReader** index_reader, InternalIterator* preloaded_meta_index_iter = nullptr); - bool FullFilterKeyMayMatch(FilterBlockReader* filter, + bool FullFilterKeyMayMatch(const ReadOptions& read_options, + FilterBlockReader* filter, const Slice& user_key) const; // Read the meta block from sst.