/src/rocksdb/options/cf_options.h
Line | Count | Source |
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 | | #pragma once |
7 | | |
8 | | #include <string> |
9 | | #include <vector> |
10 | | |
11 | | #include "db/dbformat.h" |
12 | | #include "options/db_options.h" |
13 | | #include "rocksdb/options.h" |
14 | | #include "util/compression.h" |
15 | | |
16 | | namespace ROCKSDB_NAMESPACE { |
17 | | |
18 | | // ImmutableCFOptions is a data struct used by RocksDB internal. It contains a |
19 | | // subset of Options that should not be changed during the entire lifetime |
20 | | // of DB. Raw pointers defined in this struct do not have ownership to the data |
21 | | // they point to. Options contains std::shared_ptr to these data. |
22 | | struct ImmutableCFOptions { |
23 | | public: |
24 | 248k | static const char* kName() { return "ImmutableCFOptions"; } |
25 | | explicit ImmutableCFOptions(); |
26 | | explicit ImmutableCFOptions(const ColumnFamilyOptions& cf_options); |
27 | | |
28 | | CompactionStyle compaction_style; |
29 | | |
30 | | CompactionPri compaction_pri; |
31 | | |
32 | | const Comparator* user_comparator; |
33 | | InternalKeyComparator internal_comparator; // Only in Immutable |
34 | | |
35 | | std::shared_ptr<MergeOperator> merge_operator; |
36 | | |
37 | | const CompactionFilter* compaction_filter; |
38 | | |
39 | | std::shared_ptr<CompactionFilterFactory> compaction_filter_factory; |
40 | | |
41 | | int min_write_buffer_number_to_merge; |
42 | | |
43 | | int64_t max_write_buffer_size_to_maintain; |
44 | | |
45 | | bool inplace_update_support; |
46 | | |
47 | | UpdateStatus (*inplace_callback)(char* existing_value, |
48 | | uint32_t* existing_value_size, |
49 | | Slice delta_value, |
50 | | std::string* merged_value); |
51 | | |
52 | | std::shared_ptr<MemTableRepFactory> memtable_factory; |
53 | | |
54 | | Options::TablePropertiesCollectorFactories |
55 | | table_properties_collector_factories; |
56 | | |
57 | | // This options is required by PlainTableReader. May need to move it |
58 | | // to PlainTableOptions just like bloom_bits_per_key |
59 | | uint32_t bloom_locality; |
60 | | |
61 | | bool level_compaction_dynamic_level_bytes; |
62 | | |
63 | | int num_levels; |
64 | | |
65 | | bool optimize_filters_for_hits; |
66 | | |
67 | | bool force_consistency_checks; |
68 | | |
69 | | bool disallow_memtable_writes; |
70 | | |
71 | | Temperature default_temperature; |
72 | | |
73 | | std::shared_ptr<const SliceTransform> |
74 | | memtable_insert_with_hint_prefix_extractor; |
75 | | |
76 | | std::vector<DbPath> cf_paths; |
77 | | |
78 | | std::shared_ptr<ConcurrentTaskLimiter> compaction_thread_limiter; |
79 | | |
80 | | std::shared_ptr<SstPartitionerFactory> sst_partitioner_factory; |
81 | | |
82 | | std::shared_ptr<Cache> blob_cache; |
83 | | |
84 | | bool persist_user_defined_timestamps; |
85 | | |
86 | | bool cf_allow_ingest_behind; |
87 | | }; |
88 | | |
89 | | struct ImmutableOptions : public ImmutableDBOptions, public ImmutableCFOptions { |
90 | | explicit ImmutableOptions(); |
91 | | explicit ImmutableOptions(const Options& options); |
92 | | |
93 | | ImmutableOptions(const DBOptions& db_options, |
94 | | const ColumnFamilyOptions& cf_options); |
95 | | |
96 | | ImmutableOptions(const ImmutableDBOptions& db_options, |
97 | | const ImmutableCFOptions& cf_options); |
98 | | |
99 | | ImmutableOptions(const DBOptions& db_options, |
100 | | const ImmutableCFOptions& cf_options); |
101 | | |
102 | | ImmutableOptions(const ImmutableDBOptions& db_options, |
103 | | const ColumnFamilyOptions& cf_options); |
104 | | }; |
105 | | |
106 | | struct MutableCFOptions { |
107 | 248k | static const char* kName() { return "MutableCFOptions"; } |
108 | | explicit MutableCFOptions(const ColumnFamilyOptions& options) |
109 | 311k | : write_buffer_size(options.write_buffer_size), |
110 | 311k | max_write_buffer_number(options.max_write_buffer_number), |
111 | 311k | arena_block_size(options.arena_block_size), |
112 | | memtable_prefix_bloom_size_ratio( |
113 | 311k | options.memtable_prefix_bloom_size_ratio), |
114 | 311k | memtable_whole_key_filtering(options.memtable_whole_key_filtering), |
115 | 311k | memtable_huge_page_size(options.memtable_huge_page_size), |
116 | 311k | max_successive_merges(options.max_successive_merges), |
117 | 311k | strict_max_successive_merges(options.strict_max_successive_merges), |
118 | 311k | inplace_update_num_locks(options.inplace_update_num_locks), |
119 | 311k | prefix_extractor(options.prefix_extractor), |
120 | | experimental_mempurge_threshold( |
121 | 311k | options.experimental_mempurge_threshold), |
122 | 311k | disable_auto_compactions(options.disable_auto_compactions), |
123 | 311k | table_factory(options.table_factory), |
124 | | soft_pending_compaction_bytes_limit( |
125 | 311k | options.soft_pending_compaction_bytes_limit), |
126 | | hard_pending_compaction_bytes_limit( |
127 | 311k | options.hard_pending_compaction_bytes_limit), |
128 | | level0_file_num_compaction_trigger( |
129 | 311k | options.level0_file_num_compaction_trigger), |
130 | 311k | level0_slowdown_writes_trigger(options.level0_slowdown_writes_trigger), |
131 | 311k | level0_stop_writes_trigger(options.level0_stop_writes_trigger), |
132 | 311k | max_compaction_bytes(options.max_compaction_bytes), |
133 | 311k | target_file_size_base(options.target_file_size_base), |
134 | 311k | target_file_size_multiplier(options.target_file_size_multiplier), |
135 | | target_file_size_is_upper_bound( |
136 | 311k | options.target_file_size_is_upper_bound), |
137 | 311k | max_bytes_for_level_base(options.max_bytes_for_level_base), |
138 | 311k | max_bytes_for_level_multiplier(options.max_bytes_for_level_multiplier), |
139 | 311k | ttl(options.ttl), |
140 | 311k | periodic_compaction_seconds(options.periodic_compaction_seconds), |
141 | 311k | max_bytes_for_level_multiplier_additional( |
142 | 311k | options.max_bytes_for_level_multiplier_additional), |
143 | 311k | compaction_options_fifo(options.compaction_options_fifo), |
144 | 311k | compaction_options_universal(options.compaction_options_universal), |
145 | | preclude_last_level_data_seconds( |
146 | 311k | options.preclude_last_level_data_seconds), |
147 | 311k | preserve_internal_time_seconds(options.preserve_internal_time_seconds), |
148 | 311k | verify_output_flags(options.verify_output_flags), |
149 | 311k | enable_blob_files(options.enable_blob_files), |
150 | 311k | min_blob_size(options.min_blob_size), |
151 | 311k | blob_file_size(options.blob_file_size), |
152 | 311k | blob_compression_type(options.blob_compression_type), |
153 | 311k | enable_blob_garbage_collection(options.enable_blob_garbage_collection), |
154 | | blob_garbage_collection_age_cutoff( |
155 | 311k | options.blob_garbage_collection_age_cutoff), |
156 | | blob_garbage_collection_force_threshold( |
157 | 311k | options.blob_garbage_collection_force_threshold), |
158 | 311k | blob_compaction_readahead_size(options.blob_compaction_readahead_size), |
159 | 311k | blob_file_starting_level(options.blob_file_starting_level), |
160 | 311k | prepopulate_blob_cache(options.prepopulate_blob_cache), |
161 | | max_sequential_skip_in_iterations( |
162 | 311k | options.max_sequential_skip_in_iterations), |
163 | 311k | paranoid_file_checks(options.paranoid_file_checks), |
164 | 311k | report_bg_io_stats(options.report_bg_io_stats), |
165 | 311k | compression(options.compression), |
166 | 311k | bottommost_compression(options.bottommost_compression), |
167 | 311k | compression_opts(options.compression_opts), |
168 | 311k | bottommost_compression_opts(options.bottommost_compression_opts), |
169 | 311k | compression_manager(options.compression_manager), |
170 | 311k | last_level_temperature(options.last_level_temperature), |
171 | 311k | default_write_temperature(options.default_write_temperature), |
172 | | memtable_protection_bytes_per_key( |
173 | 311k | options.memtable_protection_bytes_per_key), |
174 | 311k | block_protection_bytes_per_key(options.block_protection_bytes_per_key), |
175 | 311k | paranoid_memory_checks(options.paranoid_memory_checks), |
176 | | memtable_veirfy_per_key_checksum_on_seek( |
177 | 311k | options.memtable_veirfy_per_key_checksum_on_seek), |
178 | | sample_for_compression( |
179 | 311k | options.sample_for_compression), // TODO: is 0 fine here? |
180 | 311k | compression_per_level(options.compression_per_level), |
181 | 311k | memtable_max_range_deletions(options.memtable_max_range_deletions), |
182 | | bottommost_file_compaction_delay( |
183 | 311k | options.bottommost_file_compaction_delay), |
184 | 311k | uncache_aggressiveness(options.uncache_aggressiveness), |
185 | 311k | memtable_op_scan_flush_trigger(options.memtable_op_scan_flush_trigger), |
186 | | memtable_avg_op_scan_flush_trigger( |
187 | 311k | options.memtable_avg_op_scan_flush_trigger) { |
188 | 311k | RefreshDerivedOptions(options.num_levels, options.compaction_style); |
189 | 311k | } |
190 | | |
191 | | MutableCFOptions() |
192 | 336k | : write_buffer_size(0), |
193 | 336k | max_write_buffer_number(0), |
194 | 336k | arena_block_size(0), |
195 | 336k | memtable_prefix_bloom_size_ratio(0), |
196 | 336k | memtable_whole_key_filtering(false), |
197 | 336k | memtable_huge_page_size(0), |
198 | 336k | max_successive_merges(0), |
199 | 336k | strict_max_successive_merges(false), |
200 | 336k | inplace_update_num_locks(0), |
201 | 336k | prefix_extractor(nullptr), |
202 | 336k | experimental_mempurge_threshold(0.0), |
203 | 336k | disable_auto_compactions(false), |
204 | 336k | soft_pending_compaction_bytes_limit(0), |
205 | 336k | hard_pending_compaction_bytes_limit(0), |
206 | 336k | level0_file_num_compaction_trigger(0), |
207 | 336k | level0_slowdown_writes_trigger(0), |
208 | 336k | level0_stop_writes_trigger(0), |
209 | 336k | max_compaction_bytes(0), |
210 | 336k | target_file_size_base(0), |
211 | 336k | target_file_size_multiplier(0), |
212 | 336k | target_file_size_is_upper_bound(false), |
213 | 336k | max_bytes_for_level_base(0), |
214 | 336k | max_bytes_for_level_multiplier(0), |
215 | 336k | ttl(0), |
216 | 336k | periodic_compaction_seconds(0), |
217 | 336k | compaction_options_fifo(), |
218 | 336k | preclude_last_level_data_seconds(0), |
219 | 336k | preserve_internal_time_seconds(0), |
220 | 336k | verify_output_flags(VerifyOutputFlags::kVerifyNone), |
221 | 336k | enable_blob_files(false), |
222 | 336k | min_blob_size(0), |
223 | 336k | blob_file_size(0), |
224 | 336k | blob_compression_type(kNoCompression), |
225 | 336k | enable_blob_garbage_collection(false), |
226 | 336k | blob_garbage_collection_age_cutoff(0.0), |
227 | 336k | blob_garbage_collection_force_threshold(0.0), |
228 | 336k | blob_compaction_readahead_size(0), |
229 | 336k | blob_file_starting_level(0), |
230 | 336k | prepopulate_blob_cache(PrepopulateBlobCache::kDisable), |
231 | 336k | max_sequential_skip_in_iterations(0), |
232 | 336k | paranoid_file_checks(false), |
233 | 336k | report_bg_io_stats(false), |
234 | 336k | compression(Snappy_Supported() ? kSnappyCompression : kNoCompression), |
235 | 336k | bottommost_compression(kDisableCompressionOption), |
236 | 336k | last_level_temperature(Temperature::kUnknown), |
237 | 336k | default_write_temperature(Temperature::kUnknown), |
238 | 336k | memtable_protection_bytes_per_key(0), |
239 | 336k | block_protection_bytes_per_key(0), |
240 | 336k | paranoid_memory_checks(false), |
241 | 336k | memtable_veirfy_per_key_checksum_on_seek(false), |
242 | 336k | sample_for_compression(0), |
243 | 336k | memtable_max_range_deletions(0), |
244 | 336k | bottommost_file_compaction_delay(0), |
245 | 336k | uncache_aggressiveness(0), |
246 | 336k | memtable_op_scan_flush_trigger(0), |
247 | 336k | memtable_avg_op_scan_flush_trigger(0) {} |
248 | | |
249 | | explicit MutableCFOptions(const Options& options); |
250 | | |
251 | | // Must be called after any change to MutableCFOptions |
252 | | void RefreshDerivedOptions(int num_levels, CompactionStyle compaction_style); |
253 | | |
254 | 0 | void RefreshDerivedOptions(const ImmutableCFOptions& ioptions) { |
255 | 0 | RefreshDerivedOptions(ioptions.num_levels, ioptions.compaction_style); |
256 | 0 | } |
257 | | |
258 | 0 | int MaxBytesMultiplerAdditional(int level) const { |
259 | 0 | if (level >= |
260 | 0 | static_cast<int>(max_bytes_for_level_multiplier_additional.size())) { |
261 | 0 | return 1; |
262 | 0 | } |
263 | 0 | return max_bytes_for_level_multiplier_additional[level]; |
264 | 0 | } |
265 | | |
266 | | void Dump(Logger* log) const; |
267 | | |
268 | | bool operator==(const MutableCFOptions& rhs) const = default; |
269 | | |
270 | | // Memtable related options |
271 | | size_t write_buffer_size; |
272 | | int max_write_buffer_number; |
273 | | size_t arena_block_size; |
274 | | double memtable_prefix_bloom_size_ratio; |
275 | | bool memtable_whole_key_filtering; |
276 | | size_t memtable_huge_page_size; |
277 | | size_t max_successive_merges; |
278 | | bool strict_max_successive_merges; |
279 | | size_t inplace_update_num_locks; |
280 | | // NOTE: if too many shared_ptr make their way into MutableCFOptions, the |
281 | | // copy performance might suffer enough to warrant aggregating them in an |
282 | | // immutable+copy-on-write sub-object managed through a single shared_ptr. |
283 | | std::shared_ptr<const SliceTransform> prefix_extractor; |
284 | | // [experimental] |
285 | | // Used to activate or deactive the Mempurge feature (memtable garbage |
286 | | // collection). (deactivated by default). At every flush, the total useful |
287 | | // payload (total entries minus garbage entries) is estimated as a ratio |
288 | | // [useful payload bytes]/[size of a memtable (in bytes)]. This ratio is then |
289 | | // compared to this `threshold` value: |
290 | | // - if ratio<threshold: the flush is replaced by a mempurge operation |
291 | | // - else: a regular flush operation takes place. |
292 | | // Threshold values: |
293 | | // 0.0: mempurge deactivated (default). |
294 | | // 1.0: recommended threshold value. |
295 | | // >1.0 : aggressive mempurge. |
296 | | // 0 < threshold < 1.0: mempurge triggered only for very low useful payload |
297 | | // ratios. |
298 | | // [experimental] |
299 | | double experimental_mempurge_threshold; |
300 | | |
301 | | // Compaction related options |
302 | | bool disable_auto_compactions; |
303 | | std::shared_ptr<TableFactory> table_factory; |
304 | | uint64_t soft_pending_compaction_bytes_limit; |
305 | | uint64_t hard_pending_compaction_bytes_limit; |
306 | | int level0_file_num_compaction_trigger; |
307 | | int level0_slowdown_writes_trigger; |
308 | | int level0_stop_writes_trigger; |
309 | | uint64_t max_compaction_bytes; |
310 | | uint64_t target_file_size_base; |
311 | | int target_file_size_multiplier; |
312 | | bool target_file_size_is_upper_bound; |
313 | | uint64_t max_bytes_for_level_base; |
314 | | double max_bytes_for_level_multiplier; |
315 | | uint64_t ttl; |
316 | | uint64_t periodic_compaction_seconds; |
317 | | std::vector<int> max_bytes_for_level_multiplier_additional; |
318 | | CompactionOptionsFIFO compaction_options_fifo; |
319 | | CompactionOptionsUniversal compaction_options_universal; |
320 | | uint64_t preclude_last_level_data_seconds; |
321 | | uint64_t preserve_internal_time_seconds; |
322 | | VerifyOutputFlags verify_output_flags; |
323 | | |
324 | | // Blob file related options |
325 | | bool enable_blob_files; |
326 | | uint64_t min_blob_size; |
327 | | uint64_t blob_file_size; |
328 | | CompressionType blob_compression_type; |
329 | | bool enable_blob_garbage_collection; |
330 | | double blob_garbage_collection_age_cutoff; |
331 | | double blob_garbage_collection_force_threshold; |
332 | | uint64_t blob_compaction_readahead_size; |
333 | | int blob_file_starting_level; |
334 | | PrepopulateBlobCache prepopulate_blob_cache; |
335 | | |
336 | | // Misc options |
337 | | uint64_t max_sequential_skip_in_iterations; |
338 | | bool paranoid_file_checks; |
339 | | bool report_bg_io_stats; |
340 | | CompressionType compression; |
341 | | CompressionType bottommost_compression; |
342 | | CompressionOptions compression_opts; |
343 | | CompressionOptions bottommost_compression_opts; |
344 | | std::shared_ptr<CompressionManager> compression_manager; |
345 | | Temperature last_level_temperature; |
346 | | Temperature default_write_temperature; |
347 | | uint32_t memtable_protection_bytes_per_key; |
348 | | uint8_t block_protection_bytes_per_key; |
349 | | bool paranoid_memory_checks; |
350 | | bool memtable_veirfy_per_key_checksum_on_seek; |
351 | | |
352 | | uint64_t sample_for_compression; |
353 | | std::vector<CompressionType> compression_per_level; |
354 | | uint32_t memtable_max_range_deletions; |
355 | | uint32_t bottommost_file_compaction_delay; |
356 | | uint32_t uncache_aggressiveness; |
357 | | uint32_t memtable_op_scan_flush_trigger; |
358 | | uint32_t memtable_avg_op_scan_flush_trigger; |
359 | | |
360 | | // Derived options |
361 | | // Per-level target file size. |
362 | | std::vector<uint64_t> max_file_size; |
363 | | }; |
364 | | |
365 | | uint64_t MultiplyCheckOverflow(uint64_t op1, double op2); |
366 | | |
367 | | // Get the max file size in a given level. |
368 | | uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options, int level, |
369 | | CompactionStyle compaction_style, |
370 | | int base_level = 1, |
371 | | bool level_compaction_dynamic_level_bytes = false); |
372 | | |
373 | | // Get the max size of an L0 file for which we will pin its meta-blocks when |
374 | | // `pin_l0_filter_and_index_blocks_in_cache` is set. |
375 | | size_t MaxFileSizeForL0MetaPin(const MutableCFOptions& cf_options); |
376 | | |
377 | | Status GetStringFromMutableCFOptions(const ConfigOptions& config_options, |
378 | | const MutableCFOptions& mutable_opts, |
379 | | std::string* opt_string); |
380 | | |
381 | | Status GetMutableOptionsFromStrings( |
382 | | const MutableCFOptions& base_options, |
383 | | const std::unordered_map<std::string, std::string>& options_map, |
384 | | Logger* info_log, MutableCFOptions* new_options); |
385 | | |
386 | | #ifndef NDEBUG |
387 | | std::vector<std::string> TEST_GetImmutableInMutableCFOptions(); |
388 | | extern bool TEST_allowSetOptionsImmutableInMutable; |
389 | | #endif |
390 | | |
391 | | } // namespace ROCKSDB_NAMESPACE |