@ -334,14 +334,15 @@ class MemTableIterator : public InternalIterator {
// iterator should only use prefix bloom filter
auto ts_sz = comparator_ . comparator . user_comparator ( ) - > timestamp_size ( ) ;
Slice user_k_without_ts ( ExtractUserKeyAndStripTimestamp ( k , ts_sz ) ) ;
if ( prefix_extractor_ - > InDomain ( user_k_without_ts ) & &
! bloom_ - > MayContain (
prefix_extractor_ - > Transform ( user_k_without_ts ) ) ) {
PERF_COUNTER_ADD ( bloom_memtable_miss_count , 1 ) ;
valid_ = false ;
return ;
} else {
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
if ( prefix_extractor_ - > InDomain ( user_k_without_ts ) ) {
if ( ! bloom_ - > MayContain (
prefix_extractor_ - > Transform ( user_k_without_ts ) ) ) {
PERF_COUNTER_ADD ( bloom_memtable_miss_count , 1 ) ;
valid_ = false ;
return ;
} else {
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
}
}
}
iter_ - > Seek ( k , nullptr ) ;
@ -353,14 +354,15 @@ class MemTableIterator : public InternalIterator {
if ( bloom_ ) {
auto ts_sz = comparator_ . comparator . user_comparator ( ) - > timestamp_size ( ) ;
Slice user_k_without_ts ( ExtractUserKeyAndStripTimestamp ( k , ts_sz ) ) ;
if ( prefix_extractor_ - > InDomain ( user_k_without_ts ) & &
! bloom_ - > MayContain (
prefix_extractor_ - > Transform ( user_k_without_ts ) ) ) {
PERF_COUNTER_ADD ( bloom_memtable_miss_count , 1 ) ;
valid_ = false ;
return ;
} else {
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
if ( prefix_extractor_ - > InDomain ( user_k_without_ts ) ) {
if ( ! bloom_ - > MayContain (
prefix_extractor_ - > Transform ( user_k_without_ts ) ) ) {
PERF_COUNTER_ADD ( bloom_memtable_miss_count , 1 ) ;
valid_ = false ;
return ;
} else {
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
}
}
}
iter_ - > Seek ( k , nullptr ) ;
@ -893,16 +895,20 @@ bool MemTable::Get(const LookupKey& key, std::string* value,
bool may_contain = true ;
size_t ts_sz = GetInternalKeyComparator ( ) . user_comparator ( ) - > timestamp_size ( ) ;
Slice user_key_without_ts = StripTimestampFromUserKey ( key . user_key ( ) , ts_sz ) ;
bool bloom_checked = false ;
if ( bloom_filter_ ) {
// when both memtable_whole_key_filtering and prefix_extractor_ are set,
// only do whole key filtering for Get() to save CPU
if ( moptions_ . memtable_whole_key_filtering ) {
may_contain = bloom_filter_ - > MayContain ( user_key_without_ts ) ;
bloom_checked = true ;
} else {
assert ( prefix_extractor_ ) ;
may_contain = ! prefix_extractor_ - > InDomain ( user_key_without_ts ) | |
bloom_filter_ - > MayContain (
prefix_extractor_ - > Transform ( user_key_without_ts ) ) ;
if ( prefix_extractor_ - > InDomain ( user_key_without_ts ) ) {
may_contain = bloom_filter_ - > MayContain (
prefix_extractor_ - > Transform ( user_key_without_ts ) ) ;
bloom_checked = true ;
}
}
}
@ -911,7 +917,7 @@ bool MemTable::Get(const LookupKey& key, std::string* value,
PERF_COUNTER_ADD ( bloom_memtable_miss_count , 1 ) ;
* seq = kMaxSequenceNumber ;
} else {
if ( bloom_filter_ ) {
if ( bloom_checked ) {
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
}
GetFromTable ( key , * max_covering_tombstone_seq , do_merge , callback ,
@ -988,10 +994,6 @@ void MemTable::MultiGet(const ReadOptions& read_options, MultiGetRange* range,
bloom_keys [ num_keys ] =
prefix_extractor_ - > Transform ( iter - > ukey_without_ts ) ;
range_indexes [ num_keys + + ] = iter . index ( ) ;
} else {
// TODO: consider not counting these as Bloom hits to more closely
// match bloom_sst_hit_count
PERF_COUNTER_ADD ( bloom_memtable_hit_count , 1 ) ;
}
}
bloom_filter_ - > MayContain ( num_keys , & bloom_keys [ 0 ] , & may_match [ 0 ] ) ;