diff --git a/db/version_set.h b/db/version_set.h index b33a7c6e8..5e0969ccd 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -698,10 +698,6 @@ class Version { return storage_info_.user_comparator_; } - bool PrefixMayMatch(const ReadOptions& read_options, - InternalIterator* level_iter, - const Slice& internal_prefix) const; - // Returns true if the filter blocks in the specified level will not be // checked during read operations. In certain cases (trivial move or preload), // the filter block may already be cached, but we still do not access it such diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index 8e85af170..01557231b 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -1905,7 +1905,9 @@ BlockBasedTable::PartitionedIndexIteratorState::NewSecondaryIterator( // 2) Compare(prefix(key), key) <= 0. // 3) If Compare(key1, key2) <= 0, then Compare(prefix(key1), prefix(key2)) <= 0 // -// Otherwise, this method guarantees no I/O will be incurred. +// If read_options.read_tier == kBlockCacheTier, this method will do no I/O and +// will return true if the filter block is not in memory and not found in block +// cache. // // REQUIRES: this method shouldn't be called while the DB lock is held. bool BlockBasedTable::PrefixMayMatch( @@ -1939,12 +1941,14 @@ bool BlockBasedTable::PrefixMayMatch( FilterBlockReader* const filter = rep_->filter.get(); bool filter_checked = true; if (filter != nullptr) { + const bool no_io = read_options.read_tier == kBlockCacheTier; + if (!filter->IsBlockBased()) { const Slice* const const_ikey_ptr = &internal_key; may_match = filter->RangeMayExist( read_options.iterate_upper_bound, user_key, prefix_extractor, rep_->internal_comparator.user_comparator(), const_ikey_ptr, - &filter_checked, need_upper_bound_check, lookup_context); + &filter_checked, need_upper_bound_check, no_io, lookup_context); } else { // if prefix_extractor changed for block based filter, skip filter if (need_upper_bound_check) { @@ -1997,7 +2001,7 @@ bool BlockBasedTable::PrefixMayMatch( // is the only on could potentially contain the prefix. BlockHandle handle = iiter->value().handle; may_match = filter->PrefixMayMatch( - prefix, prefix_extractor, handle.offset(), /*no_io=*/false, + prefix, prefix_extractor, handle.offset(), no_io, /*const_key_ptr=*/nullptr, /*get_context=*/nullptr, lookup_context); } } diff --git a/table/block_based/filter_block.h b/table/block_based/filter_block.h index 1ad8d3f18..eb3e92235 100644 --- a/table/block_based/filter_block.h +++ b/table/block_based/filter_block.h @@ -161,13 +161,14 @@ class FilterBlockReader { const Comparator* /*comparator*/, const Slice* const const_ikey_ptr, bool* filter_checked, bool need_upper_bound_check, + bool no_io, BlockCacheLookupContext* lookup_context) { if (need_upper_bound_check) { return true; } *filter_checked = true; Slice prefix = prefix_extractor->Transform(user_key); - return PrefixMayMatch(prefix, prefix_extractor, kNotValid, false, + return PrefixMayMatch(prefix, prefix_extractor, kNotValid, no_io, const_ikey_ptr, /* get_context */ nullptr, lookup_context); } diff --git a/table/block_based/full_filter_block.cc b/table/block_based/full_filter_block.cc index e2f7f476f..2ddade638 100644 --- a/table/block_based/full_filter_block.cc +++ b/table/block_based/full_filter_block.cc @@ -285,7 +285,8 @@ bool FullFilterBlockReader::RangeMayExist( const Slice* iterate_upper_bound, const Slice& user_key, const SliceTransform* prefix_extractor, const Comparator* comparator, const Slice* const const_ikey_ptr, bool* filter_checked, - bool need_upper_bound_check, BlockCacheLookupContext* lookup_context) { + bool need_upper_bound_check, bool no_io, + BlockCacheLookupContext* lookup_context) { if (!prefix_extractor || !prefix_extractor->InDomain(user_key)) { *filter_checked = false; return true; @@ -297,7 +298,7 @@ bool FullFilterBlockReader::RangeMayExist( return true; } else { *filter_checked = true; - return PrefixMayMatch(prefix, prefix_extractor, kNotValid, false, + return PrefixMayMatch(prefix, prefix_extractor, kNotValid, no_io, const_ikey_ptr, /* get_context */ nullptr, lookup_context); } diff --git a/table/block_based/full_filter_block.h b/table/block_based/full_filter_block.h index c72a58021..324b1a826 100644 --- a/table/block_based/full_filter_block.h +++ b/table/block_based/full_filter_block.h @@ -119,7 +119,7 @@ class FullFilterBlockReader const SliceTransform* prefix_extractor, const Comparator* comparator, const Slice* const const_ikey_ptr, bool* filter_checked, - bool need_upper_bound_check, + bool need_upper_bound_check, bool no_io, BlockCacheLookupContext* lookup_context) override; private: