]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/include/rocksdb/table_properties.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / table_properties.h
CommitLineData
7c673cae
FG
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file. See the AUTHORS file for names of contributors.
4#pragma once
5
6#include <stdint.h>
7c673cae 7#include <map>
11fdf7f2 8#include <string>
7c673cae
FG
9#include "rocksdb/status.h"
10#include "rocksdb/types.h"
11
12namespace rocksdb {
13
14// -- Table Properties
15// Other than basic table properties, each table may also have the user
16// collected properties.
17// The value of the user-collected properties are encoded as raw bytes --
11fdf7f2 18// users have to interpret these values by themselves.
7c673cae
FG
19// Note: To do prefix seek/scan in `UserCollectedProperties`, you can do
20// something similar to:
21//
22// UserCollectedProperties props = ...;
23// for (auto pos = props.lower_bound(prefix);
24// pos != props.end() && pos->first.compare(0, prefix.size(), prefix) == 0;
25// ++pos) {
26// ...
27// }
28typedef std::map<std::string, std::string> UserCollectedProperties;
29
30// table properties' human-readable names in the property block.
31struct TablePropertiesNames {
32 static const std::string kDataSize;
33 static const std::string kIndexSize;
11fdf7f2
TL
34 static const std::string kIndexPartitions;
35 static const std::string kTopLevelIndexSize;
36 static const std::string kIndexKeyIsUserKey;
37 static const std::string kIndexValueIsDeltaEncoded;
7c673cae
FG
38 static const std::string kFilterSize;
39 static const std::string kRawKeySize;
40 static const std::string kRawValueSize;
41 static const std::string kNumDataBlocks;
42 static const std::string kNumEntries;
11fdf7f2 43 static const std::string kNumRangeDeletions;
7c673cae
FG
44 static const std::string kFormatVersion;
45 static const std::string kFixedKeyLen;
46 static const std::string kFilterPolicy;
47 static const std::string kColumnFamilyName;
48 static const std::string kColumnFamilyId;
49 static const std::string kComparator;
50 static const std::string kMergeOperator;
51 static const std::string kPrefixExtractorName;
52 static const std::string kPropertyCollectors;
53 static const std::string kCompression;
11fdf7f2
TL
54 static const std::string kCreationTime;
55 static const std::string kOldestKeyTime;
7c673cae
FG
56};
57
58extern const std::string kPropertiesBlock;
59extern const std::string kCompressionDictBlock;
60extern const std::string kRangeDelBlock;
61
7c673cae
FG
62// `TablePropertiesCollector` provides the mechanism for users to collect
63// their own properties that they are interested in. This class is essentially
64// a collection of callback functions that will be invoked during table
11fdf7f2 65// building. It is constructed with TablePropertiesCollectorFactory. The methods
7c673cae
FG
66// don't need to be thread-safe, as we will create exactly one
67// TablePropertiesCollector object per table and then call it sequentially
68class TablePropertiesCollector {
69 public:
70 virtual ~TablePropertiesCollector() {}
71
72 // DEPRECATE User defined collector should implement AddUserKey(), though
73 // this old function still works for backward compatible reason.
74 // Add() will be called when a new key/value pair is inserted into the table.
75 // @params key the user key that is inserted into the table.
76 // @params value the value that is inserted into the table.
77 virtual Status Add(const Slice& /*key*/, const Slice& /*value*/) {
78 return Status::InvalidArgument(
79 "TablePropertiesCollector::Add() deprecated.");
80 }
81
82 // AddUserKey() will be called when a new key/value pair is inserted into the
83 // table.
84 // @params key the user key that is inserted into the table.
85 // @params value the value that is inserted into the table.
86 virtual Status AddUserKey(const Slice& key, const Slice& value,
87 EntryType /*type*/, SequenceNumber /*seq*/,
88 uint64_t /*file_size*/) {
89 // For backwards-compatibility.
90 return Add(key, value);
91 }
92
93 // Finish() will be called when a table has already been built and is ready
94 // for writing the properties block.
95 // @params properties User will add their collected statistics to
96 // `properties`.
97 virtual Status Finish(UserCollectedProperties* properties) = 0;
98
99 // Return the human-readable properties, where the key is property name and
100 // the value is the human-readable form of value.
101 virtual UserCollectedProperties GetReadableProperties() const = 0;
102
103 // The name of the properties collector can be used for debugging purpose.
104 virtual const char* Name() const = 0;
105
106 // EXPERIMENTAL Return whether the output file should be further compacted
107 virtual bool NeedCompact() const { return false; }
108};
109
110// Constructs TablePropertiesCollector. Internals create a new
111// TablePropertiesCollector for each new table
112class TablePropertiesCollectorFactory {
113 public:
114 struct Context {
115 uint32_t column_family_id;
116 static const uint32_t kUnknownColumnFamily;
117 };
118
119 virtual ~TablePropertiesCollectorFactory() {}
120 // has to be thread-safe
121 virtual TablePropertiesCollector* CreateTablePropertiesCollector(
122 TablePropertiesCollectorFactory::Context context) = 0;
123
124 // The name of the properties collector can be used for debugging purpose.
125 virtual const char* Name() const = 0;
126};
127
128// TableProperties contains a bunch of read-only properties of its associated
129// table.
130struct TableProperties {
131 public:
132 // the total size of all data blocks.
133 uint64_t data_size = 0;
134 // the size of index block.
135 uint64_t index_size = 0;
11fdf7f2
TL
136 // Total number of index partitions if kTwoLevelIndexSearch is used
137 uint64_t index_partitions = 0;
138 // Size of the top-level index if kTwoLevelIndexSearch is used
139 uint64_t top_level_index_size = 0;
140 // Whether the index key is user key. Otherwise it includes 8 byte of sequence
141 // number added by internal key format.
142 uint64_t index_key_is_user_key = 0;
143 // Whether delta encoding is used to encode the index values.
144 uint64_t index_value_is_delta_encoded = 0;
7c673cae
FG
145 // the size of filter block.
146 uint64_t filter_size = 0;
147 // total raw key size
148 uint64_t raw_key_size = 0;
149 // total raw value size
150 uint64_t raw_value_size = 0;
151 // the number of blocks in this table
152 uint64_t num_data_blocks = 0;
153 // the number of entries in this table
154 uint64_t num_entries = 0;
11fdf7f2
TL
155 // the number of range deletions in this table
156 uint64_t num_range_deletions = 0;
7c673cae
FG
157 // format version, reserved for backward compatibility
158 uint64_t format_version = 0;
159 // If 0, key is variable length. Otherwise number of bytes for each key.
160 uint64_t fixed_key_len = 0;
161 // ID of column family for this SST file, corresponding to the CF identified
162 // by column_family_name.
163 uint64_t column_family_id =
164 rocksdb::TablePropertiesCollectorFactory::Context::kUnknownColumnFamily;
11fdf7f2
TL
165 // The time when the SST file was created.
166 // Since SST files are immutable, this is equivalent to last modified time.
167 uint64_t creation_time = 0;
168 // Timestamp of the earliest key. 0 means unknown.
169 uint64_t oldest_key_time = 0;
7c673cae
FG
170
171 // Name of the column family with which this SST file is associated.
172 // If column family is unknown, `column_family_name` will be an empty string.
173 std::string column_family_name;
174
175 // The name of the filter policy used in this table.
176 // If no filter policy is used, `filter_policy_name` will be an empty string.
177 std::string filter_policy_name;
178
179 // The name of the comparator used in this table.
180 std::string comparator_name;
181
182 // The name of the merge operator used in this table.
183 // If no merge operator is used, `merge_operator_name` will be "nullptr".
184 std::string merge_operator_name;
185
186 // The name of the prefix extractor used in this table
187 // If no prefix extractor is used, `prefix_extractor_name` will be "nullptr".
188 std::string prefix_extractor_name;
189
190 // The names of the property collectors factories used in this table
191 // separated by commas
192 // {collector_name[1]},{collector_name[2]},{collector_name[3]} ..
193 std::string property_collectors_names;
194
195 // The compression algo used to compress the SST files.
196 std::string compression_name;
197
198 // user collected properties
199 UserCollectedProperties user_collected_properties;
200 UserCollectedProperties readable_properties;
201
202 // The offset of the value of each property in the file.
203 std::map<std::string, uint64_t> properties_offsets;
204
205 // convert this object to a human readable form
206 // @prop_delim: delimiter for each property.
207 std::string ToString(const std::string& prop_delim = "; ",
208 const std::string& kv_delim = "=") const;
209
210 // Aggregate the numerical member variables of the specified
211 // TableProperties.
212 void Add(const TableProperties& tp);
213};
214
215// Extra properties
216// Below is a list of non-basic properties that are collected by database
217// itself. Especially some properties regarding to the internal keys (which
218// is unknown to `table`).
219extern uint64_t GetDeletedKeys(const UserCollectedProperties& props);
220extern uint64_t GetMergeOperands(const UserCollectedProperties& props,
221 bool* property_present);
222
223} // namespace rocksdb