]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/table/partitioned_filter_block.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / table / partitioned_filter_block.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
6#pragma once
7
8#include <list>
9#include <string>
10#include <unordered_map>
11#include "db/dbformat.h"
12#include "rocksdb/options.h"
13#include "rocksdb/slice.h"
14#include "rocksdb/slice_transform.h"
15
16#include "table/block.h"
17#include "table/block_based_table_reader.h"
18#include "table/full_filter_block.h"
19#include "table/index_builder.h"
20#include "util/autovector.h"
21
22namespace rocksdb {
23
24class PartitionedFilterBlockBuilder : public FullFilterBlockBuilder {
25 public:
26 explicit PartitionedFilterBlockBuilder(
27 const SliceTransform* prefix_extractor, bool whole_key_filtering,
28 FilterBitsBuilder* filter_bits_builder, int index_block_restart_interval,
11fdf7f2
TL
29 const bool use_value_delta_encoding,
30 PartitionedIndexBuilder* const p_index_builder,
31 const uint32_t partition_size);
7c673cae
FG
32
33 virtual ~PartitionedFilterBlockBuilder();
34
35 void AddKey(const Slice& key) override;
36
11fdf7f2
TL
37 size_t NumAdded() const override { return num_added_; }
38
7c673cae
FG
39 virtual Slice Finish(const BlockHandle& last_partition_block_handle,
40 Status* status) override;
41
42 private:
43 // Filter data
44 BlockBuilder index_on_filter_block_builder_; // top-level index builder
11fdf7f2
TL
45 BlockBuilder
46 index_on_filter_block_builder_without_seq_; // same for user keys
7c673cae
FG
47 struct FilterEntry {
48 std::string key;
49 Slice filter;
50 };
51 std::list<FilterEntry> filters; // list of partitioned indexes and their keys
52 std::unique_ptr<IndexBuilder> value;
53 std::vector<std::unique_ptr<const char[]>> filter_gc;
54 bool finishing_filters =
55 false; // true if Finish is called once but not complete yet.
56 // The policy of when cut a filter block and Finish it
57 void MaybeCutAFilterBlock();
11fdf7f2
TL
58 // Currently we keep the same number of partitions for filters and indexes.
59 // This would allow for some potentioal optimizations in future. If such
60 // optimizations did not realize we can use different number of partitions and
61 // eliminate p_index_builder_
7c673cae 62 PartitionedIndexBuilder* const p_index_builder_;
11fdf7f2
TL
63 // The desired number of filters per partition
64 uint32_t filters_per_partition_;
65 // The current number of filters in the last partition
66 uint32_t filters_in_partition_;
67 // Number of keys added
68 size_t num_added_;
69 BlockHandle last_encoded_handle_;
7c673cae
FG
70};
71
11fdf7f2
TL
72class PartitionedFilterBlockReader : public FilterBlockReader,
73 public Cleanable {
7c673cae 74 public:
11fdf7f2
TL
75 explicit PartitionedFilterBlockReader(
76 const SliceTransform* prefix_extractor, bool whole_key_filtering,
77 BlockContents&& contents, FilterBitsReader* filter_bits_reader,
78 Statistics* stats, const InternalKeyComparator comparator,
79 const BlockBasedTable* table, const bool index_key_includes_seq,
80 const bool index_value_is_full);
7c673cae
FG
81 virtual ~PartitionedFilterBlockReader();
82
83 virtual bool IsBlockBased() override { return false; }
84 virtual bool KeyMayMatch(
11fdf7f2
TL
85 const Slice& key, const SliceTransform* prefix_extractor,
86 uint64_t block_offset = kNotValid, const bool no_io = false,
7c673cae
FG
87 const Slice* const const_ikey_ptr = nullptr) override;
88 virtual bool PrefixMayMatch(
11fdf7f2
TL
89 const Slice& prefix, const SliceTransform* prefix_extractor,
90 uint64_t block_offset = kNotValid, const bool no_io = false,
7c673cae
FG
91 const Slice* const const_ikey_ptr = nullptr) override;
92 virtual size_t ApproximateMemoryUsage() const override;
93
94 private:
11fdf7f2 95 BlockHandle GetFilterPartitionHandle(const Slice& entry);
7c673cae 96 BlockBasedTable::CachableEntry<FilterBlockReader> GetFilterPartition(
11fdf7f2
TL
97 FilePrefetchBuffer* prefetch_buffer, BlockHandle& handle,
98 const bool no_io, bool* cached,
99 const SliceTransform* prefix_extractor = nullptr);
100 virtual void CacheDependencies(
101 bool bin, const SliceTransform* prefix_extractor) override;
7c673cae
FG
102
103 const SliceTransform* prefix_extractor_;
104 std::unique_ptr<Block> idx_on_fltr_blk_;
11fdf7f2 105 const InternalKeyComparator comparator_;
7c673cae 106 const BlockBasedTable* table_;
11fdf7f2
TL
107 const bool index_key_includes_seq_;
108 const bool index_value_is_full_;
109 std::unordered_map<uint64_t,
110 BlockBasedTable::CachableEntry<FilterBlockReader>>
111 filter_map_;
7c673cae
FG
112};
113
114} // namespace rocksdb