]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix issue in Iterator::Seek when using Block based filter block with prefix_extractor
authorIslam AbdelRahman <tec@fb.com>
Tue, 26 Jan 2016 22:47:42 +0000 (14:47 -0800)
committerIslam AbdelRahman <tec@fb.com>
Wed, 27 Jan 2016 02:45:03 +0000 (18:45 -0800)
Summary: Similar to D53385 we need to check InDomain before checking the filter block.

Test Plan: unit tests

Reviewers: yhchiang, rven, sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D53421

db/db_test.cc
table/block_based_table_reader.cc

index 8f3f32bb8f0c932d525826aa80522e5456b8f645..be0b2fd96258217e6ff6e17a2a632791866153db 100644 (file)
@@ -10554,6 +10554,7 @@ class SliceTransformLimitedDomain : public SliceTransform {
 
 TEST_F(DBTest, PrefixExtractorFullFilter) {
   BlockBasedTableOptions bbto;
+  // Full Filter Block
   bbto.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
   bbto.whole_key_filtering = false;
 
@@ -10580,6 +10581,39 @@ TEST_F(DBTest, PrefixExtractorFullFilter) {
   ASSERT_EQ(Get("zzzzz_AAAA"), "val5");
 }
 
+TEST_F(DBTest, PrefixExtractorBlockFilter) {
+  BlockBasedTableOptions bbto;
+  // Block Filter Block
+  bbto.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true));
+
+  Options options = CurrentOptions();
+  options.prefix_extractor = std::make_shared<SliceTransformLimitedDomain>();
+  options.table_factory.reset(NewBlockBasedTableFactory(bbto));
+
+  DestroyAndReopen(options);
+
+  ASSERT_OK(Put("x1113_AAAA", "val3"));
+  ASSERT_OK(Put("x1114_AAAA", "val4"));
+  // Not in domain, wont be added to filter
+  ASSERT_OK(Put("zzzzz_AAAA", "val1"));
+  ASSERT_OK(Put("zzzzz_AAAB", "val2"));
+  ASSERT_OK(Put("zzzzz_AAAC", "val3"));
+  ASSERT_OK(Put("zzzzz_AAAD", "val4"));
+
+  ASSERT_OK(Flush());
+
+  std::vector<std::string> iter_res;
+  auto iter = db_->NewIterator(ReadOptions());
+  // Seek to a key that was not in Domain
+  for (iter->Seek("zzzzz_AAAA"); iter->Valid(); iter->Next()) {
+    iter_res.emplace_back(iter->value().ToString());
+  }
+
+  std::vector<std::string> expected_res = {"val1", "val2", "val3", "val4"};
+  ASSERT_EQ(iter_res, expected_res);
+  delete iter;
+}
+
 #ifndef ROCKSDB_LITE
 class BloomStatsTestWithParam
     : public DBTest,
index d5a6aa03e05bd5390408cf02430a55aa61125195..b428122a06e7e898d8d0f7bc7a9ed0345c518fc7 100644 (file)
@@ -1117,8 +1117,11 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key) {
   }
 
   assert(rep_->ioptions.prefix_extractor != nullptr);
-  auto prefix = rep_->ioptions.prefix_extractor->Transform(
-      ExtractUserKey(internal_key));
+  auto user_key = ExtractUserKey(internal_key);
+  if (!rep_->ioptions.prefix_extractor->InDomain(user_key)) {
+    return true;
+  }
+  auto prefix = rep_->ioptions.prefix_extractor->Transform(user_key);
   InternalKey internal_key_prefix(prefix, kMaxSequenceNumber, kTypeValue);
   auto internal_prefix = internal_key_prefix.Encode();