]>
Commit | Line | Data |
---|---|---|
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 | #include "rocksdb/table_properties.h" | |
7 | #include "port/port.h" | |
8 | #include "rocksdb/env.h" | |
9 | #include "rocksdb/iterator.h" | |
10 | #include "table/block.h" | |
11 | #include "table/internal_iterator.h" | |
12 | #include "table/table_properties_internal.h" | |
13 | #include "util/string_util.h" | |
14 | ||
15 | namespace rocksdb { | |
16 | ||
17 | const uint32_t TablePropertiesCollectorFactory::Context::kUnknownColumnFamily = | |
18 | port::kMaxInt32; | |
19 | ||
20 | namespace { | |
21 | void AppendProperty( | |
22 | std::string& props, | |
23 | const std::string& key, | |
24 | const std::string& value, | |
25 | const std::string& prop_delim, | |
26 | const std::string& kv_delim) { | |
27 | props.append(key); | |
28 | props.append(kv_delim); | |
29 | props.append(value); | |
30 | props.append(prop_delim); | |
31 | } | |
32 | ||
33 | template <class TValue> | |
34 | void AppendProperty( | |
35 | std::string& props, | |
36 | const std::string& key, | |
37 | const TValue& value, | |
38 | const std::string& prop_delim, | |
39 | const std::string& kv_delim) { | |
40 | AppendProperty( | |
41 | props, key, ToString(value), prop_delim, kv_delim | |
42 | ); | |
43 | } | |
44 | ||
45 | // Seek to the specified meta block. | |
46 | // Return true if it successfully seeks to that block. | |
47 | Status SeekToMetaBlock(InternalIterator* meta_iter, | |
48 | const std::string& block_name, bool* is_found, | |
49 | BlockHandle* block_handle = nullptr) { | |
50 | if (block_handle != nullptr) { | |
51 | *block_handle = BlockHandle::NullBlockHandle(); | |
52 | } | |
53 | *is_found = true; | |
54 | meta_iter->Seek(block_name); | |
55 | if (meta_iter->status().ok()) { | |
56 | if (meta_iter->Valid() && meta_iter->key() == block_name) { | |
57 | *is_found = true; | |
58 | if (block_handle) { | |
59 | Slice v = meta_iter->value(); | |
60 | return block_handle->DecodeFrom(&v); | |
61 | } | |
62 | } else { | |
63 | *is_found = false; | |
64 | return Status::OK(); | |
65 | } | |
66 | } | |
67 | return meta_iter->status(); | |
68 | } | |
69 | } | |
70 | ||
71 | std::string TableProperties::ToString( | |
72 | const std::string& prop_delim, | |
73 | const std::string& kv_delim) const { | |
74 | std::string result; | |
75 | result.reserve(1024); | |
76 | ||
77 | // Basic Info | |
78 | AppendProperty(result, "# data blocks", num_data_blocks, prop_delim, | |
79 | kv_delim); | |
80 | AppendProperty(result, "# entries", num_entries, prop_delim, kv_delim); | |
494da23a TL |
81 | AppendProperty(result, "# deletions", num_deletions, prop_delim, kv_delim); |
82 | AppendProperty(result, "# merge operands", num_merge_operands, prop_delim, | |
83 | kv_delim); | |
11fdf7f2 TL |
84 | AppendProperty(result, "# range deletions", num_range_deletions, prop_delim, |
85 | kv_delim); | |
7c673cae FG |
86 | |
87 | AppendProperty(result, "raw key size", raw_key_size, prop_delim, kv_delim); | |
88 | AppendProperty(result, "raw average key size", | |
89 | num_entries != 0 ? 1.0 * raw_key_size / num_entries : 0.0, | |
90 | prop_delim, kv_delim); | |
91 | AppendProperty(result, "raw value size", raw_value_size, prop_delim, | |
92 | kv_delim); | |
93 | AppendProperty(result, "raw average value size", | |
94 | num_entries != 0 ? 1.0 * raw_value_size / num_entries : 0.0, | |
95 | prop_delim, kv_delim); | |
96 | ||
97 | AppendProperty(result, "data block size", data_size, prop_delim, kv_delim); | |
11fdf7f2 TL |
98 | char index_block_size_str[80]; |
99 | snprintf(index_block_size_str, sizeof(index_block_size_str), | |
100 | "index block size (user-key? %d, delta-value? %d)", | |
101 | static_cast<int>(index_key_is_user_key), | |
102 | static_cast<int>(index_value_is_delta_encoded)); | |
103 | AppendProperty(result, index_block_size_str, index_size, prop_delim, | |
104 | kv_delim); | |
105 | if (index_partitions != 0) { | |
106 | AppendProperty(result, "# index partitions", index_partitions, prop_delim, | |
107 | kv_delim); | |
108 | AppendProperty(result, "top-level index size", top_level_index_size, prop_delim, | |
109 | kv_delim); | |
110 | } | |
7c673cae FG |
111 | AppendProperty(result, "filter block size", filter_size, prop_delim, |
112 | kv_delim); | |
113 | AppendProperty(result, "(estimated) table size", | |
114 | data_size + index_size + filter_size, prop_delim, kv_delim); | |
115 | ||
116 | AppendProperty( | |
117 | result, "filter policy name", | |
118 | filter_policy_name.empty() ? std::string("N/A") : filter_policy_name, | |
119 | prop_delim, kv_delim); | |
120 | ||
11fdf7f2 TL |
121 | AppendProperty(result, "prefix extractor name", |
122 | prefix_extractor_name.empty() ? std::string("N/A") | |
123 | : prefix_extractor_name, | |
124 | prop_delim, kv_delim); | |
125 | ||
7c673cae FG |
126 | AppendProperty(result, "column family ID", |
127 | column_family_id == rocksdb::TablePropertiesCollectorFactory:: | |
128 | Context::kUnknownColumnFamily | |
129 | ? std::string("N/A") | |
130 | : rocksdb::ToString(column_family_id), | |
131 | prop_delim, kv_delim); | |
132 | AppendProperty( | |
133 | result, "column family name", | |
134 | column_family_name.empty() ? std::string("N/A") : column_family_name, | |
135 | prop_delim, kv_delim); | |
136 | ||
137 | AppendProperty(result, "comparator name", | |
138 | comparator_name.empty() ? std::string("N/A") : comparator_name, | |
139 | prop_delim, kv_delim); | |
140 | ||
141 | AppendProperty( | |
142 | result, "merge operator name", | |
143 | merge_operator_name.empty() ? std::string("N/A") : merge_operator_name, | |
144 | prop_delim, kv_delim); | |
145 | ||
146 | AppendProperty(result, "property collectors names", | |
147 | property_collectors_names.empty() ? std::string("N/A") | |
148 | : property_collectors_names, | |
149 | prop_delim, kv_delim); | |
150 | ||
151 | AppendProperty( | |
152 | result, "SST file compression algo", | |
153 | compression_name.empty() ? std::string("N/A") : compression_name, | |
154 | prop_delim, kv_delim); | |
155 | ||
494da23a TL |
156 | AppendProperty( |
157 | result, "SST file compression options", | |
158 | compression_options.empty() ? std::string("N/A") : compression_options, | |
159 | prop_delim, kv_delim); | |
160 | ||
11fdf7f2 TL |
161 | AppendProperty(result, "creation time", creation_time, prop_delim, kv_delim); |
162 | ||
163 | AppendProperty(result, "time stamp of earliest key", oldest_key_time, | |
164 | prop_delim, kv_delim); | |
165 | ||
7c673cae FG |
166 | return result; |
167 | } | |
168 | ||
169 | void TableProperties::Add(const TableProperties& tp) { | |
170 | data_size += tp.data_size; | |
171 | index_size += tp.index_size; | |
11fdf7f2 TL |
172 | index_partitions += tp.index_partitions; |
173 | top_level_index_size += tp.top_level_index_size; | |
174 | index_key_is_user_key += tp.index_key_is_user_key; | |
175 | index_value_is_delta_encoded += tp.index_value_is_delta_encoded; | |
7c673cae FG |
176 | filter_size += tp.filter_size; |
177 | raw_key_size += tp.raw_key_size; | |
178 | raw_value_size += tp.raw_value_size; | |
179 | num_data_blocks += tp.num_data_blocks; | |
180 | num_entries += tp.num_entries; | |
494da23a TL |
181 | num_deletions += tp.num_deletions; |
182 | num_merge_operands += tp.num_merge_operands; | |
11fdf7f2 | 183 | num_range_deletions += tp.num_range_deletions; |
7c673cae FG |
184 | } |
185 | ||
186 | const std::string TablePropertiesNames::kDataSize = | |
187 | "rocksdb.data.size"; | |
188 | const std::string TablePropertiesNames::kIndexSize = | |
189 | "rocksdb.index.size"; | |
11fdf7f2 TL |
190 | const std::string TablePropertiesNames::kIndexPartitions = |
191 | "rocksdb.index.partitions"; | |
192 | const std::string TablePropertiesNames::kTopLevelIndexSize = | |
193 | "rocksdb.top-level.index.size"; | |
194 | const std::string TablePropertiesNames::kIndexKeyIsUserKey = | |
195 | "rocksdb.index.key.is.user.key"; | |
196 | const std::string TablePropertiesNames::kIndexValueIsDeltaEncoded = | |
197 | "rocksdb.index.value.is.delta.encoded"; | |
7c673cae FG |
198 | const std::string TablePropertiesNames::kFilterSize = |
199 | "rocksdb.filter.size"; | |
200 | const std::string TablePropertiesNames::kRawKeySize = | |
201 | "rocksdb.raw.key.size"; | |
202 | const std::string TablePropertiesNames::kRawValueSize = | |
203 | "rocksdb.raw.value.size"; | |
204 | const std::string TablePropertiesNames::kNumDataBlocks = | |
205 | "rocksdb.num.data.blocks"; | |
206 | const std::string TablePropertiesNames::kNumEntries = | |
207 | "rocksdb.num.entries"; | |
494da23a TL |
208 | const std::string TablePropertiesNames::kDeletedKeys = "rocksdb.deleted.keys"; |
209 | const std::string TablePropertiesNames::kMergeOperands = | |
210 | "rocksdb.merge.operands"; | |
11fdf7f2 TL |
211 | const std::string TablePropertiesNames::kNumRangeDeletions = |
212 | "rocksdb.num.range-deletions"; | |
7c673cae FG |
213 | const std::string TablePropertiesNames::kFilterPolicy = |
214 | "rocksdb.filter.policy"; | |
215 | const std::string TablePropertiesNames::kFormatVersion = | |
216 | "rocksdb.format.version"; | |
217 | const std::string TablePropertiesNames::kFixedKeyLen = | |
218 | "rocksdb.fixed.key.length"; | |
219 | const std::string TablePropertiesNames::kColumnFamilyId = | |
220 | "rocksdb.column.family.id"; | |
221 | const std::string TablePropertiesNames::kColumnFamilyName = | |
222 | "rocksdb.column.family.name"; | |
223 | const std::string TablePropertiesNames::kComparator = "rocksdb.comparator"; | |
224 | const std::string TablePropertiesNames::kMergeOperator = | |
225 | "rocksdb.merge.operator"; | |
226 | const std::string TablePropertiesNames::kPrefixExtractorName = | |
227 | "rocksdb.prefix.extractor.name"; | |
228 | const std::string TablePropertiesNames::kPropertyCollectors = | |
229 | "rocksdb.property.collectors"; | |
230 | const std::string TablePropertiesNames::kCompression = "rocksdb.compression"; | |
494da23a TL |
231 | const std::string TablePropertiesNames::kCompressionOptions = |
232 | "rocksdb.compression_options"; | |
11fdf7f2 TL |
233 | const std::string TablePropertiesNames::kCreationTime = "rocksdb.creation.time"; |
234 | const std::string TablePropertiesNames::kOldestKeyTime = | |
235 | "rocksdb.oldest.key.time"; | |
7c673cae FG |
236 | |
237 | extern const std::string kPropertiesBlock = "rocksdb.properties"; | |
238 | // Old property block name for backward compatibility | |
239 | extern const std::string kPropertiesBlockOldName = "rocksdb.stats"; | |
240 | extern const std::string kCompressionDictBlock = "rocksdb.compression_dict"; | |
241 | extern const std::string kRangeDelBlock = "rocksdb.range_del"; | |
242 | ||
243 | // Seek to the properties block. | |
244 | // Return true if it successfully seeks to the properties block. | |
245 | Status SeekToPropertiesBlock(InternalIterator* meta_iter, bool* is_found) { | |
246 | Status status = SeekToMetaBlock(meta_iter, kPropertiesBlock, is_found); | |
247 | if (!*is_found && status.ok()) { | |
248 | status = SeekToMetaBlock(meta_iter, kPropertiesBlockOldName, is_found); | |
249 | } | |
250 | return status; | |
251 | } | |
252 | ||
253 | // Seek to the compression dictionary block. | |
254 | // Return true if it successfully seeks to that block. | |
11fdf7f2 TL |
255 | Status SeekToCompressionDictBlock(InternalIterator* meta_iter, bool* is_found, |
256 | BlockHandle* block_handle) { | |
257 | return SeekToMetaBlock(meta_iter, kCompressionDictBlock, is_found, block_handle); | |
7c673cae FG |
258 | } |
259 | ||
260 | Status SeekToRangeDelBlock(InternalIterator* meta_iter, bool* is_found, | |
261 | BlockHandle* block_handle = nullptr) { | |
262 | return SeekToMetaBlock(meta_iter, kRangeDelBlock, is_found, block_handle); | |
263 | } | |
264 | ||
265 | } // namespace rocksdb |