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