]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/options/cf_options.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / options / cf_options.cc
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 #include "options/cf_options.h"
7
8 #ifndef __STDC_FORMAT_MACROS
9 #define __STDC_FORMAT_MACROS
10 #endif
11
12 #include <inttypes.h>
13 #include <cassert>
14 #include <limits>
15 #include <string>
16 #include "options/db_options.h"
17 #include "port/port.h"
18 #include "rocksdb/env.h"
19 #include "rocksdb/options.h"
20 #include "rocksdb/concurrent_task_limiter.h"
21
22 namespace rocksdb {
23
24 ImmutableCFOptions::ImmutableCFOptions(const Options& options)
25 : ImmutableCFOptions(ImmutableDBOptions(options), options) {}
26
27 ImmutableCFOptions::ImmutableCFOptions(const ImmutableDBOptions& db_options,
28 const ColumnFamilyOptions& cf_options)
29 : compaction_style(cf_options.compaction_style),
30 compaction_pri(cf_options.compaction_pri),
31 user_comparator(cf_options.comparator),
32 internal_comparator(InternalKeyComparator(cf_options.comparator)),
33 merge_operator(cf_options.merge_operator.get()),
34 compaction_filter(cf_options.compaction_filter),
35 compaction_filter_factory(cf_options.compaction_filter_factory.get()),
36 min_write_buffer_number_to_merge(
37 cf_options.min_write_buffer_number_to_merge),
38 max_write_buffer_number_to_maintain(
39 cf_options.max_write_buffer_number_to_maintain),
40 inplace_update_support(cf_options.inplace_update_support),
41 inplace_callback(cf_options.inplace_callback),
42 info_log(db_options.info_log.get()),
43 statistics(db_options.statistics.get()),
44 rate_limiter(db_options.rate_limiter.get()),
45 info_log_level(db_options.info_log_level),
46 env(db_options.env),
47 allow_mmap_reads(db_options.allow_mmap_reads),
48 allow_mmap_writes(db_options.allow_mmap_writes),
49 db_paths(db_options.db_paths),
50 memtable_factory(cf_options.memtable_factory.get()),
51 table_factory(cf_options.table_factory.get()),
52 table_properties_collector_factories(
53 cf_options.table_properties_collector_factories),
54 advise_random_on_open(db_options.advise_random_on_open),
55 bloom_locality(cf_options.bloom_locality),
56 purge_redundant_kvs_while_flush(
57 cf_options.purge_redundant_kvs_while_flush),
58 use_fsync(db_options.use_fsync),
59 compression_per_level(cf_options.compression_per_level),
60 bottommost_compression(cf_options.bottommost_compression),
61 bottommost_compression_opts(cf_options.bottommost_compression_opts),
62 compression_opts(cf_options.compression_opts),
63 level_compaction_dynamic_level_bytes(
64 cf_options.level_compaction_dynamic_level_bytes),
65 access_hint_on_compaction_start(
66 db_options.access_hint_on_compaction_start),
67 new_table_reader_for_compaction_inputs(
68 db_options.new_table_reader_for_compaction_inputs),
69 num_levels(cf_options.num_levels),
70 optimize_filters_for_hits(cf_options.optimize_filters_for_hits),
71 force_consistency_checks(cf_options.force_consistency_checks),
72 allow_ingest_behind(db_options.allow_ingest_behind),
73 preserve_deletes(db_options.preserve_deletes),
74 listeners(db_options.listeners),
75 row_cache(db_options.row_cache),
76 max_subcompactions(db_options.max_subcompactions),
77 memtable_insert_with_hint_prefix_extractor(
78 cf_options.memtable_insert_with_hint_prefix_extractor.get()),
79 cf_paths(cf_options.cf_paths),
80 compaction_thread_limiter(cf_options.compaction_thread_limiter) {}
81
82 // Multiple two operands. If they overflow, return op1.
83 uint64_t MultiplyCheckOverflow(uint64_t op1, double op2) {
84 if (op1 == 0 || op2 <= 0) {
85 return 0;
86 }
87 if (port::kMaxUint64 / op1 < op2) {
88 return op1;
89 }
90 return static_cast<uint64_t>(op1 * op2);
91 }
92
93 // when level_compaction_dynamic_level_bytes is true and leveled compaction
94 // is used, the base level is not always L1, so precomupted max_file_size can
95 // no longer be used. Recompute file_size_for_level from base level.
96 uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options,
97 int level, CompactionStyle compaction_style, int base_level,
98 bool level_compaction_dynamic_level_bytes) {
99 if (!level_compaction_dynamic_level_bytes || level < base_level ||
100 compaction_style != kCompactionStyleLevel) {
101 assert(level >= 0);
102 assert(level < (int)cf_options.max_file_size.size());
103 return cf_options.max_file_size[level];
104 } else {
105 assert(level >= 0 && base_level >= 0);
106 assert(level - base_level < (int)cf_options.max_file_size.size());
107 return cf_options.max_file_size[level - base_level];
108 }
109 }
110
111 void MutableCFOptions::RefreshDerivedOptions(int num_levels,
112 CompactionStyle compaction_style) {
113 max_file_size.resize(num_levels);
114 for (int i = 0; i < num_levels; ++i) {
115 if (i == 0 && compaction_style == kCompactionStyleUniversal) {
116 max_file_size[i] = ULLONG_MAX;
117 } else if (i > 1) {
118 max_file_size[i] = MultiplyCheckOverflow(max_file_size[i - 1],
119 target_file_size_multiplier);
120 } else {
121 max_file_size[i] = target_file_size_base;
122 }
123 }
124 }
125
126 void MutableCFOptions::Dump(Logger* log) const {
127 // Memtable related options
128 ROCKS_LOG_INFO(log,
129 " write_buffer_size: %" ROCKSDB_PRIszt,
130 write_buffer_size);
131 ROCKS_LOG_INFO(log, " max_write_buffer_number: %d",
132 max_write_buffer_number);
133 ROCKS_LOG_INFO(log,
134 " arena_block_size: %" ROCKSDB_PRIszt,
135 arena_block_size);
136 ROCKS_LOG_INFO(log, " memtable_prefix_bloom_ratio: %f",
137 memtable_prefix_bloom_size_ratio);
138 ROCKS_LOG_INFO(log, " memtable_whole_key_filtering: %d",
139 memtable_whole_key_filtering);
140 ROCKS_LOG_INFO(log,
141 " memtable_huge_page_size: %" ROCKSDB_PRIszt,
142 memtable_huge_page_size);
143 ROCKS_LOG_INFO(log,
144 " max_successive_merges: %" ROCKSDB_PRIszt,
145 max_successive_merges);
146 ROCKS_LOG_INFO(log,
147 " inplace_update_num_locks: %" ROCKSDB_PRIszt,
148 inplace_update_num_locks);
149 ROCKS_LOG_INFO(
150 log, " prefix_extractor: %s",
151 prefix_extractor == nullptr ? "nullptr" : prefix_extractor->Name());
152 ROCKS_LOG_INFO(log, " disable_auto_compactions: %d",
153 disable_auto_compactions);
154 ROCKS_LOG_INFO(log, " soft_pending_compaction_bytes_limit: %" PRIu64,
155 soft_pending_compaction_bytes_limit);
156 ROCKS_LOG_INFO(log, " hard_pending_compaction_bytes_limit: %" PRIu64,
157 hard_pending_compaction_bytes_limit);
158 ROCKS_LOG_INFO(log, " level0_file_num_compaction_trigger: %d",
159 level0_file_num_compaction_trigger);
160 ROCKS_LOG_INFO(log, " level0_slowdown_writes_trigger: %d",
161 level0_slowdown_writes_trigger);
162 ROCKS_LOG_INFO(log, " level0_stop_writes_trigger: %d",
163 level0_stop_writes_trigger);
164 ROCKS_LOG_INFO(log, " max_compaction_bytes: %" PRIu64,
165 max_compaction_bytes);
166 ROCKS_LOG_INFO(log, " target_file_size_base: %" PRIu64,
167 target_file_size_base);
168 ROCKS_LOG_INFO(log, " target_file_size_multiplier: %d",
169 target_file_size_multiplier);
170 ROCKS_LOG_INFO(log, " max_bytes_for_level_base: %" PRIu64,
171 max_bytes_for_level_base);
172 ROCKS_LOG_INFO(log, " max_bytes_for_level_multiplier: %f",
173 max_bytes_for_level_multiplier);
174 ROCKS_LOG_INFO(log, " ttl: %" PRIu64,
175 ttl);
176 std::string result;
177 char buf[10];
178 for (const auto m : max_bytes_for_level_multiplier_additional) {
179 snprintf(buf, sizeof(buf), "%d, ", m);
180 result += buf;
181 }
182 if (result.size() >= 2) {
183 result.resize(result.size() - 2);
184 } else {
185 result = "";
186 }
187
188 ROCKS_LOG_INFO(log, "max_bytes_for_level_multiplier_additional: %s",
189 result.c_str());
190 ROCKS_LOG_INFO(log, " max_sequential_skip_in_iterations: %" PRIu64,
191 max_sequential_skip_in_iterations);
192 ROCKS_LOG_INFO(log, " paranoid_file_checks: %d",
193 paranoid_file_checks);
194 ROCKS_LOG_INFO(log, " report_bg_io_stats: %d",
195 report_bg_io_stats);
196 ROCKS_LOG_INFO(log, " compression: %d",
197 static_cast<int>(compression));
198
199 // Universal Compaction Options
200 ROCKS_LOG_INFO(log, "compaction_options_universal.size_ratio : %d",
201 compaction_options_universal.size_ratio);
202 ROCKS_LOG_INFO(log, "compaction_options_universal.min_merge_width : %d",
203 compaction_options_universal.min_merge_width);
204 ROCKS_LOG_INFO(log, "compaction_options_universal.max_merge_width : %d",
205 compaction_options_universal.max_merge_width);
206 ROCKS_LOG_INFO(
207 log, "compaction_options_universal.max_size_amplification_percent : %d",
208 compaction_options_universal.max_size_amplification_percent);
209 ROCKS_LOG_INFO(log,
210 "compaction_options_universal.compression_size_percent : %d",
211 compaction_options_universal.compression_size_percent);
212 ROCKS_LOG_INFO(log, "compaction_options_universal.stop_style : %d",
213 compaction_options_universal.stop_style);
214 ROCKS_LOG_INFO(
215 log, "compaction_options_universal.allow_trivial_move : %d",
216 static_cast<int>(compaction_options_universal.allow_trivial_move));
217
218 // FIFO Compaction Options
219 ROCKS_LOG_INFO(log, "compaction_options_fifo.max_table_files_size : %" PRIu64,
220 compaction_options_fifo.max_table_files_size);
221 ROCKS_LOG_INFO(log, "compaction_options_fifo.allow_compaction : %d",
222 compaction_options_fifo.allow_compaction);
223 }
224
225 MutableCFOptions::MutableCFOptions(const Options& options)
226 : MutableCFOptions(ColumnFamilyOptions(options)) {}
227
228 } // namespace rocksdb