YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/full_filter_block.cc
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#include "yb/rocksdb/table/full_filter_block.h"
22
23
#include "yb/rocksdb/filter_policy.h"
24
#include "yb/rocksdb/util/perf_context_imp.h"
25
26
namespace rocksdb {
27
28
FullFilterBlockBuilder::FullFilterBlockBuilder(
29
    const SliceTransform* prefix_extractor, bool whole_key_filtering,
30
    FilterBitsBuilder* filter_bits_builder)
31
    : prefix_extractor_(prefix_extractor),
32
      whole_key_filtering_(whole_key_filtering),
33
3.45k
      num_added_(0) {
34
3.45k
  assert(filter_bits_builder != nullptr);
35
3.45k
  filter_bits_builder_.reset(filter_bits_builder);
36
3.45k
}
37
38
515k
void FullFilterBlockBuilder::Add(const Slice& key) {
39
515k
  if (whole_key_filtering_) {
40
515k
    AddKey(key);
41
515k
  }
42
515k
  if (prefix_extractor_ && prefix_extractor_->InDomain(key)) {
43
72
    AddPrefix(key);
44
72
  }
45
515k
}
46
47
// Add key to filter if needed
48
515k
inline void FullFilterBlockBuilder::AddKey(const Slice& key) {
49
515k
  filter_bits_builder_->AddKey(key);
50
515k
  num_added_++;
51
515k
}
52
53
// Add prefix to filter if needed
54
72
inline void FullFilterBlockBuilder::AddPrefix(const Slice& key) {
55
72
  Slice prefix = prefix_extractor_->Transform(key);
56
72
  filter_bits_builder_->AddKey(prefix);
57
72
  num_added_++;
58
72
}
59
60
3.45k
Slice FullFilterBlockBuilder::Finish() {
61
3.45k
  if (num_added_ != 0) {
62
3.45k
    num_added_ = 0;
63
3.45k
    return filter_bits_builder_->Finish(&filter_data_);
64
3.45k
  }
65
2
  return Slice();
66
2
}
67
68
FullFilterBlockReader::FullFilterBlockReader(
69
    const SliceTransform* prefix_extractor, bool whole_key_filtering,
70
    const Slice& contents, FilterBitsReader* filter_bits_reader)
71
    : prefix_extractor_(prefix_extractor),
72
      whole_key_filtering_(whole_key_filtering),
73
4.00k
      contents_(contents) {
74
4.00k
  assert(filter_bits_reader != nullptr);
75
4.00k
  filter_bits_reader_.reset(filter_bits_reader);
76
4.00k
}
77
78
FullFilterBlockReader::FullFilterBlockReader(
79
    const SliceTransform* prefix_extractor, bool whole_key_filtering,
80
    BlockContents&& contents, FilterBitsReader* filter_bits_reader)
81
    : FullFilterBlockReader(prefix_extractor, whole_key_filtering,
82
4.00k
                            contents.data, filter_bits_reader) {
83
4.00k
  block_contents_ = std::move(contents);
84
4.00k
}
Unexecuted instantiation: _ZN7rocksdb21FullFilterBlockReaderC2EPKNS_14SliceTransformEbONS_13BlockContentsEPNS_16FilterBitsReaderE
_ZN7rocksdb21FullFilterBlockReaderC1EPKNS_14SliceTransformEbONS_13BlockContentsEPNS_16FilterBitsReaderE
Line
Count
Source
82
4.00k
                            contents.data, filter_bits_reader) {
83
4.00k
  block_contents_ = std::move(contents);
84
4.00k
}
85
86
bool FullFilterBlockReader::KeyMayMatch(const Slice& key,
87
279k
    uint64_t block_offset) {
88
279k
  assert(block_offset == kNotValid);
89
279k
  if (!whole_key_filtering_) {
90
43
    return true;
91
43
  }
92
279k
  return MayMatch(key);
93
279k
}
94
95
bool FullFilterBlockReader::PrefixMayMatch(const Slice& prefix,
96
60
                                           uint64_t block_offset) {
97
60
  assert(block_offset == kNotValid);
98
60
  if (!prefix_extractor_) {
99
8
    return true;
100
8
  }
101
52
  return MayMatch(prefix);
102
52
}
103
104
279k
bool FullFilterBlockReader::MayMatch(const Slice& entry) {
105
279k
  if (contents_.size() != 0)  {
106
279k
    if (filter_bits_reader_->MayMatch(entry)) {
107
119k
      PERF_COUNTER_ADD(bloom_sst_hit_count, 1);
108
119k
      return true;
109
160k
    } else {
110
160k
      PERF_COUNTER_ADD(bloom_sst_miss_count, 1);
111
160k
      return false;
112
160k
    }
113
4
  }
114
4
  return true;  // remain the same with block_based filter
115
4
}
116
117
0
size_t FullFilterBlockReader::ApproximateMemoryUsage() const {
118
0
  return contents_.size();
119
0
}
120
}  // namespace rocksdb