]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/table_builder.h
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / rocksdb / table / table_builder.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
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).
5 //
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #pragma once
11
12 #include <stdint.h>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 #include "db/dbformat.h"
17 #include "db/table_properties_collector.h"
18 #include "options/cf_options.h"
19 #include "rocksdb/options.h"
20 #include "rocksdb/table_properties.h"
21 #include "util/file_reader_writer.h"
22
23 namespace rocksdb {
24
25 class Slice;
26 class Status;
27
28 struct TableReaderOptions {
29 // @param skip_filters Disables loading/accessing the filter block
30 TableReaderOptions(const ImmutableCFOptions& _ioptions,
31 const SliceTransform* _prefix_extractor,
32 const EnvOptions& _env_options,
33 const InternalKeyComparator& _internal_comparator,
34 bool _skip_filters = false, bool _immortal = false,
35 int _level = -1)
36 : TableReaderOptions(_ioptions, _prefix_extractor, _env_options,
37 _internal_comparator, _skip_filters, _immortal,
38 _level, 0 /* _largest_seqno */) {}
39
40 // @param skip_filters Disables loading/accessing the filter block
41 TableReaderOptions(const ImmutableCFOptions& _ioptions,
42 const SliceTransform* _prefix_extractor,
43 const EnvOptions& _env_options,
44 const InternalKeyComparator& _internal_comparator,
45 bool _skip_filters, bool _immortal, int _level,
46 SequenceNumber _largest_seqno)
47 : ioptions(_ioptions),
48 prefix_extractor(_prefix_extractor),
49 env_options(_env_options),
50 internal_comparator(_internal_comparator),
51 skip_filters(_skip_filters),
52 immortal(_immortal),
53 level(_level),
54 largest_seqno(_largest_seqno) {}
55
56 const ImmutableCFOptions& ioptions;
57 const SliceTransform* prefix_extractor;
58 const EnvOptions& env_options;
59 const InternalKeyComparator& internal_comparator;
60 // This is only used for BlockBasedTable (reader)
61 bool skip_filters;
62 // Whether the table will be valid as long as the DB is open
63 bool immortal;
64 // what level this table/file is on, -1 for "not set, don't know"
65 int level;
66 // largest seqno in the table
67 SequenceNumber largest_seqno;
68 };
69
70 struct TableBuilderOptions {
71 TableBuilderOptions(
72 const ImmutableCFOptions& _ioptions, const MutableCFOptions& _moptions,
73 const InternalKeyComparator& _internal_comparator,
74 const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
75 _int_tbl_prop_collector_factories,
76 CompressionType _compression_type, uint64_t _sample_for_compression,
77 const CompressionOptions& _compression_opts, bool _skip_filters,
78 const std::string& _column_family_name, int _level,
79 const uint64_t _creation_time = 0, const int64_t _oldest_key_time = 0,
80 const uint64_t _target_file_size = 0)
81 : ioptions(_ioptions),
82 moptions(_moptions),
83 internal_comparator(_internal_comparator),
84 int_tbl_prop_collector_factories(_int_tbl_prop_collector_factories),
85 compression_type(_compression_type),
86 sample_for_compression(_sample_for_compression),
87 compression_opts(_compression_opts),
88 skip_filters(_skip_filters),
89 column_family_name(_column_family_name),
90 level(_level),
91 creation_time(_creation_time),
92 oldest_key_time(_oldest_key_time),
93 target_file_size(_target_file_size) {}
94 const ImmutableCFOptions& ioptions;
95 const MutableCFOptions& moptions;
96 const InternalKeyComparator& internal_comparator;
97 const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
98 int_tbl_prop_collector_factories;
99 CompressionType compression_type;
100 uint64_t sample_for_compression;
101 const CompressionOptions& compression_opts;
102 bool skip_filters; // only used by BlockBasedTableBuilder
103 const std::string& column_family_name;
104 int level; // what level this table/file is on, -1 for "not set, don't know"
105 const uint64_t creation_time;
106 const int64_t oldest_key_time;
107 const uint64_t target_file_size;
108 };
109
110 // TableBuilder provides the interface used to build a Table
111 // (an immutable and sorted map from keys to values).
112 //
113 // Multiple threads can invoke const methods on a TableBuilder without
114 // external synchronization, but if any of the threads may call a
115 // non-const method, all threads accessing the same TableBuilder must use
116 // external synchronization.
117 class TableBuilder {
118 public:
119 // REQUIRES: Either Finish() or Abandon() has been called.
120 virtual ~TableBuilder() {}
121
122 // Add key,value to the table being constructed.
123 // REQUIRES: key is after any previously added key according to comparator.
124 // REQUIRES: Finish(), Abandon() have not been called
125 virtual void Add(const Slice& key, const Slice& value) = 0;
126
127 // Return non-ok iff some error has been detected.
128 virtual Status status() const = 0;
129
130 // Finish building the table.
131 // REQUIRES: Finish(), Abandon() have not been called
132 virtual Status Finish() = 0;
133
134 // Indicate that the contents of this builder should be abandoned.
135 // If the caller is not going to call Finish(), it must call Abandon()
136 // before destroying this builder.
137 // REQUIRES: Finish(), Abandon() have not been called
138 virtual void Abandon() = 0;
139
140 // Number of calls to Add() so far.
141 virtual uint64_t NumEntries() const = 0;
142
143 // Size of the file generated so far. If invoked after a successful
144 // Finish() call, returns the size of the final generated file.
145 virtual uint64_t FileSize() const = 0;
146
147 // If the user defined table properties collector suggest the file to
148 // be further compacted.
149 virtual bool NeedCompact() const { return false; }
150
151 // Returns table properties
152 virtual TableProperties GetTableProperties() const = 0;
153 };
154
155 } // namespace rocksdb