]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/table/block_prefix_index.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / table / block_prefix_index.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5#pragma once
6
7#include <stdint.h>
8#include "rocksdb/status.h"
9
10namespace rocksdb {
11
12class Comparator;
13class Iterator;
14class Slice;
15class SliceTransform;
16
17// Build a hash-based index to speed up the lookup for "index block".
18// BlockHashIndex accepts a key and, if found, returns its restart index within
19// that index block.
20class BlockPrefixIndex {
21 public:
22
23 // Maps a key to a list of data blocks that could potentially contain
24 // the key, based on the prefix.
25 // Returns the total number of relevant blocks, 0 means the key does
26 // not exist.
27 uint32_t GetBlocks(const Slice& key, uint32_t** blocks);
28
29 size_t ApproximateMemoryUsage() const {
30 return sizeof(BlockPrefixIndex) +
31 (num_block_array_buffer_entries_ + num_buckets_) * sizeof(uint32_t);
32 }
33
34 // Create hash index by reading from the metadata blocks.
35 // @params prefixes: a sequence of prefixes.
36 // @params prefix_meta: contains the "metadata" to of the prefixes.
37 static Status Create(const SliceTransform* hash_key_extractor,
38 const Slice& prefixes, const Slice& prefix_meta,
39 BlockPrefixIndex** prefix_index);
40
41 ~BlockPrefixIndex() {
42 delete[] buckets_;
43 delete[] block_array_buffer_;
44 }
45
46 private:
47 class Builder;
48 friend Builder;
49
50 BlockPrefixIndex(const SliceTransform* internal_prefix_extractor,
51 uint32_t num_buckets,
52 uint32_t* buckets,
53 uint32_t num_block_array_buffer_entries,
54 uint32_t* block_array_buffer)
55 : internal_prefix_extractor_(internal_prefix_extractor),
56 num_buckets_(num_buckets),
57 num_block_array_buffer_entries_(num_block_array_buffer_entries),
58 buckets_(buckets),
59 block_array_buffer_(block_array_buffer) {}
60
61 const SliceTransform* internal_prefix_extractor_;
62 uint32_t num_buckets_;
63 uint32_t num_block_array_buffer_entries_;
64 uint32_t* buckets_;
65 uint32_t* block_array_buffer_;
66};
67
68} // namespace rocksdb