/Users/deen/code/yugabyte-db/src/yb/rocksdb/table_properties.h
Line | Count | Source (jump to first uncovered line) |
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 | | // |
5 | | // The following only applies to changes made to this file as part of YugaByte development. |
6 | | // |
7 | | // Portions Copyright (c) YugaByte, Inc. |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
10 | | // in compliance with the License. You may obtain a copy of the License at |
11 | | // |
12 | | // http://www.apache.org/licenses/LICENSE-2.0 |
13 | | // |
14 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
15 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
16 | | // or implied. See the License for the specific language governing permissions and limitations |
17 | | // under the License. |
18 | | // |
19 | | #ifndef YB_ROCKSDB_TABLE_PROPERTIES_H |
20 | | #define YB_ROCKSDB_TABLE_PROPERTIES_H |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <stdint.h> |
25 | | #include <string> |
26 | | #include <map> |
27 | | #include "yb/rocksdb/status.h" |
28 | | #include "yb/util/slice.h" |
29 | | #include "yb/rocksdb/types.h" |
30 | | |
31 | | namespace rocksdb { |
32 | | |
33 | | // -- Table Properties |
34 | | // Other than basic table properties, each table may also have the user |
35 | | // collected properties. |
36 | | // The value of the user-collected properties are encoded as raw bytes -- |
37 | | // users have to interpret these values by themselves. |
38 | | // Note: To do prefix seek/scan in `UserCollectedProperties`, you can do |
39 | | // something similar to: |
40 | | // |
41 | | // UserCollectedProperties props = ...; |
42 | | // for (auto pos = props.lower_bound(prefix); |
43 | | // pos != props.end() && pos->first.compare(0, prefix.size(), prefix) == 0; |
44 | | // ++pos) { |
45 | | // ... |
46 | | // } |
47 | | typedef std::map<std::string, std::string> UserCollectedProperties; |
48 | | |
49 | | // TableProperties contains a bunch of read-only properties of its associated |
50 | | // table. |
51 | | struct TableProperties { |
52 | | public: |
53 | | // the total size of all data blocks. |
54 | | uint64_t data_size = 0; |
55 | | // the size of data index block. |
56 | | uint64_t data_index_size = 0; |
57 | | // the size of filter block. |
58 | | uint64_t filter_size = 0; |
59 | | // the size of filter index block. |
60 | | uint64_t filter_index_size = 0; |
61 | | // total raw key size |
62 | | uint64_t raw_key_size = 0; |
63 | | // total raw value size |
64 | | uint64_t raw_value_size = 0; |
65 | | // the number of blocks in this table |
66 | | uint64_t num_data_blocks = 0; |
67 | | // the number of entries in this table |
68 | | uint64_t num_entries = 0; |
69 | | // the number of filter blocks |
70 | | uint64_t num_filter_blocks = 0; |
71 | | // the number of data index blocks |
72 | | uint64_t num_data_index_blocks = 0; |
73 | | // format version, reserved for backward compatibility |
74 | | uint64_t format_version = 0; |
75 | | // If 0, key is variable length. Otherwise number of bytes for each key. |
76 | | uint64_t fixed_key_len = 0; |
77 | | |
78 | | // The name of the filter policy used in this table. |
79 | | // If no filter policy is used, `filter_policy_name` will be an empty string. |
80 | | std::string filter_policy_name; |
81 | | |
82 | | // user collected properties |
83 | | UserCollectedProperties user_collected_properties; |
84 | | UserCollectedProperties readable_properties; |
85 | | |
86 | | // convert this object to a human readable form |
87 | | // @prop_delim: delimiter for each property. |
88 | | std::string ToString(const std::string& prop_delim = "; ", |
89 | | const std::string& kv_delim = "=") const; |
90 | | |
91 | | // Aggregate the numerical member variables of the specified |
92 | | // TableProperties. |
93 | | void Add(const TableProperties& tp); |
94 | | }; |
95 | | |
96 | | // table properties' human-readable names in the property block. |
97 | | struct TablePropertiesNames { |
98 | | static const std::string kDataSize; |
99 | | static const std::string kDataIndexSize; |
100 | | static const std::string kFilterSize; |
101 | | static const std::string kFilterIndexSize; |
102 | | static const std::string kRawKeySize; |
103 | | static const std::string kRawValueSize; |
104 | | static const std::string kNumDataBlocks; |
105 | | static const std::string kNumEntries; |
106 | | static const std::string kNumFilterBlocks; |
107 | | static const std::string kNumDataIndexBlocks; |
108 | | static const std::string kFormatVersion; |
109 | | static const std::string kFixedKeyLen; |
110 | | static const std::string kFilterPolicy; |
111 | | }; |
112 | | |
113 | | extern const std::string kPropertiesBlock; |
114 | | |
115 | | enum EntryType { |
116 | | kEntryPut, |
117 | | kEntryDelete, |
118 | | kEntrySingleDelete, |
119 | | kEntryMerge, |
120 | | kEntryOther, |
121 | | }; |
122 | | |
123 | | // `TablePropertiesCollector` provides the mechanism for users to collect |
124 | | // their own properties that they are interested in. This class is essentially |
125 | | // a collection of callback functions that will be invoked during table |
126 | | // building. It is construced with TablePropertiesCollectorFactory. The methods |
127 | | // don't need to be thread-safe, as we will create exactly one |
128 | | // TablePropertiesCollector object per table and then call it sequentially |
129 | | class TablePropertiesCollector { |
130 | | public: |
131 | 567 | virtual ~TablePropertiesCollector() {} |
132 | | |
133 | | // DEPRECATE User defined collector should implement AddUserKey(), though |
134 | | // this old function still works for backward compatible reason. |
135 | | // Add() will be called when a new key/value pair is inserted into the table. |
136 | | // @params key the user key that is inserted into the table. |
137 | | // @params value the value that is inserted into the table. |
138 | 0 | virtual Status Add(const Slice& /*key*/, const Slice& /*value*/) { |
139 | 0 | return STATUS(InvalidArgument, "TablePropertiesCollector::Add() deprecated."); |
140 | 0 | } Unexecuted instantiation: _ZN7rocksdb24TablePropertiesCollector3AddERKN2yb5SliceES4_ Unexecuted instantiation: _ZN7rocksdb24TablePropertiesCollector3AddERKN2yb5SliceES4_ |
141 | | |
142 | | // AddUserKey() will be called when a new key/value pair is inserted into the |
143 | | // table. |
144 | | // @params key the user key that is inserted into the table. |
145 | | // @params value the value that is inserted into the table. |
146 | | virtual Status AddUserKey(const Slice& key, const Slice& value, |
147 | | EntryType /*type*/, SequenceNumber /*seq*/, |
148 | 72 | uint64_t /*file_size*/) { |
149 | | // For backwards-compatibility. |
150 | 72 | return Add(key, value); |
151 | 72 | } |
152 | | |
153 | | // Finish() will be called when a table has already been built and is ready |
154 | | // for writing the properties block. |
155 | | // @params properties User will add their collected statistics to |
156 | | // `properties`. |
157 | | virtual Status Finish(UserCollectedProperties* properties) = 0; |
158 | | |
159 | | // Return the human-readable properties, where the key is property name and |
160 | | // the value is the human-readable form of value. |
161 | | virtual UserCollectedProperties GetReadableProperties() const = 0; |
162 | | |
163 | | // The name of the properties collector can be used for debugging purpose. |
164 | | virtual const char* Name() const = 0; |
165 | | |
166 | | // EXPERIMENTAL Return whether the output file should be further compacted |
167 | 125 | virtual bool NeedCompact() const { return false; } |
168 | | }; |
169 | | |
170 | | // Constructs TablePropertiesCollector. Internals create a new |
171 | | // TablePropertiesCollector for each new table |
172 | | class TablePropertiesCollectorFactory { |
173 | | public: |
174 | | struct Context { |
175 | | uint32_t column_family_id; |
176 | | static const uint32_t kUnknownColumnFamily; |
177 | | }; |
178 | | |
179 | 356 | virtual ~TablePropertiesCollectorFactory() {} |
180 | | // has to be thread-safe |
181 | | virtual TablePropertiesCollector* CreateTablePropertiesCollector( |
182 | | TablePropertiesCollectorFactory::Context context) = 0; |
183 | | |
184 | | // The name of the properties collector can be used for debugging purpose. |
185 | | virtual const char* Name() const = 0; |
186 | | }; |
187 | | |
188 | | // Extra properties |
189 | | // Below is a list of non-basic properties that are collected by database |
190 | | // itself. Especially some properties regarding to the internal keys (which |
191 | | // is unknown to `table`). |
192 | | extern uint64_t GetDeletedKeys(const UserCollectedProperties& props); |
193 | | |
194 | | } // namespace rocksdb |
195 | | |
196 | | #endif // YB_ROCKSDB_TABLE_PROPERTIES_H |