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).
6 #include "options/cf_options.h"
8 #ifndef __STDC_FORMAT_MACROS
9 #define __STDC_FORMAT_MACROS
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"
24 ImmutableCFOptions::ImmutableCFOptions(const Options
& options
)
25 : ImmutableCFOptions(ImmutableDBOptions(options
), options
) {}
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
),
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
) {}
82 // Multiple two operands. If they overflow, return op1.
83 uint64_t MultiplyCheckOverflow(uint64_t op1
, double op2
) {
84 if (op1
== 0 || op2
<= 0) {
87 if (port::kMaxUint64
/ op1
< op2
) {
90 return static_cast<uint64_t>(op1
* op2
);
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
) {
102 assert(level
< (int)cf_options
.max_file_size
.size());
103 return cf_options
.max_file_size
[level
];
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
];
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
;
118 max_file_size
[i
] = MultiplyCheckOverflow(max_file_size
[i
- 1],
119 target_file_size_multiplier
);
121 max_file_size
[i
] = target_file_size_base
;
126 void MutableCFOptions::Dump(Logger
* log
) const {
127 // Memtable related options
129 " write_buffer_size: %" ROCKSDB_PRIszt
,
131 ROCKS_LOG_INFO(log
, " max_write_buffer_number: %d",
132 max_write_buffer_number
);
134 " arena_block_size: %" ROCKSDB_PRIszt
,
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
);
141 " memtable_huge_page_size: %" ROCKSDB_PRIszt
,
142 memtable_huge_page_size
);
144 " max_successive_merges: %" ROCKSDB_PRIszt
,
145 max_successive_merges
);
147 " inplace_update_num_locks: %" ROCKSDB_PRIszt
,
148 inplace_update_num_locks
);
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
,
178 for (const auto m
: max_bytes_for_level_multiplier_additional
) {
179 snprintf(buf
, sizeof(buf
), "%d, ", m
);
182 if (result
.size() >= 2) {
183 result
.resize(result
.size() - 2);
188 ROCKS_LOG_INFO(log
, "max_bytes_for_level_multiplier_additional: %s",
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",
196 ROCKS_LOG_INFO(log
, " compression: %d",
197 static_cast<int>(compression
));
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
);
207 log
, "compaction_options_universal.max_size_amplification_percent : %d",
208 compaction_options_universal
.max_size_amplification_percent
);
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
);
215 log
, "compaction_options_universal.allow_trivial_move : %d",
216 static_cast<int>(compaction_options_universal
.allow_trivial_move
));
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
);
225 MutableCFOptions::MutableCFOptions(const Options
& options
)
226 : MutableCFOptions(ColumnFamilyOptions(options
)) {}
228 } // namespace rocksdb