]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/table/plain_table_builder.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / table / plain_table_builder.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#ifndef ROCKSDB_LITE
8#include <stdint.h>
9#include <string>
10#include <vector>
11#include "rocksdb/options.h"
12#include "rocksdb/status.h"
13#include "rocksdb/table.h"
14#include "rocksdb/table_properties.h"
15#include "table/bloom_block.h"
16#include "table/plain_table_index.h"
17#include "table/plain_table_key_coding.h"
18#include "table/table_builder.h"
19
20namespace rocksdb {
21
22class BlockBuilder;
23class BlockHandle;
24class WritableFile;
25class TableBuilder;
26
27class PlainTableBuilder: public TableBuilder {
28 public:
29 // Create a builder that will store the contents of the table it is
30 // building in *file. Does not close the file. It is up to the
31 // caller to close the file after calling Finish(). The output file
32 // will be part of level specified by 'level'. A value of -1 means
33 // that the caller does not know which level the output file will reside.
34 PlainTableBuilder(
11fdf7f2 35 const ImmutableCFOptions& ioptions, const MutableCFOptions& moptions,
7c673cae
FG
36 const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
37 int_tbl_prop_collector_factories,
38 uint32_t column_family_id, WritableFileWriter* file,
39 uint32_t user_key_size, EncodingType encoding_type,
40 size_t index_sparseness, uint32_t bloom_bits_per_key,
41 const std::string& column_family_name, uint32_t num_probes = 6,
42 size_t huge_page_tlb_size = 0, double hash_table_ratio = 0,
43 bool store_index_in_file = false);
44
45 // REQUIRES: Either Finish() or Abandon() has been called.
46 ~PlainTableBuilder();
47
48 // Add key,value to the table being constructed.
49 // REQUIRES: key is after any previously added key according to comparator.
50 // REQUIRES: Finish(), Abandon() have not been called
51 void Add(const Slice& key, const Slice& value) override;
52
53 // Return non-ok iff some error has been detected.
54 Status status() const override;
55
56 // Finish building the table. Stops using the file passed to the
57 // constructor after this function returns.
58 // REQUIRES: Finish(), Abandon() have not been called
59 Status Finish() override;
60
61 // Indicate that the contents of this builder should be abandoned. Stops
62 // using the file passed to the constructor after this function returns.
63 // If the caller is not going to call Finish(), it must call Abandon()
64 // before destroying this builder.
65 // REQUIRES: Finish(), Abandon() have not been called
66 void Abandon() override;
67
68 // Number of calls to Add() so far.
69 uint64_t NumEntries() const override;
70
71 // Size of the file generated so far. If invoked after a successful
72 // Finish() call, returns the size of the final generated file.
73 uint64_t FileSize() const override;
74
75 TableProperties GetTableProperties() const override { return properties_; }
76
77 bool SaveIndexInFile() const { return store_index_in_file_; }
78
79 private:
80 Arena arena_;
81 const ImmutableCFOptions& ioptions_;
11fdf7f2 82 const MutableCFOptions& moptions_;
7c673cae
FG
83 std::vector<std::unique_ptr<IntTblPropCollector>>
84 table_properties_collectors_;
85
86 BloomBlockBuilder bloom_block_;
87 std::unique_ptr<PlainTableIndexBuilder> index_builder_;
88
89 WritableFileWriter* file_;
90 uint64_t offset_ = 0;
91 uint32_t bloom_bits_per_key_;
92 size_t huge_page_tlb_size_;
93 Status status_;
94 TableProperties properties_;
95 PlainTableKeyEncoder encoder_;
96
97 bool store_index_in_file_;
98
99 std::vector<uint32_t> keys_or_prefixes_hashes_;
100 bool closed_ = false; // Either Finish() or Abandon() has been called.
101
102 const SliceTransform* prefix_extractor_;
103
104 Slice GetPrefix(const Slice& target) const {
105 assert(target.size() >= 8); // target is internal key
106 return GetPrefixFromUserKey(GetUserKey(target));
107 }
108
109 Slice GetPrefix(const ParsedInternalKey& target) const {
110 return GetPrefixFromUserKey(target.user_key);
111 }
112
113 Slice GetUserKey(const Slice& key) const {
114 return Slice(key.data(), key.size() - 8);
115 }
116
117 Slice GetPrefixFromUserKey(const Slice& user_key) const {
118 if (!IsTotalOrderMode()) {
119 return prefix_extractor_->Transform(user_key);
120 } else {
121 // Use empty slice as prefix if prefix_extractor is not set.
122 // In that case,
123 // it falls back to pure binary search and
124 // total iterator seek is supported.
125 return Slice();
126 }
127 }
128
129 bool IsTotalOrderMode() const { return (prefix_extractor_ == nullptr); }
130
131 // No copying allowed
132 PlainTableBuilder(const PlainTableBuilder&) = delete;
133 void operator=(const PlainTableBuilder&) = delete;
134};
135
136} // namespace rocksdb
137
138#endif // ROCKSDB_LITE