db_options.cc 49.3 KB
Newer Older
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
S
Siying Dong 已提交
2 3 4
//  This source code is licensed under both the GPLv2 (found in the
//  COPYING file in the root directory) and Apache 2.0 License
//  (found in the LICENSE.Apache file in the root directory).
5

6
#include "options/db_options.h"
7

8
#include <cinttypes>
9

10
#include "logging/logging.h"
11
#include "options/configurable_helper.h"
12
#include "options/options_helper.h"
13
#include "options/options_parser.h"
14
#include "port/port.h"
15
#include "rocksdb/configurable.h"
16
#include "rocksdb/env.h"
17
#include "rocksdb/file_system.h"
18
#include "rocksdb/listener.h"
19
#include "rocksdb/rate_limiter.h"
20
#include "rocksdb/sst_file_manager.h"
21
#include "rocksdb/statistics.h"
22
#include "rocksdb/system_clock.h"
23
#include "rocksdb/utilities/options_type.h"
24
#include "rocksdb/wal_filter.h"
25
#include "util/string_util.h"
26

27
namespace ROCKSDB_NAMESPACE {
28
#ifndef ROCKSDB_LITE
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
static std::unordered_map<std::string, WALRecoveryMode>
    wal_recovery_mode_string_map = {
        {"kTolerateCorruptedTailRecords",
         WALRecoveryMode::kTolerateCorruptedTailRecords},
        {"kAbsoluteConsistency", WALRecoveryMode::kAbsoluteConsistency},
        {"kPointInTimeRecovery", WALRecoveryMode::kPointInTimeRecovery},
        {"kSkipAnyCorruptedRecords",
         WALRecoveryMode::kSkipAnyCorruptedRecords}};

static std::unordered_map<std::string, DBOptions::AccessHint>
    access_hint_string_map = {{"NONE", DBOptions::AccessHint::NONE},
                              {"NORMAL", DBOptions::AccessHint::NORMAL},
                              {"SEQUENTIAL", DBOptions::AccessHint::SEQUENTIAL},
                              {"WILLNEED", DBOptions::AccessHint::WILLNEED}};

44 45 46 47
static std::unordered_map<std::string, CacheTier> cache_tier_string_map = {
    {"kVolatileTier", CacheTier::kVolatileTier},
    {"kNonVolatileBlockTier", CacheTier::kNonVolatileBlockTier}};

48 49 50 51 52 53 54 55
static std::unordered_map<std::string, InfoLogLevel> info_log_level_string_map =
    {{"DEBUG_LEVEL", InfoLogLevel::DEBUG_LEVEL},
     {"INFO_LEVEL", InfoLogLevel::INFO_LEVEL},
     {"WARN_LEVEL", InfoLogLevel::WARN_LEVEL},
     {"ERROR_LEVEL", InfoLogLevel::ERROR_LEVEL},
     {"FATAL_LEVEL", InfoLogLevel::FATAL_LEVEL},
     {"HEADER_LEVEL", InfoLogLevel::HEADER_LEVEL}};

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
static std::unordered_map<std::string, OptionTypeInfo>
    db_mutable_options_type_info = {
        {"allow_os_buffer",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kMutable}},
        {"max_background_jobs",
         {offsetof(struct MutableDBOptions, max_background_jobs),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"max_background_compactions",
         {offsetof(struct MutableDBOptions, max_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"base_background_compactions",
         {offsetof(struct MutableDBOptions, base_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"max_subcompactions",
         {offsetof(struct MutableDBOptions, max_subcompactions),
          OptionType::kUInt32T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"avoid_flush_during_shutdown",
         {offsetof(struct MutableDBOptions, avoid_flush_during_shutdown),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"writable_file_max_buffer_size",
         {offsetof(struct MutableDBOptions, writable_file_max_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"delayed_write_rate",
         {offsetof(struct MutableDBOptions, delayed_write_rate),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"max_total_wal_size",
         {offsetof(struct MutableDBOptions, max_total_wal_size),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"delete_obsolete_files_period_micros",
         {offsetof(struct MutableDBOptions,
                   delete_obsolete_files_period_micros),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"stats_dump_period_sec",
         {offsetof(struct MutableDBOptions, stats_dump_period_sec),
          OptionType::kUInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"stats_persist_period_sec",
         {offsetof(struct MutableDBOptions, stats_persist_period_sec),
          OptionType::kUInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"stats_history_buffer_size",
         {offsetof(struct MutableDBOptions, stats_history_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"max_open_files",
         {offsetof(struct MutableDBOptions, max_open_files), OptionType::kInt,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
        {"bytes_per_sync",
         {offsetof(struct MutableDBOptions, bytes_per_sync),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"wal_bytes_per_sync",
         {offsetof(struct MutableDBOptions, wal_bytes_per_sync),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"strict_bytes_per_sync",
         {offsetof(struct MutableDBOptions, strict_bytes_per_sync),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"compaction_readahead_size",
         {offsetof(struct MutableDBOptions, compaction_readahead_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
        {"max_background_flushes",
         {offsetof(struct MutableDBOptions, max_background_flushes),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable}},
};

static std::unordered_map<std::string, OptionTypeInfo>
    db_immutable_options_type_info = {
137 138 139 140 141 142 143 144
        /*
         // not yet supported
          std::shared_ptr<Cache> row_cache;
          std::shared_ptr<DeleteScheduler> delete_scheduler;
          std::shared_ptr<Logger> info_log;
          std::shared_ptr<RateLimiter> rate_limiter;
          std::shared_ptr<Statistics> statistics;
          std::vector<DbPath> db_paths;
145
          FileTypeSet checksum_handoff_file_types;
146 147
         */
        {"advise_random_on_open",
148
         {offsetof(struct ImmutableDBOptions, advise_random_on_open),
149
          OptionType::kBoolean, OptionVerificationType::kNormal,
150
          OptionTypeFlags::kNone}},
151
        {"allow_mmap_reads",
152 153 154
         {offsetof(struct ImmutableDBOptions, allow_mmap_reads),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
155
        {"allow_fallocate",
156 157 158
         {offsetof(struct ImmutableDBOptions, allow_fallocate),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
159
        {"allow_mmap_writes",
160 161 162
         {offsetof(struct ImmutableDBOptions, allow_mmap_writes),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
163
        {"use_direct_reads",
164 165 166
         {offsetof(struct ImmutableDBOptions, use_direct_reads),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
167 168
        {"use_direct_writes",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
169
          OptionTypeFlags::kNone}},
170
        {"use_direct_io_for_flush_and_compaction",
171 172
         {offsetof(struct ImmutableDBOptions,
                   use_direct_io_for_flush_and_compaction),
173
          OptionType::kBoolean, OptionVerificationType::kNormal,
174
          OptionTypeFlags::kNone}},
175
        {"allow_2pc",
176 177
         {offsetof(struct ImmutableDBOptions, allow_2pc), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
178 179 180 181 182
        {"wal_filter",
         OptionTypeInfo::AsCustomRawPtr<WalFilter>(
             offsetof(struct ImmutableDBOptions, wal_filter),
             OptionVerificationType::kByName,
             (OptionTypeFlags::kAllowNull | OptionTypeFlags::kCompareNever))},
183
        {"create_if_missing",
184 185 186
         {offsetof(struct ImmutableDBOptions, create_if_missing),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
187
        {"create_missing_column_families",
188
         {offsetof(struct ImmutableDBOptions, create_missing_column_families),
189
          OptionType::kBoolean, OptionVerificationType::kNormal,
190
          OptionTypeFlags::kNone}},
191 192
        {"disableDataSync",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
193
          OptionTypeFlags::kNone}},
194 195
        {"disable_data_sync",  // for compatibility
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
196
          OptionTypeFlags::kNone}},
197
        {"enable_thread_tracking",
198
         {offsetof(struct ImmutableDBOptions, enable_thread_tracking),
199
          OptionType::kBoolean, OptionVerificationType::kNormal,
200
          OptionTypeFlags::kNone}},
201
        {"error_if_exists",
202 203 204
         {offsetof(struct ImmutableDBOptions, error_if_exists),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
205 206 207 208 209 210
        {"experimental_allow_mempurge",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone}},
        {"experimental_mempurge_policy",
         {0, OptionType::kString, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone}},
211 212 213
        {"experimental_mempurge_threshold",
         {offsetof(struct ImmutableDBOptions, experimental_mempurge_threshold),
          OptionType::kDouble, OptionVerificationType::kNormal,
214
          OptionTypeFlags::kNone}},
215
        {"is_fd_close_on_exec",
216 217 218
         {offsetof(struct ImmutableDBOptions, is_fd_close_on_exec),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
219
        {"paranoid_checks",
220
         {offsetof(struct ImmutableDBOptions, paranoid_checks),
221
          OptionType::kBoolean, OptionVerificationType::kNormal,
222
          OptionTypeFlags::kNone}},
223 224 225 226
        {"flush_verify_memtable_count",
         {offsetof(struct ImmutableDBOptions, flush_verify_memtable_count),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
227 228 229 230 231
        {"track_and_verify_wals_in_manifest",
         {offsetof(struct ImmutableDBOptions,
                   track_and_verify_wals_in_manifest),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
232 233 234
        {"skip_log_error_on_recovery",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone}},
235
        {"skip_stats_update_on_db_open",
236
         {offsetof(struct ImmutableDBOptions, skip_stats_update_on_db_open),
237
          OptionType::kBoolean, OptionVerificationType::kNormal,
238
          OptionTypeFlags::kNone}},
239
        {"skip_checking_sst_file_sizes_on_db_open",
240 241
         {offsetof(struct ImmutableDBOptions,
                   skip_checking_sst_file_sizes_on_db_open),
242
          OptionType::kBoolean, OptionVerificationType::kNormal,
243
          OptionTypeFlags::kNone}},
244
        {"new_table_reader_for_compaction_inputs",
245 246
         {offsetof(struct ImmutableDBOptions,
                   new_table_reader_for_compaction_inputs),
247
          OptionType::kBoolean, OptionVerificationType::kNormal,
248
          OptionTypeFlags::kNone}},
249
        {"random_access_max_buffer_size",
250
         {offsetof(struct ImmutableDBOptions, random_access_max_buffer_size),
251
          OptionType::kSizeT, OptionVerificationType::kNormal,
252
          OptionTypeFlags::kNone}},
253
        {"use_adaptive_mutex",
254 255 256
         {offsetof(struct ImmutableDBOptions, use_adaptive_mutex),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
257
        {"use_fsync",
258 259
         {offsetof(struct ImmutableDBOptions, use_fsync), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
260
        {"max_file_opening_threads",
261
         {offsetof(struct ImmutableDBOptions, max_file_opening_threads),
262
          OptionType::kInt, OptionVerificationType::kNormal,
263
          OptionTypeFlags::kNone}},
264
        {"table_cache_numshardbits",
265
         {offsetof(struct ImmutableDBOptions, table_cache_numshardbits),
266
          OptionType::kInt, OptionVerificationType::kNormal,
267
          OptionTypeFlags::kNone}},
268
        {"db_write_buffer_size",
269 270 271
         {offsetof(struct ImmutableDBOptions, db_write_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
272
        {"keep_log_file_num",
273 274 275
         {offsetof(struct ImmutableDBOptions, keep_log_file_num),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
276
        {"recycle_log_file_num",
277 278 279
         {offsetof(struct ImmutableDBOptions, recycle_log_file_num),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
280
        {"log_file_time_to_roll",
281 282 283
         {offsetof(struct ImmutableDBOptions, log_file_time_to_roll),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
284
        {"manifest_preallocation_size",
285
         {offsetof(struct ImmutableDBOptions, manifest_preallocation_size),
286
          OptionType::kSizeT, OptionVerificationType::kNormal,
287
          OptionTypeFlags::kNone}},
288
        {"max_log_file_size",
289 290 291
         {offsetof(struct ImmutableDBOptions, max_log_file_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
292
        {"db_log_dir",
293 294
         {offsetof(struct ImmutableDBOptions, db_log_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
295
        {"wal_dir",
296 297
         {offsetof(struct ImmutableDBOptions, wal_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
298
        {"WAL_size_limit_MB",
299
         {offsetof(struct ImmutableDBOptions, WAL_size_limit_MB),
300 301
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
302
        {"WAL_ttl_seconds",
303
         {offsetof(struct ImmutableDBOptions, WAL_ttl_seconds),
304
          OptionType::kUInt64T, OptionVerificationType::kNormal,
305
          OptionTypeFlags::kNone}},
306
        {"max_manifest_file_size",
307
         {offsetof(struct ImmutableDBOptions, max_manifest_file_size),
308
          OptionType::kUInt64T, OptionVerificationType::kNormal,
309
          OptionTypeFlags::kNone}},
310
        {"persist_stats_to_disk",
311
         {offsetof(struct ImmutableDBOptions, persist_stats_to_disk),
312
          OptionType::kBoolean, OptionVerificationType::kNormal,
313
          OptionTypeFlags::kNone}},
314
        {"fail_if_options_file_error",
315
         {offsetof(struct ImmutableDBOptions, fail_if_options_file_error),
316
          OptionType::kBoolean, OptionVerificationType::kNormal,
317
          OptionTypeFlags::kNone}},
318
        {"enable_pipelined_write",
319
         {offsetof(struct ImmutableDBOptions, enable_pipelined_write),
320
          OptionType::kBoolean, OptionVerificationType::kNormal,
321
          OptionTypeFlags::kNone}},
322
        {"unordered_write",
323 324 325
         {offsetof(struct ImmutableDBOptions, unordered_write),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
326
        {"allow_concurrent_memtable_write",
327
         {offsetof(struct ImmutableDBOptions, allow_concurrent_memtable_write),
328
          OptionType::kBoolean, OptionVerificationType::kNormal,
329 330 331 332 333
          OptionTypeFlags::kNone}},
        {"wal_recovery_mode",
         OptionTypeInfo::Enum<WALRecoveryMode>(
             offsetof(struct ImmutableDBOptions, wal_recovery_mode),
             &wal_recovery_mode_string_map)},
334
        {"enable_write_thread_adaptive_yield",
335 336
         {offsetof(struct ImmutableDBOptions,
                   enable_write_thread_adaptive_yield),
337
          OptionType::kBoolean, OptionVerificationType::kNormal,
338
          OptionTypeFlags::kNone}},
339
        {"write_thread_slow_yield_usec",
340
         {offsetof(struct ImmutableDBOptions, write_thread_slow_yield_usec),
341
          OptionType::kUInt64T, OptionVerificationType::kNormal,
342
          OptionTypeFlags::kNone}},
343
        {"max_write_batch_group_size_bytes",
344
         {offsetof(struct ImmutableDBOptions, max_write_batch_group_size_bytes),
345
          OptionType::kUInt64T, OptionVerificationType::kNormal,
346
          OptionTypeFlags::kNone}},
347
        {"write_thread_max_yield_usec",
348
         {offsetof(struct ImmutableDBOptions, write_thread_max_yield_usec),
349
          OptionType::kUInt64T, OptionVerificationType::kNormal,
350
          OptionTypeFlags::kNone}},
351
        {"access_hint_on_compaction_start",
352
         OptionTypeInfo::Enum<DBOptions::AccessHint>(
353 354
             offsetof(struct ImmutableDBOptions,
                      access_hint_on_compaction_start),
355
             &access_hint_string_map)},
356 357 358 359
        {"info_log_level",
         OptionTypeInfo::Enum<InfoLogLevel>(
             offsetof(struct ImmutableDBOptions, info_log_level),
             &info_log_level_string_map)},
360
        {"dump_malloc_stats",
361
         {offsetof(struct ImmutableDBOptions, dump_malloc_stats),
362
          OptionType::kBoolean, OptionVerificationType::kNormal,
363 364 365
          OptionTypeFlags::kNone}},
        {"avoid_flush_during_recovery",
         {offsetof(struct ImmutableDBOptions, avoid_flush_during_recovery),
366
          OptionType::kBoolean, OptionVerificationType::kNormal,
367
          OptionTypeFlags::kNone}},
368
        {"allow_ingest_behind",
369 370 371
         {offsetof(struct ImmutableDBOptions, allow_ingest_behind),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
372
        {"preserve_deletes",
373 374 375
         {offsetof(struct ImmutableDBOptions, preserve_deletes),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
376 377
        {"concurrent_prepare",  // Deprecated by two_write_queues
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
378
          OptionTypeFlags::kNone}},
379
        {"two_write_queues",
380 381 382
         {offsetof(struct ImmutableDBOptions, two_write_queues),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
383
        {"manual_wal_flush",
384 385 386
         {offsetof(struct ImmutableDBOptions, manual_wal_flush),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
387 388
        {"seq_per_batch",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
389
          OptionTypeFlags::kNone}},
390
        {"atomic_flush",
391 392 393
         {offsetof(struct ImmutableDBOptions, atomic_flush),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
394
        {"avoid_unnecessary_blocking_io",
395
         {offsetof(struct ImmutableDBOptions, avoid_unnecessary_blocking_io),
396
          OptionType::kBoolean, OptionVerificationType::kNormal,
397
          OptionTypeFlags::kNone}},
398
        {"write_dbid_to_manifest",
399
         {offsetof(struct ImmutableDBOptions, write_dbid_to_manifest),
400
          OptionType::kBoolean, OptionVerificationType::kNormal,
401
          OptionTypeFlags::kNone}},
402
        {"log_readahead_size",
403 404 405
         {offsetof(struct ImmutableDBOptions, log_readahead_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
406
        {"best_efforts_recovery",
407
         {offsetof(struct ImmutableDBOptions, best_efforts_recovery),
408
          OptionType::kBoolean, OptionVerificationType::kNormal,
409
          OptionTypeFlags::kNone}},
410
        {"max_bgerror_resume_count",
411
         {offsetof(struct ImmutableDBOptions, max_bgerror_resume_count),
412
          OptionType::kInt, OptionVerificationType::kNormal,
413
          OptionTypeFlags::kNone}},
414
        {"bgerror_resume_retry_interval",
415
         {offsetof(struct ImmutableDBOptions, bgerror_resume_retry_interval),
416
          OptionType::kUInt64T, OptionVerificationType::kNormal,
417
          OptionTypeFlags::kNone}},
418 419 420
        {"db_host_id",
         {offsetof(struct ImmutableDBOptions, db_host_id), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kCompareNever}},
M
mrambacher 已提交
421 422 423 424 425 426
        {"rate_limiter",
         OptionTypeInfo::AsCustomSharedPtr<RateLimiter>(
             offsetof(struct ImmutableDBOptions, rate_limiter),
             OptionVerificationType::kNormal,
             OptionTypeFlags::kCompareNever | OptionTypeFlags::kAllowNull)},

427 428 429 430
        // The following properties were handled as special cases in ParseOption
        // This means that the properties could be read from the options file
        // but never written to the file or compared to each other.
        {"rate_limiter_bytes_per_sec",
431 432 433
         {offsetof(struct ImmutableDBOptions, rate_limiter),
          OptionType::kUnknown, OptionVerificationType::kNormal,
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever),
434 435
          // Parse the input value as a RateLimiter
          [](const ConfigOptions& /*opts*/, const std::string& /*name*/,
436 437
             const std::string& value, void* addr) {
            auto limiter = static_cast<std::shared_ptr<RateLimiter>*>(addr);
438 439 440 441 442
            limiter->reset(NewGenericRateLimiter(
                static_cast<int64_t>(ParseUint64(value))));
            return Status::OK();
          }}},
        {"env",
443
         {offsetof(struct ImmutableDBOptions, env), OptionType::kUnknown,
444
          OptionVerificationType::kNormal,
445
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever),
446
          // Parse the input value as an Env
447
          [](const ConfigOptions& opts, const std::string& /*name*/,
448 449
             const std::string& value, void* addr) {
            auto old_env = static_cast<Env**>(addr);       // Get the old value
450
            Env* new_env = *old_env;                       // Set new to old
451 452
            Status s = Env::CreateFromString(opts, value,
                                             &new_env);    // Update new value
453 454 455 456 457
            if (s.ok()) {                                  // It worked
              *old_env = new_env;                          // Update the old one
            }
            return s;
          }}},
458 459 460 461
        {"allow_data_in_errors",
         {offsetof(struct ImmutableDBOptions, allow_data_in_errors),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
462 463 464
        {"file_checksum_gen_factory",
         OptionTypeInfo::AsCustomSharedPtr<FileChecksumGenFactory>(
             offsetof(struct ImmutableDBOptions, file_checksum_gen_factory),
465 466
             OptionVerificationType::kByNameAllowFromNull,
             OptionTypeFlags::kAllowNull)},
467 468 469 470 471 472 473 474 475
        {"statistics",
         OptionTypeInfo::AsCustomSharedPtr<Statistics>(
             // Statistics should not be compared and can be null
             // Statistics are maked "don't serialize" until they can be shared
             // between DBs
             offsetof(struct ImmutableDBOptions, statistics),
             OptionVerificationType::kNormal,
             OptionTypeFlags::kCompareNever | OptionTypeFlags::kDontSerialize |
                 OptionTypeFlags::kAllowNull)},
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
        // Allow EventListeners that have a non-empty Name() to be read/written
        // as options Each listener will either be
        // - A simple name (e.g. "MyEventListener")
        // - A name with properties (e.g. "{id=MyListener1; timeout=60}"
        // Multiple listeners will be separated by a ":":
        //   - "MyListener0;{id=MyListener1; timeout=60}
        {"listeners",
         {offsetof(struct ImmutableDBOptions, listeners), OptionType::kVector,
          OptionVerificationType::kByNameAllowNull,
          OptionTypeFlags::kCompareNever,
          [](const ConfigOptions& opts, const std::string& /*name*/,
             const std::string& value, void* addr) {
            ConfigOptions embedded = opts;
            embedded.ignore_unsupported_options = true;
            std::vector<std::shared_ptr<EventListener>> listeners;
            Status s;
            for (size_t start = 0, end = 0;
                 s.ok() && start < value.size() && end != std::string::npos;
                 start = end + 1) {
              std::string token;
              s = OptionTypeInfo::NextToken(value, ':', start, &end, &token);
              if (s.ok() && !token.empty()) {
                std::shared_ptr<EventListener> listener;
                s = EventListener::CreateFromString(embedded, token, &listener);
                if (s.ok() && listener != nullptr) {
                  listeners.push_back(listener);
                }
              }
            }
            if (s.ok()) {  // It worked
              *(static_cast<std::vector<std::shared_ptr<EventListener>>*>(
                  addr)) = listeners;
            }
            return s;
          },
          [](const ConfigOptions& opts, const std::string& /*name*/,
             const void* addr, std::string* value) {
            const auto listeners =
                static_cast<const std::vector<std::shared_ptr<EventListener>>*>(
                    addr);
            ConfigOptions embedded = opts;
            embedded.delimiter = ";";
            int printed = 0;
            for (const auto& listener : *listeners) {
              auto id = listener->GetId();
              if (!id.empty()) {
                std::string elem_str = listener->ToString(embedded, "");
                if (printed++ == 0) {
                  value->append("{");
                } else {
                  value->append(":");
                }
                value->append(elem_str);
              }
            }
            if (printed > 0) {
              value->append("}");
            }
            return Status::OK();
          },
          nullptr}},
537 538 539 540
        {"lowest_used_cache_tier",
         OptionTypeInfo::Enum<CacheTier>(
             offsetof(struct ImmutableDBOptions, lowest_used_cache_tier),
             &cache_tier_string_map, OptionTypeFlags::kNone)},
541
};
542 543 544 545 546

const std::string OptionsHelper::kDBOptionsName = "DBOptions";

class MutableDBConfigurable : public Configurable {
 public:
547 548 549 550
  explicit MutableDBConfigurable(
      const MutableDBOptions& mdb,
      const std::unordered_map<std::string, std::string>* map = nullptr)
      : mutable_(mdb), opt_map_(map) {
551
    RegisterOptions(&mutable_, &db_mutable_options_type_info);
552 553
  }

554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
  bool OptionsAreEqual(const ConfigOptions& config_options,
                       const OptionTypeInfo& opt_info,
                       const std::string& opt_name, const void* const this_ptr,
                       const void* const that_ptr,
                       std::string* mismatch) const override {
    bool equals = opt_info.AreEqual(config_options, opt_name, this_ptr,
                                    that_ptr, mismatch);
    if (!equals && opt_info.IsByName()) {
      if (opt_map_ == nullptr) {
        equals = true;
      } else {
        const auto& iter = opt_map_->find(opt_name);
        if (iter == opt_map_->end()) {
          equals = true;
        } else {
          equals = opt_info.AreEqualByName(config_options, opt_name, this_ptr,
                                           iter->second);
        }
      }
      if (equals) {  // False alarm, clear mismatch
        *mismatch = "";
      }
    }
    if (equals && opt_info.IsConfigurable() && opt_map_ != nullptr) {
      const auto* this_config = opt_info.AsRawPointer<Configurable>(this_ptr);
      if (this_config == nullptr) {
        const auto& iter = opt_map_->find(opt_name);
        // If the name exists in the map and is not empty/null,
        // then the this_config should be set.
        if (iter != opt_map_->end() && !iter->second.empty() &&
            iter->second != kNullptrString) {
          *mismatch = opt_name;
          equals = false;
        }
      }
    }
    return equals;
  }

593 594
 protected:
  MutableDBOptions mutable_;
595
  const std::unordered_map<std::string, std::string>* opt_map_;
596 597 598 599
};

class DBOptionsConfigurable : public MutableDBConfigurable {
 public:
600 601 602 603
  explicit DBOptionsConfigurable(
      const DBOptions& opts,
      const std::unordered_map<std::string, std::string>* map = nullptr)
      : MutableDBConfigurable(MutableDBOptions(opts), map), db_options_(opts) {
604 605 606 607 608 609 610 611 612
    // The ImmutableDBOptions currently requires the env to be non-null.  Make
    // sure it is
    if (opts.env != nullptr) {
      immutable_ = ImmutableDBOptions(opts);
    } else {
      DBOptions copy = opts;
      copy.env = Env::Default();
      immutable_ = ImmutableDBOptions(copy);
    }
613
    RegisterOptions(&immutable_, &db_immutable_options_type_info);
614 615 616 617 618 619 620
  }

 protected:
  Status ConfigureOptions(
      const ConfigOptions& config_options,
      const std::unordered_map<std::string, std::string>& opts_map,
      std::unordered_map<std::string, std::string>* unused) override {
621
    Status s = Configurable::ConfigureOptions(config_options, opts_map, unused);
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    if (s.ok()) {
      db_options_ = BuildDBOptions(immutable_, mutable_);
      s = PrepareOptions(config_options);
    }
    return s;
  }

  const void* GetOptionsPtr(const std::string& name) const override {
    if (name == OptionsHelper::kDBOptionsName) {
      return &db_options_;
    } else {
      return MutableDBConfigurable::GetOptionsPtr(name);
    }
  }

 private:
  ImmutableDBOptions immutable_;
  DBOptions db_options_;
};

std::unique_ptr<Configurable> DBOptionsAsConfigurable(
    const MutableDBOptions& opts) {
  std::unique_ptr<Configurable> ptr(new MutableDBConfigurable(opts));
  return ptr;
}
647 648 649 650
std::unique_ptr<Configurable> DBOptionsAsConfigurable(
    const DBOptions& opts,
    const std::unordered_map<std::string, std::string>* opt_map) {
  std::unique_ptr<Configurable> ptr(new DBOptionsConfigurable(opts, opt_map));
651 652
  return ptr;
}
653
#endif  // ROCKSDB_LITE
654 655 656 657 658 659 660 661

ImmutableDBOptions::ImmutableDBOptions() : ImmutableDBOptions(Options()) {}

ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options)
    : create_if_missing(options.create_if_missing),
      create_missing_column_families(options.create_missing_column_families),
      error_if_exists(options.error_if_exists),
      paranoid_checks(options.paranoid_checks),
662
      flush_verify_memtable_count(options.flush_verify_memtable_count),
663 664
      track_and_verify_wals_in_manifest(
          options.track_and_verify_wals_in_manifest),
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
      env(options.env),
      rate_limiter(options.rate_limiter),
      sst_file_manager(options.sst_file_manager),
      info_log(options.info_log),
      info_log_level(options.info_log_level),
      max_file_opening_threads(options.max_file_opening_threads),
      statistics(options.statistics),
      use_fsync(options.use_fsync),
      db_paths(options.db_paths),
      db_log_dir(options.db_log_dir),
      wal_dir(options.wal_dir),
      max_log_file_size(options.max_log_file_size),
      log_file_time_to_roll(options.log_file_time_to_roll),
      keep_log_file_num(options.keep_log_file_num),
      recycle_log_file_num(options.recycle_log_file_num),
      max_manifest_file_size(options.max_manifest_file_size),
      table_cache_numshardbits(options.table_cache_numshardbits),
682 683
      WAL_ttl_seconds(options.WAL_ttl_seconds),
      WAL_size_limit_MB(options.WAL_size_limit_MB),
684 685
      max_write_batch_group_size_bytes(
          options.max_write_batch_group_size_bytes),
686 687 688
      manifest_preallocation_size(options.manifest_preallocation_size),
      allow_mmap_reads(options.allow_mmap_reads),
      allow_mmap_writes(options.allow_mmap_writes),
689
      use_direct_reads(options.use_direct_reads),
690 691
      use_direct_io_for_flush_and_compaction(
          options.use_direct_io_for_flush_and_compaction),
692 693 694
      allow_fallocate(options.allow_fallocate),
      is_fd_close_on_exec(options.is_fd_close_on_exec),
      advise_random_on_open(options.advise_random_on_open),
695
      experimental_mempurge_threshold(options.experimental_mempurge_threshold),
696 697 698 699 700 701 702 703 704
      db_write_buffer_size(options.db_write_buffer_size),
      write_buffer_manager(options.write_buffer_manager),
      access_hint_on_compaction_start(options.access_hint_on_compaction_start),
      new_table_reader_for_compaction_inputs(
          options.new_table_reader_for_compaction_inputs),
      random_access_max_buffer_size(options.random_access_max_buffer_size),
      use_adaptive_mutex(options.use_adaptive_mutex),
      listeners(options.listeners),
      enable_thread_tracking(options.enable_thread_tracking),
705
      enable_pipelined_write(options.enable_pipelined_write),
M
Maysam Yabandeh 已提交
706
      unordered_write(options.unordered_write),
707 708 709 710 711 712
      allow_concurrent_memtable_write(options.allow_concurrent_memtable_write),
      enable_write_thread_adaptive_yield(
          options.enable_write_thread_adaptive_yield),
      write_thread_max_yield_usec(options.write_thread_max_yield_usec),
      write_thread_slow_yield_usec(options.write_thread_slow_yield_usec),
      skip_stats_update_on_db_open(options.skip_stats_update_on_db_open),
713 714
      skip_checking_sst_file_sizes_on_db_open(
          options.skip_checking_sst_file_sizes_on_db_open),
715 716 717 718 719 720 721 722
      wal_recovery_mode(options.wal_recovery_mode),
      allow_2pc(options.allow_2pc),
      row_cache(options.row_cache),
#ifndef ROCKSDB_LITE
      wal_filter(options.wal_filter),
#endif  // ROCKSDB_LITE
      fail_if_options_file_error(options.fail_if_options_file_error),
      dump_malloc_stats(options.dump_malloc_stats),
723
      avoid_flush_during_recovery(options.avoid_flush_during_recovery),
724
      allow_ingest_behind(options.allow_ingest_behind),
725
      preserve_deletes(options.preserve_deletes),
726
      two_write_queues(options.two_write_queues),
727
      manual_wal_flush(options.manual_wal_flush),
728
      atomic_flush(options.atomic_flush),
729
      avoid_unnecessary_blocking_io(options.avoid_unnecessary_blocking_io),
730
      persist_stats_to_disk(options.persist_stats_to_disk),
731
      write_dbid_to_manifest(options.write_dbid_to_manifest),
732
      log_readahead_size(options.log_readahead_size),
733
      file_checksum_gen_factory(options.file_checksum_gen_factory),
734 735
      best_efforts_recovery(options.best_efforts_recovery),
      max_bgerror_resume_count(options.max_bgerror_resume_count),
736
      bgerror_resume_retry_interval(options.bgerror_resume_retry_interval),
737
      allow_data_in_errors(options.allow_data_in_errors),
738
      db_host_id(options.db_host_id),
739
      checksum_handoff_file_types(options.checksum_handoff_file_types),
740
      lowest_used_cache_tier(options.lowest_used_cache_tier),
741
      compaction_service(options.compaction_service) {
742
  stats = statistics.get();
743
  fs = env->GetFileSystem();
744 745 746 747 748
  if (env != nullptr) {
    clock = env->GetSystemClock().get();
  } else {
    clock = SystemClock::Default().get();
  }
749 750
  logger = info_log.get();
  stats = statistics.get();
751 752 753
}

void ImmutableDBOptions::Dump(Logger* log) const {
754 755 756 757 758 759
  ROCKS_LOG_HEADER(log, "                        Options.error_if_exists: %d",
                   error_if_exists);
  ROCKS_LOG_HEADER(log, "                      Options.create_if_missing: %d",
                   create_if_missing);
  ROCKS_LOG_HEADER(log, "                        Options.paranoid_checks: %d",
                   paranoid_checks);
760 761
  ROCKS_LOG_HEADER(log, "            Options.flush_verify_memtable_count: %d",
                   flush_verify_memtable_count);
762 763 764 765
  ROCKS_LOG_HEADER(log,
                   "                              "
                   "Options.track_and_verify_wals_in_manifest: %d",
                   track_and_verify_wals_in_manifest);
766 767
  ROCKS_LOG_HEADER(log, "                                    Options.env: %p",
                   env);
768 769
  ROCKS_LOG_HEADER(log, "                                     Options.fs: %s",
                   fs->Name());
770 771 772 773
  ROCKS_LOG_HEADER(log, "                               Options.info_log: %p",
                   info_log.get());
  ROCKS_LOG_HEADER(log, "               Options.max_file_opening_threads: %d",
                   max_file_opening_threads);
774
  ROCKS_LOG_HEADER(log, "                             Options.statistics: %p",
775
                   stats);
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
  ROCKS_LOG_HEADER(log, "                              Options.use_fsync: %d",
                   use_fsync);
  ROCKS_LOG_HEADER(
      log, "                      Options.max_log_file_size: %" ROCKSDB_PRIszt,
      max_log_file_size);
  ROCKS_LOG_HEADER(log,
                   "                 Options.max_manifest_file_size: %" PRIu64,
                   max_manifest_file_size);
  ROCKS_LOG_HEADER(
      log, "                  Options.log_file_time_to_roll: %" ROCKSDB_PRIszt,
      log_file_time_to_roll);
  ROCKS_LOG_HEADER(
      log, "                      Options.keep_log_file_num: %" ROCKSDB_PRIszt,
      keep_log_file_num);
  ROCKS_LOG_HEADER(
      log, "                   Options.recycle_log_file_num: %" ROCKSDB_PRIszt,
      recycle_log_file_num);
  ROCKS_LOG_HEADER(log, "                        Options.allow_fallocate: %d",
                   allow_fallocate);
  ROCKS_LOG_HEADER(log, "                       Options.allow_mmap_reads: %d",
                   allow_mmap_reads);
  ROCKS_LOG_HEADER(log, "                      Options.allow_mmap_writes: %d",
                   allow_mmap_writes);
  ROCKS_LOG_HEADER(log, "                       Options.use_direct_reads: %d",
                   use_direct_reads);
801 802 803 804
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.use_direct_io_for_flush_and_compaction: %d",
                   use_direct_io_for_flush_and_compaction);
805 806 807 808 809 810 811 812 813 814
  ROCKS_LOG_HEADER(log, "         Options.create_missing_column_families: %d",
                   create_missing_column_families);
  ROCKS_LOG_HEADER(log, "                             Options.db_log_dir: %s",
                   db_log_dir.c_str());
  ROCKS_LOG_HEADER(log, "                                Options.wal_dir: %s",
                   wal_dir.c_str());
  ROCKS_LOG_HEADER(log, "               Options.table_cache_numshardbits: %d",
                   table_cache_numshardbits);
  ROCKS_LOG_HEADER(log,
                   "                        Options.WAL_ttl_seconds: %" PRIu64,
815
                   WAL_ttl_seconds);
816 817
  ROCKS_LOG_HEADER(log,
                   "                      Options.WAL_size_limit_MB: %" PRIu64,
818
                   WAL_size_limit_MB);
819 820 821 822
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.max_write_batch_group_size_bytes: %" PRIu64,
                   max_write_batch_group_size_bytes);
823 824 825 826 827 828 829
  ROCKS_LOG_HEADER(
      log, "            Options.manifest_preallocation_size: %" ROCKSDB_PRIszt,
      manifest_preallocation_size);
  ROCKS_LOG_HEADER(log, "                    Options.is_fd_close_on_exec: %d",
                   is_fd_close_on_exec);
  ROCKS_LOG_HEADER(log, "                  Options.advise_random_on_open: %d",
                   advise_random_on_open);
830 831 832
  ROCKS_LOG_HEADER(
      log, "                  Options.experimental_mempurge_threshold: %f",
      experimental_mempurge_threshold);
833 834 835
  ROCKS_LOG_HEADER(
      log, "                   Options.db_write_buffer_size: %" ROCKSDB_PRIszt,
      db_write_buffer_size);
836 837
  ROCKS_LOG_HEADER(log, "                   Options.write_buffer_manager: %p",
                   write_buffer_manager.get());
838 839 840 841 842 843 844 845 846 847 848
  ROCKS_LOG_HEADER(log, "        Options.access_hint_on_compaction_start: %d",
                   static_cast<int>(access_hint_on_compaction_start));
  ROCKS_LOG_HEADER(log, " Options.new_table_reader_for_compaction_inputs: %d",
                   new_table_reader_for_compaction_inputs);
  ROCKS_LOG_HEADER(
      log, "          Options.random_access_max_buffer_size: %" ROCKSDB_PRIszt,
      random_access_max_buffer_size);
  ROCKS_LOG_HEADER(log, "                     Options.use_adaptive_mutex: %d",
                   use_adaptive_mutex);
  ROCKS_LOG_HEADER(log, "                           Options.rate_limiter: %p",
                   rate_limiter.get());
849 850 851
  Header(
      log, "    Options.sst_file_manager.rate_bytes_per_sec: %" PRIi64,
      sst_file_manager ? sst_file_manager->GetDeleteRateBytesPerSecond() : 0);
852
  ROCKS_LOG_HEADER(log, "                      Options.wal_recovery_mode: %d",
853
                   static_cast<int>(wal_recovery_mode));
854 855
  ROCKS_LOG_HEADER(log, "                 Options.enable_thread_tracking: %d",
                   enable_thread_tracking);
856 857
  ROCKS_LOG_HEADER(log, "                 Options.enable_pipelined_write: %d",
                   enable_pipelined_write);
M
Maysam Yabandeh 已提交
858 859
  ROCKS_LOG_HEADER(log, "                 Options.unordered_write: %d",
                   unordered_write);
860 861 862 863 864 865 866 867 868 869
  ROCKS_LOG_HEADER(log, "        Options.allow_concurrent_memtable_write: %d",
                   allow_concurrent_memtable_write);
  ROCKS_LOG_HEADER(log, "     Options.enable_write_thread_adaptive_yield: %d",
                   enable_write_thread_adaptive_yield);
  ROCKS_LOG_HEADER(log,
                   "            Options.write_thread_max_yield_usec: %" PRIu64,
                   write_thread_max_yield_usec);
  ROCKS_LOG_HEADER(log,
                   "           Options.write_thread_slow_yield_usec: %" PRIu64,
                   write_thread_slow_yield_usec);
870
  if (row_cache) {
871
    ROCKS_LOG_HEADER(
872 873
        log,
        "                              Options.row_cache: %" ROCKSDB_PRIszt,
874
        row_cache->GetCapacity());
875
  } else {
876 877
    ROCKS_LOG_HEADER(log,
                     "                              Options.row_cache: None");
878 879
  }
#ifndef ROCKSDB_LITE
880 881
  ROCKS_LOG_HEADER(log, "                             Options.wal_filter: %s",
                   wal_filter ? wal_filter->Name() : "None");
882
#endif  // ROCKDB_LITE
883

884 885
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_recovery: %d",
                   avoid_flush_during_recovery);
886 887
  ROCKS_LOG_HEADER(log, "            Options.allow_ingest_behind: %d",
                   allow_ingest_behind);
888 889
  ROCKS_LOG_HEADER(log, "            Options.preserve_deletes: %d",
                   preserve_deletes);
890 891
  ROCKS_LOG_HEADER(log, "            Options.two_write_queues: %d",
                   two_write_queues);
892 893
  ROCKS_LOG_HEADER(log, "            Options.manual_wal_flush: %d",
                   manual_wal_flush);
894 895 896 897
  ROCKS_LOG_HEADER(log, "            Options.atomic_flush: %d", atomic_flush);
  ROCKS_LOG_HEADER(log,
                   "            Options.avoid_unnecessary_blocking_io: %d",
                   avoid_unnecessary_blocking_io);
898 899
  ROCKS_LOG_HEADER(log, "                Options.persist_stats_to_disk: %u",
                   persist_stats_to_disk);
900 901
  ROCKS_LOG_HEADER(log, "                Options.write_dbid_to_manifest: %d",
                   write_dbid_to_manifest);
902 903 904
  ROCKS_LOG_HEADER(
      log, "                Options.log_readahead_size: %" ROCKSDB_PRIszt,
      log_readahead_size);
905
  ROCKS_LOG_HEADER(log, "                Options.file_checksum_gen_factory: %s",
906 907
                   file_checksum_gen_factory ? file_checksum_gen_factory->Name()
                                             : kUnknownFileChecksumFuncName);
908 909
  ROCKS_LOG_HEADER(log, "                Options.best_efforts_recovery: %d",
                   static_cast<int>(best_efforts_recovery));
910 911 912 913 914
  ROCKS_LOG_HEADER(log, "               Options.max_bgerror_resume_count: %d",
                   max_bgerror_resume_count);
  ROCKS_LOG_HEADER(log,
                   "           Options.bgerror_resume_retry_interval: %" PRIu64,
                   bgerror_resume_retry_interval);
915 916
  ROCKS_LOG_HEADER(log, "            Options.allow_data_in_errors: %d",
                   allow_data_in_errors);
917 918
  ROCKS_LOG_HEADER(log, "            Options.db_host_id: %s",
                   db_host_id.c_str());
919 920
}

921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
bool ImmutableDBOptions::IsWalDirSameAsDBPath() const {
  assert(!db_paths.empty());
  return IsWalDirSameAsDBPath(db_paths[0].path);
}

bool ImmutableDBOptions::IsWalDirSameAsDBPath(
    const std::string& db_path) const {
  bool same = wal_dir.empty();
  if (!same) {
    Status s = env->AreFilesSame(wal_dir, db_path, &same);
    if (s.IsNotSupported()) {
      same = wal_dir == db_path;
    }
  }
  return same;
}

const std::string& ImmutableDBOptions::GetWalDir() const {
  if (wal_dir.empty()) {
    assert(!db_paths.empty());
    return db_paths[0].path;
  } else {
    return wal_dir;
  }
}

const std::string& ImmutableDBOptions::GetWalDir(
    const std::string& path) const {
  if (wal_dir.empty()) {
    return path;
  } else {
    return wal_dir;
  }
}

956
MutableDBOptions::MutableDBOptions()
957 958 959
    : max_background_jobs(2),
      base_background_compactions(-1),
      max_background_compactions(-1),
960
      max_subcompactions(0),
961
      avoid_flush_during_shutdown(false),
962
      writable_file_max_buffer_size(1024 * 1024),
963
      delayed_write_rate(2 * 1024U * 1024U),
964
      max_total_wal_size(0),
965
      delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
L
Leonidas Galanis 已提交
966
      stats_dump_period_sec(600),
967 968
      stats_persist_period_sec(600),
      stats_history_buffer_size(1024 * 1024),
969 970
      max_open_files(-1),
      bytes_per_sync(0),
971
      wal_bytes_per_sync(0),
972
      strict_bytes_per_sync(false),
973 974
      compaction_readahead_size(0),
      max_background_flushes(-1) {}
975 976

MutableDBOptions::MutableDBOptions(const DBOptions& options)
977 978
    : max_background_jobs(options.max_background_jobs),
      base_background_compactions(options.base_background_compactions),
Y
Yi Wu 已提交
979
      max_background_compactions(options.max_background_compactions),
980
      max_subcompactions(options.max_subcompactions),
981
      avoid_flush_during_shutdown(options.avoid_flush_during_shutdown),
982
      writable_file_max_buffer_size(options.writable_file_max_buffer_size),
983
      delayed_write_rate(options.delayed_write_rate),
984 985
      max_total_wal_size(options.max_total_wal_size),
      delete_obsolete_files_period_micros(
986
          options.delete_obsolete_files_period_micros),
L
Leonidas Galanis 已提交
987
      stats_dump_period_sec(options.stats_dump_period_sec),
988 989
      stats_persist_period_sec(options.stats_persist_period_sec),
      stats_history_buffer_size(options.stats_history_buffer_size),
990 991
      max_open_files(options.max_open_files),
      bytes_per_sync(options.bytes_per_sync),
992
      wal_bytes_per_sync(options.wal_bytes_per_sync),
993
      strict_bytes_per_sync(options.strict_bytes_per_sync),
994 995
      compaction_readahead_size(options.compaction_readahead_size),
      max_background_flushes(options.max_background_flushes) {}
996

997
void MutableDBOptions::Dump(Logger* log) const {
998 999
  ROCKS_LOG_HEADER(log, "            Options.max_background_jobs: %d",
                   max_background_jobs);
1000 1001
  ROCKS_LOG_HEADER(log, "            Options.max_background_compactions: %d",
                   max_background_compactions);
1002 1003
  ROCKS_LOG_HEADER(log, "            Options.max_subcompactions: %" PRIu32,
                   max_subcompactions);
1004 1005
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_shutdown: %d",
                   avoid_flush_during_shutdown);
1006 1007 1008
  ROCKS_LOG_HEADER(
      log, "          Options.writable_file_max_buffer_size: %" ROCKSDB_PRIszt,
      writable_file_max_buffer_size);
1009 1010 1011 1012 1013 1014 1015
  ROCKS_LOG_HEADER(log, "            Options.delayed_write_rate : %" PRIu64,
                   delayed_write_rate);
  ROCKS_LOG_HEADER(log, "            Options.max_total_wal_size: %" PRIu64,
                   max_total_wal_size);
  ROCKS_LOG_HEADER(
      log, "            Options.delete_obsolete_files_period_micros: %" PRIu64,
      delete_obsolete_files_period_micros);
1016 1017
  ROCKS_LOG_HEADER(log, "                  Options.stats_dump_period_sec: %u",
                   stats_dump_period_sec);
1018 1019
  ROCKS_LOG_HEADER(log, "                Options.stats_persist_period_sec: %d",
                   stats_persist_period_sec);
1020 1021 1022 1023
  ROCKS_LOG_HEADER(
      log,
      "                Options.stats_history_buffer_size: %" ROCKSDB_PRIszt,
      stats_history_buffer_size);
L
Leonidas Galanis 已提交
1024 1025
  ROCKS_LOG_HEADER(log, "                         Options.max_open_files: %d",
                   max_open_files);
1026 1027 1028 1029 1030 1031
  ROCKS_LOG_HEADER(log,
                   "                         Options.bytes_per_sync: %" PRIu64,
                   bytes_per_sync);
  ROCKS_LOG_HEADER(log,
                   "                     Options.wal_bytes_per_sync: %" PRIu64,
                   wal_bytes_per_sync);
1032 1033 1034
  ROCKS_LOG_HEADER(log,
                   "                  Options.strict_bytes_per_sync: %d",
                   strict_bytes_per_sync);
1035 1036 1037
  ROCKS_LOG_HEADER(log,
                   "      Options.compaction_readahead_size: %" ROCKSDB_PRIszt,
                   compaction_readahead_size);
1038 1039
  ROCKS_LOG_HEADER(log, "                 Options.max_background_flushes: %d",
                          max_background_flushes);
1040
}
1041

1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
#ifndef ROCKSDB_LITE
Status GetMutableDBOptionsFromStrings(
    const MutableDBOptions& base_options,
    const std::unordered_map<std::string, std::string>& options_map,
    MutableDBOptions* new_options) {
  assert(new_options);
  *new_options = base_options;
  ConfigOptions config_options;
  Status s = OptionTypeInfo::ParseType(
      config_options, options_map, db_mutable_options_type_info, new_options);
  if (!s.ok()) {
    *new_options = base_options;
  }
  return s;
}

1058 1059 1060 1061 1062 1063 1064 1065 1066
bool MutableDBOptionsAreEqual(const MutableDBOptions& this_options,
                              const MutableDBOptions& that_options) {
  ConfigOptions config_options;
  std::string mismatch;
  return OptionTypeInfo::StructsAreEqual(
      config_options, "MutableDBOptions", &db_mutable_options_type_info,
      "MutableDBOptions", &this_options, &that_options, &mismatch);
}

1067 1068 1069 1070 1071 1072 1073
Status GetStringFromMutableDBOptions(const ConfigOptions& config_options,
                                     const MutableDBOptions& mutable_opts,
                                     std::string* opt_string) {
  return OptionTypeInfo::SerializeType(
      config_options, db_mutable_options_type_info, &mutable_opts, opt_string);
}
#endif  // ROCKSDB_LITE
1074
}  // namespace ROCKSDB_NAMESPACE