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.
6 #include "options/db_options.h"
8 #ifndef __STDC_FORMAT_MACROS
9 #define __STDC_FORMAT_MACROS
14 #include "port/port.h"
15 #include "rocksdb/cache.h"
16 #include "rocksdb/env.h"
17 #include "rocksdb/sst_file_manager.h"
18 #include "rocksdb/wal_filter.h"
19 #include "util/logging.h"
23 ImmutableDBOptions::ImmutableDBOptions() : ImmutableDBOptions(Options()) {}
25 ImmutableDBOptions::ImmutableDBOptions(const DBOptions
& options
)
26 : create_if_missing(options
.create_if_missing
),
27 create_missing_column_families(options
.create_missing_column_families
),
28 error_if_exists(options
.error_if_exists
),
29 paranoid_checks(options
.paranoid_checks
),
31 rate_limiter(options
.rate_limiter
),
32 sst_file_manager(options
.sst_file_manager
),
33 info_log(options
.info_log
),
34 info_log_level(options
.info_log_level
),
35 max_open_files(options
.max_open_files
),
36 max_file_opening_threads(options
.max_file_opening_threads
),
37 statistics(options
.statistics
),
38 use_fsync(options
.use_fsync
),
39 db_paths(options
.db_paths
),
40 db_log_dir(options
.db_log_dir
),
41 wal_dir(options
.wal_dir
),
42 max_subcompactions(options
.max_subcompactions
),
43 max_background_flushes(options
.max_background_flushes
),
44 max_log_file_size(options
.max_log_file_size
),
45 log_file_time_to_roll(options
.log_file_time_to_roll
),
46 keep_log_file_num(options
.keep_log_file_num
),
47 recycle_log_file_num(options
.recycle_log_file_num
),
48 max_manifest_file_size(options
.max_manifest_file_size
),
49 table_cache_numshardbits(options
.table_cache_numshardbits
),
50 wal_ttl_seconds(options
.WAL_ttl_seconds
),
51 wal_size_limit_mb(options
.WAL_size_limit_MB
),
52 manifest_preallocation_size(options
.manifest_preallocation_size
),
53 allow_mmap_reads(options
.allow_mmap_reads
),
54 allow_mmap_writes(options
.allow_mmap_writes
),
55 use_direct_reads(options
.use_direct_reads
),
56 use_direct_io_for_flush_and_compaction(
57 options
.use_direct_io_for_flush_and_compaction
),
58 allow_fallocate(options
.allow_fallocate
),
59 is_fd_close_on_exec(options
.is_fd_close_on_exec
),
60 advise_random_on_open(options
.advise_random_on_open
),
61 db_write_buffer_size(options
.db_write_buffer_size
),
62 write_buffer_manager(options
.write_buffer_manager
),
63 access_hint_on_compaction_start(options
.access_hint_on_compaction_start
),
64 new_table_reader_for_compaction_inputs(
65 options
.new_table_reader_for_compaction_inputs
),
66 compaction_readahead_size(options
.compaction_readahead_size
),
67 random_access_max_buffer_size(options
.random_access_max_buffer_size
),
68 writable_file_max_buffer_size(options
.writable_file_max_buffer_size
),
69 use_adaptive_mutex(options
.use_adaptive_mutex
),
70 bytes_per_sync(options
.bytes_per_sync
),
71 wal_bytes_per_sync(options
.wal_bytes_per_sync
),
72 listeners(options
.listeners
),
73 enable_thread_tracking(options
.enable_thread_tracking
),
74 allow_concurrent_memtable_write(options
.allow_concurrent_memtable_write
),
75 enable_write_thread_adaptive_yield(
76 options
.enable_write_thread_adaptive_yield
),
77 write_thread_max_yield_usec(options
.write_thread_max_yield_usec
),
78 write_thread_slow_yield_usec(options
.write_thread_slow_yield_usec
),
79 skip_stats_update_on_db_open(options
.skip_stats_update_on_db_open
),
80 wal_recovery_mode(options
.wal_recovery_mode
),
81 allow_2pc(options
.allow_2pc
),
82 row_cache(options
.row_cache
),
84 wal_filter(options
.wal_filter
),
85 #endif // ROCKSDB_LITE
86 fail_if_options_file_error(options
.fail_if_options_file_error
),
87 dump_malloc_stats(options
.dump_malloc_stats
),
88 avoid_flush_during_recovery(options
.avoid_flush_during_recovery
) {
91 void ImmutableDBOptions::Dump(Logger
* log
) const {
92 ROCKS_LOG_HEADER(log
, " Options.error_if_exists: %d",
94 ROCKS_LOG_HEADER(log
, " Options.create_if_missing: %d",
96 ROCKS_LOG_HEADER(log
, " Options.paranoid_checks: %d",
98 ROCKS_LOG_HEADER(log
, " Options.env: %p",
100 ROCKS_LOG_HEADER(log
, " Options.info_log: %p",
102 ROCKS_LOG_HEADER(log
, " Options.max_open_files: %d",
104 ROCKS_LOG_HEADER(log
, " Options.max_file_opening_threads: %d",
105 max_file_opening_threads
);
106 ROCKS_LOG_HEADER(log
, " Options.use_fsync: %d",
109 log
, " Options.max_log_file_size: %" ROCKSDB_PRIszt
,
111 ROCKS_LOG_HEADER(log
,
112 " Options.max_manifest_file_size: %" PRIu64
,
113 max_manifest_file_size
);
115 log
, " Options.log_file_time_to_roll: %" ROCKSDB_PRIszt
,
116 log_file_time_to_roll
);
118 log
, " Options.keep_log_file_num: %" ROCKSDB_PRIszt
,
121 log
, " Options.recycle_log_file_num: %" ROCKSDB_PRIszt
,
122 recycle_log_file_num
);
123 ROCKS_LOG_HEADER(log
, " Options.allow_fallocate: %d",
125 ROCKS_LOG_HEADER(log
, " Options.allow_mmap_reads: %d",
127 ROCKS_LOG_HEADER(log
, " Options.allow_mmap_writes: %d",
129 ROCKS_LOG_HEADER(log
, " Options.use_direct_reads: %d",
131 ROCKS_LOG_HEADER(log
,
133 "Options.use_direct_io_for_flush_and_compaction: %d",
134 use_direct_io_for_flush_and_compaction
);
135 ROCKS_LOG_HEADER(log
, " Options.create_missing_column_families: %d",
136 create_missing_column_families
);
137 ROCKS_LOG_HEADER(log
, " Options.db_log_dir: %s",
139 ROCKS_LOG_HEADER(log
, " Options.wal_dir: %s",
141 ROCKS_LOG_HEADER(log
, " Options.table_cache_numshardbits: %d",
142 table_cache_numshardbits
);
143 ROCKS_LOG_HEADER(log
,
144 " Options.max_subcompactions: %" PRIu32
,
146 ROCKS_LOG_HEADER(log
, " Options.max_background_flushes: %d",
147 max_background_flushes
);
148 ROCKS_LOG_HEADER(log
,
149 " Options.WAL_ttl_seconds: %" PRIu64
,
151 ROCKS_LOG_HEADER(log
,
152 " Options.WAL_size_limit_MB: %" PRIu64
,
155 log
, " Options.manifest_preallocation_size: %" ROCKSDB_PRIszt
,
156 manifest_preallocation_size
);
157 ROCKS_LOG_HEADER(log
, " Options.is_fd_close_on_exec: %d",
158 is_fd_close_on_exec
);
159 ROCKS_LOG_HEADER(log
, " Options.advise_random_on_open: %d",
160 advise_random_on_open
);
162 log
, " Options.db_write_buffer_size: %" ROCKSDB_PRIszt
,
163 db_write_buffer_size
);
164 ROCKS_LOG_HEADER(log
, " Options.access_hint_on_compaction_start: %d",
165 static_cast<int>(access_hint_on_compaction_start
));
166 ROCKS_LOG_HEADER(log
, " Options.new_table_reader_for_compaction_inputs: %d",
167 new_table_reader_for_compaction_inputs
);
169 log
, " Options.compaction_readahead_size: %" ROCKSDB_PRIszt
,
170 compaction_readahead_size
);
172 log
, " Options.random_access_max_buffer_size: %" ROCKSDB_PRIszt
,
173 random_access_max_buffer_size
);
175 log
, " Options.writable_file_max_buffer_size: %" ROCKSDB_PRIszt
,
176 writable_file_max_buffer_size
);
177 ROCKS_LOG_HEADER(log
, " Options.use_adaptive_mutex: %d",
179 ROCKS_LOG_HEADER(log
, " Options.rate_limiter: %p",
182 log
, " Options.sst_file_manager.rate_bytes_per_sec: %" PRIi64
,
183 sst_file_manager
? sst_file_manager
->GetDeleteRateBytesPerSecond() : 0);
184 ROCKS_LOG_HEADER(log
,
185 " Options.bytes_per_sync: %" PRIu64
,
187 ROCKS_LOG_HEADER(log
,
188 " Options.wal_bytes_per_sync: %" PRIu64
,
190 ROCKS_LOG_HEADER(log
, " Options.wal_recovery_mode: %d",
192 ROCKS_LOG_HEADER(log
, " Options.enable_thread_tracking: %d",
193 enable_thread_tracking
);
194 ROCKS_LOG_HEADER(log
, " Options.allow_concurrent_memtable_write: %d",
195 allow_concurrent_memtable_write
);
196 ROCKS_LOG_HEADER(log
, " Options.enable_write_thread_adaptive_yield: %d",
197 enable_write_thread_adaptive_yield
);
198 ROCKS_LOG_HEADER(log
,
199 " Options.write_thread_max_yield_usec: %" PRIu64
,
200 write_thread_max_yield_usec
);
201 ROCKS_LOG_HEADER(log
,
202 " Options.write_thread_slow_yield_usec: %" PRIu64
,
203 write_thread_slow_yield_usec
);
206 log
, " Options.row_cache: %" PRIu64
,
207 row_cache
->GetCapacity());
209 ROCKS_LOG_HEADER(log
,
210 " Options.row_cache: None");
213 ROCKS_LOG_HEADER(log
, " Options.wal_filter: %s",
214 wal_filter
? wal_filter
->Name() : "None");
215 #endif // ROCKDB_LITE
216 ROCKS_LOG_HEADER(log
, " Options.avoid_flush_during_recovery: %d",
217 avoid_flush_during_recovery
);
220 MutableDBOptions::MutableDBOptions()
221 : base_background_compactions(1),
222 max_background_compactions(1),
223 avoid_flush_during_shutdown(false),
224 delayed_write_rate(2 * 1024U * 1024U),
225 max_total_wal_size(0),
226 delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
227 stats_dump_period_sec(600) {}
229 MutableDBOptions::MutableDBOptions(const DBOptions
& options
)
230 : base_background_compactions(options
.base_background_compactions
),
231 max_background_compactions(options
.max_background_compactions
),
232 avoid_flush_during_shutdown(options
.avoid_flush_during_shutdown
),
233 delayed_write_rate(options
.delayed_write_rate
),
234 max_total_wal_size(options
.max_total_wal_size
),
235 delete_obsolete_files_period_micros(
236 options
.delete_obsolete_files_period_micros
),
237 stats_dump_period_sec(options
.stats_dump_period_sec
) {}
239 void MutableDBOptions::Dump(Logger
* log
) const {
240 ROCKS_LOG_HEADER(log
, " Options.base_background_compactions: %d",
241 base_background_compactions
);
242 ROCKS_LOG_HEADER(log
, " Options.max_background_compactions: %d",
243 max_background_compactions
);
244 ROCKS_LOG_HEADER(log
, " Options.avoid_flush_during_shutdown: %d",
245 avoid_flush_during_shutdown
);
246 ROCKS_LOG_HEADER(log
, " Options.delayed_write_rate : %" PRIu64
,
248 ROCKS_LOG_HEADER(log
, " Options.max_total_wal_size: %" PRIu64
,
251 log
, " Options.delete_obsolete_files_period_micros: %" PRIu64
,
252 delete_obsolete_files_period_micros
);
253 ROCKS_LOG_HEADER(log
, " Options.stats_dump_period_sec: %u",
254 stats_dump_period_sec
);
257 } // namespace rocksdb