1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
11 #include "db/dbformat.h"
12 #include "options/db_options.h"
13 #include "rocksdb/options.h"
14 #include "util/compression.h"
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 shared_ptr to these data.
22 struct ImmutableCFOptions
{
24 explicit ImmutableCFOptions(const Options
& options
);
26 ImmutableCFOptions(const ImmutableDBOptions
& db_options
,
27 const ColumnFamilyOptions
& cf_options
);
29 CompactionStyle compaction_style
;
31 CompactionPri compaction_pri
;
33 CompactionOptionsUniversal compaction_options_universal
;
34 CompactionOptionsFIFO compaction_options_fifo
;
36 const SliceTransform
* prefix_extractor
;
38 const Comparator
* user_comparator
;
39 InternalKeyComparator internal_comparator
;
41 MergeOperator
* merge_operator
;
43 const CompactionFilter
* compaction_filter
;
45 CompactionFilterFactory
* compaction_filter_factory
;
47 int min_write_buffer_number_to_merge
;
49 int max_write_buffer_number_to_maintain
;
51 bool inplace_update_support
;
53 UpdateStatus (*inplace_callback
)(char* existing_value
,
54 uint32_t* existing_value_size
,
56 std::string
* merged_value
);
60 Statistics
* statistics
;
62 InfoLogLevel info_log_level
;
66 // Allow the OS to mmap file for reading sst tables. Default: false
67 bool allow_mmap_reads
;
69 // Allow the OS to mmap file for writing. Default: false
70 bool allow_mmap_writes
;
72 std::vector
<DbPath
> db_paths
;
74 MemTableRepFactory
* memtable_factory
;
76 TableFactory
* table_factory
;
78 Options::TablePropertiesCollectorFactories
79 table_properties_collector_factories
;
81 bool advise_random_on_open
;
83 // This options is required by PlainTableReader. May need to move it
84 // to PlainTalbeOptions just like bloom_bits_per_key
85 uint32_t bloom_locality
;
87 bool purge_redundant_kvs_while_flush
;
91 std::vector
<CompressionType
> compression_per_level
;
93 CompressionType bottommost_compression
;
95 CompressionOptions compression_opts
;
97 bool level_compaction_dynamic_level_bytes
;
99 Options::AccessHint access_hint_on_compaction_start
;
101 bool new_table_reader_for_compaction_inputs
;
103 size_t compaction_readahead_size
;
107 bool optimize_filters_for_hits
;
109 bool force_consistency_checks
;
111 // A vector of EventListeners which call-back functions will be called
112 // when specific RocksDB event happens.
113 std::vector
<std::shared_ptr
<EventListener
>> listeners
;
115 std::shared_ptr
<Cache
> row_cache
;
117 uint32_t max_subcompactions
;
119 const SliceTransform
* memtable_insert_with_hint_prefix_extractor
;
122 struct MutableCFOptions
{
123 explicit MutableCFOptions(const ColumnFamilyOptions
& options
)
124 : write_buffer_size(options
.write_buffer_size
),
125 max_write_buffer_number(options
.max_write_buffer_number
),
126 arena_block_size(options
.arena_block_size
),
127 memtable_prefix_bloom_size_ratio(
128 options
.memtable_prefix_bloom_size_ratio
),
129 memtable_huge_page_size(options
.memtable_huge_page_size
),
130 max_successive_merges(options
.max_successive_merges
),
131 inplace_update_num_locks(options
.inplace_update_num_locks
),
132 disable_auto_compactions(options
.disable_auto_compactions
),
133 soft_pending_compaction_bytes_limit(
134 options
.soft_pending_compaction_bytes_limit
),
135 hard_pending_compaction_bytes_limit(
136 options
.hard_pending_compaction_bytes_limit
),
137 level0_file_num_compaction_trigger(
138 options
.level0_file_num_compaction_trigger
),
139 level0_slowdown_writes_trigger(options
.level0_slowdown_writes_trigger
),
140 level0_stop_writes_trigger(options
.level0_stop_writes_trigger
),
141 max_compaction_bytes(options
.max_compaction_bytes
),
142 target_file_size_base(options
.target_file_size_base
),
143 target_file_size_multiplier(options
.target_file_size_multiplier
),
144 max_bytes_for_level_base(options
.max_bytes_for_level_base
),
145 max_bytes_for_level_multiplier(options
.max_bytes_for_level_multiplier
),
146 max_bytes_for_level_multiplier_additional(
147 options
.max_bytes_for_level_multiplier_additional
),
148 max_sequential_skip_in_iterations(
149 options
.max_sequential_skip_in_iterations
),
150 paranoid_file_checks(options
.paranoid_file_checks
),
151 report_bg_io_stats(options
.report_bg_io_stats
),
152 compression(options
.compression
) {
153 RefreshDerivedOptions(options
.num_levels
, options
.compaction_style
);
157 : write_buffer_size(0),
158 max_write_buffer_number(0),
160 memtable_prefix_bloom_size_ratio(0),
161 memtable_huge_page_size(0),
162 max_successive_merges(0),
163 inplace_update_num_locks(0),
164 disable_auto_compactions(false),
165 soft_pending_compaction_bytes_limit(0),
166 hard_pending_compaction_bytes_limit(0),
167 level0_file_num_compaction_trigger(0),
168 level0_slowdown_writes_trigger(0),
169 level0_stop_writes_trigger(0),
170 max_compaction_bytes(0),
171 target_file_size_base(0),
172 target_file_size_multiplier(0),
173 max_bytes_for_level_base(0),
174 max_bytes_for_level_multiplier(0),
175 max_sequential_skip_in_iterations(0),
176 paranoid_file_checks(false),
177 report_bg_io_stats(false),
178 compression(Snappy_Supported() ? kSnappyCompression
: kNoCompression
) {}
180 // Must be called after any change to MutableCFOptions
181 void RefreshDerivedOptions(int num_levels
, CompactionStyle compaction_style
);
183 void RefreshDerivedOptions(const ImmutableCFOptions
& ioptions
) {
184 RefreshDerivedOptions(ioptions
.num_levels
, ioptions
.compaction_style
);
187 // Get the max file size in a given level.
188 uint64_t MaxFileSizeForLevel(int level
) const;
189 int MaxBytesMultiplerAdditional(int level
) const {
191 static_cast<int>(max_bytes_for_level_multiplier_additional
.size())) {
194 return max_bytes_for_level_multiplier_additional
[level
];
197 void Dump(Logger
* log
) const;
199 // Memtable related options
200 size_t write_buffer_size
;
201 int max_write_buffer_number
;
202 size_t arena_block_size
;
203 double memtable_prefix_bloom_size_ratio
;
204 size_t memtable_huge_page_size
;
205 size_t max_successive_merges
;
206 size_t inplace_update_num_locks
;
208 // Compaction related options
209 bool disable_auto_compactions
;
210 uint64_t soft_pending_compaction_bytes_limit
;
211 uint64_t hard_pending_compaction_bytes_limit
;
212 int level0_file_num_compaction_trigger
;
213 int level0_slowdown_writes_trigger
;
214 int level0_stop_writes_trigger
;
215 uint64_t max_compaction_bytes
;
216 uint64_t target_file_size_base
;
217 int target_file_size_multiplier
;
218 uint64_t max_bytes_for_level_base
;
219 double max_bytes_for_level_multiplier
;
220 std::vector
<int> max_bytes_for_level_multiplier_additional
;
223 uint64_t max_sequential_skip_in_iterations
;
224 bool paranoid_file_checks
;
225 bool report_bg_io_stats
;
226 CompressionType compression
;
229 // Per-level target file size.
230 std::vector
<uint64_t> max_file_size
;
233 uint64_t MultiplyCheckOverflow(uint64_t op1
, double op2
);
235 } // namespace rocksdb