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