YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/block_prefix_index.h
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
#ifndef ROCKSDB_TABLE_BLOCK_PREFIX_INDEX_H
21
#define ROCKSDB_TABLE_BLOCK_PREFIX_INDEX_H
22
23
#pragma once
24
25
#include <stdint.h>
26
27
#include "yb/util/slice.h"
28
#include "yb/rocksdb/status.h"
29
30
namespace rocksdb {
31
32
class Comparator;
33
class Iterator;
34
class SliceTransform;
35
36
// Build a hash-based index to speed up the lookup for "index block".
37
// BlockHashIndex accepts a key and, if found, returns its restart index within
38
// that index block.
39
class BlockPrefixIndex {
40
 public:
41
42
  // Maps a key to a list of data blocks that could potentially contain
43
  // the key, based on the prefix.
44
  // Returns the total number of relevant blocks, 0 means the key does
45
  // not exist.
46
  uint32_t GetBlocks(const Slice& key, uint32_t** blocks);
47
48
0
  size_t ApproximateMemoryUsage() const {
49
0
    return sizeof(BlockPrefixIndex) +
50
0
      (num_block_array_buffer_entries_ + num_buckets_) * sizeof(uint32_t);
51
0
  }
52
53
  // Create hash index by reading from the metadata blocks.
54
  // @params prefixes: a sequence of prefixes.
55
  // @params prefix_meta: contains the "metadata" to of the prefixes.
56
  static Status Create(const SliceTransform* hash_key_extractor,
57
                       const Slice& prefixes, const Slice& prefix_meta,
58
                       BlockPrefixIndex** prefix_index);
59
60
1.66k
  ~BlockPrefixIndex() {
61
1.66k
    delete[] buckets_;
62
1.66k
    delete[] block_array_buffer_;
63
1.66k
  }
64
65
 private:
66
  class Builder;
67
  friend Builder;
68
69
  BlockPrefixIndex(const SliceTransform* internal_prefix_extractor,
70
                   uint32_t num_buckets,
71
                   uint32_t* buckets,
72
                   uint32_t num_block_array_buffer_entries,
73
                   uint32_t* block_array_buffer)
74
      : internal_prefix_extractor_(internal_prefix_extractor),
75
        num_buckets_(num_buckets),
76
        num_block_array_buffer_entries_(num_block_array_buffer_entries),
77
        buckets_(buckets),
78
1.66k
        block_array_buffer_(block_array_buffer) {}
79
80
  const SliceTransform* internal_prefix_extractor_;
81
  uint32_t num_buckets_;
82
  uint32_t num_block_array_buffer_entries_;
83
  uint32_t* buckets_;
84
  uint32_t* block_array_buffer_;
85
};
86
87
}  // namespace rocksdb
88
89
#endif // ROCKSDB_TABLE_BLOCK_PREFIX_INDEX_H