db_options.cc 36.4 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 "db/version_edit.h"
11
#include "logging/logging.h"
12
#include "options/options_helper.h"
13 14 15
#include "port/port.h"
#include "rocksdb/cache.h"
#include "rocksdb/env.h"
16
#include "rocksdb/file_system.h"
17
#include "rocksdb/rate_limiter.h"
18 19 20
#include "rocksdb/sst_file_manager.h"
#include "rocksdb/wal_filter.h"

21
namespace ROCKSDB_NAMESPACE {
22
#ifndef ROCKSDB_LITE
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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}};

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}};

46 47 48 49 50 51 52 53 54 55 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
std::unordered_map<std::string, OptionTypeInfo>
    OptionsHelper::db_options_type_info = {
        /*
         // 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;
          std::vector<std::shared_ptr<EventListener>> listeners;
         */
        {"advise_random_on_open",
         {offsetof(struct DBOptions, advise_random_on_open),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"allow_mmap_reads",
         {offsetof(struct DBOptions, allow_mmap_reads), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"allow_fallocate",
         {offsetof(struct DBOptions, allow_fallocate), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"allow_mmap_writes",
         {offsetof(struct DBOptions, allow_mmap_writes), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"use_direct_reads",
         {offsetof(struct DBOptions, use_direct_reads), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"use_direct_writes",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone, 0}},
        {"use_direct_io_for_flush_and_compaction",
         {offsetof(struct DBOptions, use_direct_io_for_flush_and_compaction),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"allow_2pc",
         {offsetof(struct DBOptions, allow_2pc), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"allow_os_buffer",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kMutable, 0}},
        {"create_if_missing",
         {offsetof(struct DBOptions, create_if_missing), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"create_missing_column_families",
         {offsetof(struct DBOptions, create_missing_column_families),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"disableDataSync",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone, 0}},
        {"disable_data_sync",  // for compatibility
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone, 0}},
        {"enable_thread_tracking",
         {offsetof(struct DBOptions, enable_thread_tracking),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"error_if_exists",
         {offsetof(struct DBOptions, error_if_exists), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"is_fd_close_on_exec",
         {offsetof(struct DBOptions, is_fd_close_on_exec), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"paranoid_checks",
         {offsetof(struct DBOptions, paranoid_checks), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"skip_log_error_on_recovery",
         {offsetof(struct DBOptions, skip_log_error_on_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"skip_stats_update_on_db_open",
         {offsetof(struct DBOptions, skip_stats_update_on_db_open),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"skip_checking_sst_file_sizes_on_db_open",
         {offsetof(struct DBOptions, skip_checking_sst_file_sizes_on_db_open),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"new_table_reader_for_compaction_inputs",
         {offsetof(struct DBOptions, new_table_reader_for_compaction_inputs),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"compaction_readahead_size",
         {offsetof(struct DBOptions, compaction_readahead_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, compaction_readahead_size)}},
        {"random_access_max_buffer_size",
         {offsetof(struct DBOptions, random_access_max_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"use_adaptive_mutex",
         {offsetof(struct DBOptions, use_adaptive_mutex), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"use_fsync",
         {offsetof(struct DBOptions, use_fsync), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"max_background_jobs",
         {offsetof(struct DBOptions, max_background_jobs), OptionType::kInt,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, max_background_jobs)}},
        {"max_background_compactions",
         {offsetof(struct DBOptions, max_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, max_background_compactions)}},
        {"base_background_compactions",
         {offsetof(struct DBOptions, base_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, base_background_compactions)}},
        {"max_background_flushes",
         {offsetof(struct DBOptions, max_background_flushes), OptionType::kInt,
160 161
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, max_background_flushes)}},
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        {"max_file_opening_threads",
         {offsetof(struct DBOptions, max_file_opening_threads),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"max_open_files",
         {offsetof(struct DBOptions, max_open_files), OptionType::kInt,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, max_open_files)}},
        {"table_cache_numshardbits",
         {offsetof(struct DBOptions, table_cache_numshardbits),
          OptionType::kInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"db_write_buffer_size",
         {offsetof(struct DBOptions, db_write_buffer_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"keep_log_file_num",
         {offsetof(struct DBOptions, keep_log_file_num), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"recycle_log_file_num",
         {offsetof(struct DBOptions, recycle_log_file_num), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"log_file_time_to_roll",
         {offsetof(struct DBOptions, log_file_time_to_roll), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"manifest_preallocation_size",
         {offsetof(struct DBOptions, manifest_preallocation_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"max_log_file_size",
         {offsetof(struct DBOptions, max_log_file_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"db_log_dir",
         {offsetof(struct DBOptions, db_log_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"wal_dir",
         {offsetof(struct DBOptions, wal_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"max_subcompactions",
         {offsetof(struct DBOptions, max_subcompactions), OptionType::kUInt32T,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"WAL_size_limit_MB",
         {offsetof(struct DBOptions, WAL_size_limit_MB), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"WAL_ttl_seconds",
         {offsetof(struct DBOptions, WAL_ttl_seconds), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"bytes_per_sync",
         {offsetof(struct DBOptions, bytes_per_sync), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, bytes_per_sync)}},
        {"delayed_write_rate",
         {offsetof(struct DBOptions, delayed_write_rate), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, delayed_write_rate)}},
        {"delete_obsolete_files_period_micros",
         {offsetof(struct DBOptions, delete_obsolete_files_period_micros),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions,
                   delete_obsolete_files_period_micros)}},
        {"max_manifest_file_size",
         {offsetof(struct DBOptions, max_manifest_file_size),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"max_total_wal_size",
         {offsetof(struct DBOptions, max_total_wal_size), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, max_total_wal_size)}},
        {"wal_bytes_per_sync",
         {offsetof(struct DBOptions, wal_bytes_per_sync), OptionType::kUInt64T,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, wal_bytes_per_sync)}},
        {"strict_bytes_per_sync",
         {offsetof(struct DBOptions, strict_bytes_per_sync),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, strict_bytes_per_sync)}},
        {"stats_dump_period_sec",
         {offsetof(struct DBOptions, stats_dump_period_sec), OptionType::kUInt,
          OptionVerificationType::kNormal, OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, stats_dump_period_sec)}},
        {"stats_persist_period_sec",
         {offsetof(struct DBOptions, stats_persist_period_sec),
          OptionType::kUInt, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, stats_persist_period_sec)}},
        {"persist_stats_to_disk",
         {offsetof(struct DBOptions, persist_stats_to_disk),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, persist_stats_to_disk)}},
        {"stats_history_buffer_size",
         {offsetof(struct DBOptions, stats_history_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, stats_history_buffer_size)}},
        {"fail_if_options_file_error",
         {offsetof(struct DBOptions, fail_if_options_file_error),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"enable_pipelined_write",
         {offsetof(struct DBOptions, enable_pipelined_write),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"unordered_write",
         {offsetof(struct DBOptions, unordered_write), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"allow_concurrent_memtable_write",
         {offsetof(struct DBOptions, allow_concurrent_memtable_write),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
273 274 275
        {"wal_recovery_mode", OptionTypeInfo::Enum<WALRecoveryMode>(
                                  offsetof(struct DBOptions, wal_recovery_mode),
                                  &wal_recovery_mode_string_map)},
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
        {"enable_write_thread_adaptive_yield",
         {offsetof(struct DBOptions, enable_write_thread_adaptive_yield),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"write_thread_slow_yield_usec",
         {offsetof(struct DBOptions, write_thread_slow_yield_usec),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"max_write_batch_group_size_bytes",
         {offsetof(struct DBOptions, max_write_batch_group_size_bytes),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"write_thread_max_yield_usec",
         {offsetof(struct DBOptions, write_thread_max_yield_usec),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"access_hint_on_compaction_start",
293 294 295 296 297 298
         OptionTypeInfo::Enum<DBOptions::AccessHint>(
             offsetof(struct DBOptions, access_hint_on_compaction_start),
             &access_hint_string_map)},
        {"info_log_level", OptionTypeInfo::Enum<InfoLogLevel>(
                               offsetof(struct DBOptions, info_log_level),
                               &info_log_level_string_map)},
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
        {"dump_malloc_stats",
         {offsetof(struct DBOptions, dump_malloc_stats), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"avoid_flush_during_recovery",
         {offsetof(struct DBOptions, avoid_flush_during_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"avoid_flush_during_shutdown",
         {offsetof(struct DBOptions, avoid_flush_during_shutdown),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, avoid_flush_during_shutdown)}},
        {"writable_file_max_buffer_size",
         {offsetof(struct DBOptions, writable_file_max_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kMutable,
          offsetof(struct MutableDBOptions, writable_file_max_buffer_size)}},
        {"allow_ingest_behind",
         {offsetof(struct DBOptions, allow_ingest_behind), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, allow_ingest_behind)}},
        {"preserve_deletes",
         {offsetof(struct DBOptions, preserve_deletes), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, preserve_deletes)}},
        {"concurrent_prepare",  // Deprecated by two_write_queues
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone, 0}},
        {"two_write_queues",
         {offsetof(struct DBOptions, two_write_queues), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, two_write_queues)}},
        {"manual_wal_flush",
         {offsetof(struct DBOptions, manual_wal_flush), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, manual_wal_flush)}},
        {"seq_per_batch",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone, 0}},
        {"atomic_flush",
         {offsetof(struct DBOptions, atomic_flush), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, atomic_flush)}},
        {"avoid_unnecessary_blocking_io",
         {offsetof(struct DBOptions, avoid_unnecessary_blocking_io),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone,
          offsetof(struct ImmutableDBOptions, avoid_unnecessary_blocking_io)}},
        {"write_dbid_to_manifest",
         {offsetof(struct DBOptions, write_dbid_to_manifest),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
        {"log_readahead_size",
         {offsetof(struct DBOptions, log_readahead_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
        {"best_efforts_recovery",
         {offsetof(struct DBOptions, best_efforts_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone, 0}},
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
        // 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",
         {offsetof(struct DBOptions, rate_limiter), OptionType::kUnknown,
          OptionVerificationType::kNormal,
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever), 0,
          // Parse the input value as a RateLimiter
          [](const ConfigOptions& /*opts*/, const std::string& /*name*/,
             const std::string& value, char* addr) {
            auto limiter =
                reinterpret_cast<std::shared_ptr<RateLimiter>*>(addr);
            limiter->reset(NewGenericRateLimiter(
                static_cast<int64_t>(ParseUint64(value))));
            return Status::OK();
          }}},
        {"env",
         {offsetof(struct DBOptions, env), OptionType::kUnknown,
          OptionVerificationType::kNormal,
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever), 0,
          // Parse the input value as an Env
          [](const ConfigOptions& /*opts*/, const std::string& /*name*/,
             const std::string& value, char* addr) {
            auto old_env = reinterpret_cast<Env**>(addr);  // Get the old value
            Env* new_env = *old_env;                       // Set new to old
            Status s = Env::LoadEnv(value, &new_env);      // Update new value
            if (s.ok()) {                                  // It worked
              *old_env = new_env;                          // Update the old one
            }
            return s;
          }}},
389 390
};
#endif  // ROCKSDB_LITE
391 392 393 394 395 396 397 398 399

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),
      env(options.env),
400
      fs(options.env->GetFileSystem()),
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
      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_subcompactions(options.max_subcompactions),
      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),
      wal_ttl_seconds(options.WAL_ttl_seconds),
      wal_size_limit_mb(options.WAL_size_limit_MB),
420 421
      max_write_batch_group_size_bytes(
          options.max_write_batch_group_size_bytes),
422 423 424
      manifest_preallocation_size(options.manifest_preallocation_size),
      allow_mmap_reads(options.allow_mmap_reads),
      allow_mmap_writes(options.allow_mmap_writes),
425
      use_direct_reads(options.use_direct_reads),
426 427
      use_direct_io_for_flush_and_compaction(
          options.use_direct_io_for_flush_and_compaction),
428 429 430 431 432 433 434 435 436 437 438 439
      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),
      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),
440
      enable_pipelined_write(options.enable_pipelined_write),
M
Maysam Yabandeh 已提交
441
      unordered_write(options.unordered_write),
442 443 444 445 446 447
      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),
448 449
      skip_checking_sst_file_sizes_on_db_open(
          options.skip_checking_sst_file_sizes_on_db_open),
450 451 452 453 454 455 456 457
      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),
458
      avoid_flush_during_recovery(options.avoid_flush_during_recovery),
459
      allow_ingest_behind(options.allow_ingest_behind),
460
      preserve_deletes(options.preserve_deletes),
461
      two_write_queues(options.two_write_queues),
462
      manual_wal_flush(options.manual_wal_flush),
463
      atomic_flush(options.atomic_flush),
464
      avoid_unnecessary_blocking_io(options.avoid_unnecessary_blocking_io),
465
      persist_stats_to_disk(options.persist_stats_to_disk),
466
      write_dbid_to_manifest(options.write_dbid_to_manifest),
467
      log_readahead_size(options.log_readahead_size),
468
      file_checksum_gen_factory(options.file_checksum_gen_factory),
469
      best_efforts_recovery(options.best_efforts_recovery) {
470 471 472
}

void ImmutableDBOptions::Dump(Logger* log) const {
473 474 475 476 477 478 479 480
  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);
  ROCKS_LOG_HEADER(log, "                                    Options.env: %p",
                   env);
481 482
  ROCKS_LOG_HEADER(log, "                                     Options.fs: %s",
                   fs->Name());
483 484 485 486
  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);
487 488
  ROCKS_LOG_HEADER(log, "                             Options.statistics: %p",
                   statistics.get());
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
  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);
514 515 516 517
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.use_direct_io_for_flush_and_compaction: %d",
                   use_direct_io_for_flush_and_compaction);
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
  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.max_subcompactions: %" PRIu32,
                   max_subcompactions);
  ROCKS_LOG_HEADER(log,
                   "                        Options.WAL_ttl_seconds: %" PRIu64,
                   wal_ttl_seconds);
  ROCKS_LOG_HEADER(log,
                   "                      Options.WAL_size_limit_MB: %" PRIu64,
                   wal_size_limit_mb);
535 536 537 538
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.max_write_batch_group_size_bytes: %" PRIu64,
                   max_write_batch_group_size_bytes);
539 540 541 542 543 544 545 546 547 548
  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);
  ROCKS_LOG_HEADER(
      log, "                   Options.db_write_buffer_size: %" ROCKSDB_PRIszt,
      db_write_buffer_size);
549 550
  ROCKS_LOG_HEADER(log, "                   Options.write_buffer_manager: %p",
                   write_buffer_manager.get());
551 552 553 554 555 556 557 558 559 560 561
  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());
562 563 564
  Header(
      log, "    Options.sst_file_manager.rate_bytes_per_sec: %" PRIi64,
      sst_file_manager ? sst_file_manager->GetDeleteRateBytesPerSecond() : 0);
565
  ROCKS_LOG_HEADER(log, "                      Options.wal_recovery_mode: %d",
566
                   static_cast<int>(wal_recovery_mode));
567 568
  ROCKS_LOG_HEADER(log, "                 Options.enable_thread_tracking: %d",
                   enable_thread_tracking);
569 570
  ROCKS_LOG_HEADER(log, "                 Options.enable_pipelined_write: %d",
                   enable_pipelined_write);
M
Maysam Yabandeh 已提交
571 572
  ROCKS_LOG_HEADER(log, "                 Options.unordered_write: %d",
                   unordered_write);
573 574 575 576 577 578 579 580 581 582
  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);
583
  if (row_cache) {
584
    ROCKS_LOG_HEADER(
585 586
        log,
        "                              Options.row_cache: %" ROCKSDB_PRIszt,
587
        row_cache->GetCapacity());
588
  } else {
589 590
    ROCKS_LOG_HEADER(log,
                     "                              Options.row_cache: None");
591 592
  }
#ifndef ROCKSDB_LITE
593 594
  ROCKS_LOG_HEADER(log, "                             Options.wal_filter: %s",
                   wal_filter ? wal_filter->Name() : "None");
595
#endif  // ROCKDB_LITE
596

597 598
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_recovery: %d",
                   avoid_flush_during_recovery);
599 600
  ROCKS_LOG_HEADER(log, "            Options.allow_ingest_behind: %d",
                   allow_ingest_behind);
601 602
  ROCKS_LOG_HEADER(log, "            Options.preserve_deletes: %d",
                   preserve_deletes);
603 604
  ROCKS_LOG_HEADER(log, "            Options.two_write_queues: %d",
                   two_write_queues);
605 606
  ROCKS_LOG_HEADER(log, "            Options.manual_wal_flush: %d",
                   manual_wal_flush);
607 608 609 610
  ROCKS_LOG_HEADER(log, "            Options.atomic_flush: %d", atomic_flush);
  ROCKS_LOG_HEADER(log,
                   "            Options.avoid_unnecessary_blocking_io: %d",
                   avoid_unnecessary_blocking_io);
611 612
  ROCKS_LOG_HEADER(log, "                Options.persist_stats_to_disk: %u",
                   persist_stats_to_disk);
613 614
  ROCKS_LOG_HEADER(log, "                Options.write_dbid_to_manifest: %d",
                   write_dbid_to_manifest);
615 616 617
  ROCKS_LOG_HEADER(
      log, "                Options.log_readahead_size: %" ROCKSDB_PRIszt,
      log_readahead_size);
618 619 620
  ROCKS_LOG_HEADER(log, "                Options.file_checksum_gen_factory: %s",
                   file_checksum_gen_factory
                       ? file_checksum_gen_factory->Name()
621
                       : kUnknownFileChecksumFuncName.c_str());
622 623
  ROCKS_LOG_HEADER(log, "                Options.best_efforts_recovery: %d",
                   static_cast<int>(best_efforts_recovery));
624 625
}

626
MutableDBOptions::MutableDBOptions()
627 628 629
    : max_background_jobs(2),
      base_background_compactions(-1),
      max_background_compactions(-1),
630
      avoid_flush_during_shutdown(false),
631
      writable_file_max_buffer_size(1024 * 1024),
632
      delayed_write_rate(2 * 1024U * 1024U),
633
      max_total_wal_size(0),
634
      delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
L
Leonidas Galanis 已提交
635
      stats_dump_period_sec(600),
636 637
      stats_persist_period_sec(600),
      stats_history_buffer_size(1024 * 1024),
638 639
      max_open_files(-1),
      bytes_per_sync(0),
640
      wal_bytes_per_sync(0),
641
      strict_bytes_per_sync(false),
642 643
      compaction_readahead_size(0),
      max_background_flushes(-1) {}
644 645

MutableDBOptions::MutableDBOptions(const DBOptions& options)
646 647
    : max_background_jobs(options.max_background_jobs),
      base_background_compactions(options.base_background_compactions),
Y
Yi Wu 已提交
648
      max_background_compactions(options.max_background_compactions),
649
      avoid_flush_during_shutdown(options.avoid_flush_during_shutdown),
650
      writable_file_max_buffer_size(options.writable_file_max_buffer_size),
651
      delayed_write_rate(options.delayed_write_rate),
652 653
      max_total_wal_size(options.max_total_wal_size),
      delete_obsolete_files_period_micros(
654
          options.delete_obsolete_files_period_micros),
L
Leonidas Galanis 已提交
655
      stats_dump_period_sec(options.stats_dump_period_sec),
656 657
      stats_persist_period_sec(options.stats_persist_period_sec),
      stats_history_buffer_size(options.stats_history_buffer_size),
658 659
      max_open_files(options.max_open_files),
      bytes_per_sync(options.bytes_per_sync),
660
      wal_bytes_per_sync(options.wal_bytes_per_sync),
661
      strict_bytes_per_sync(options.strict_bytes_per_sync),
662 663
      compaction_readahead_size(options.compaction_readahead_size),
      max_background_flushes(options.max_background_flushes) {}
664

665
void MutableDBOptions::Dump(Logger* log) const {
666 667
  ROCKS_LOG_HEADER(log, "            Options.max_background_jobs: %d",
                   max_background_jobs);
668 669 670 671
  ROCKS_LOG_HEADER(log, "            Options.max_background_compactions: %d",
                   max_background_compactions);
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_shutdown: %d",
                   avoid_flush_during_shutdown);
672 673 674
  ROCKS_LOG_HEADER(
      log, "          Options.writable_file_max_buffer_size: %" ROCKSDB_PRIszt,
      writable_file_max_buffer_size);
675 676 677 678 679 680 681
  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);
682 683
  ROCKS_LOG_HEADER(log, "                  Options.stats_dump_period_sec: %u",
                   stats_dump_period_sec);
684 685
  ROCKS_LOG_HEADER(log, "                Options.stats_persist_period_sec: %d",
                   stats_persist_period_sec);
686 687 688 689
  ROCKS_LOG_HEADER(
      log,
      "                Options.stats_history_buffer_size: %" ROCKSDB_PRIszt,
      stats_history_buffer_size);
L
Leonidas Galanis 已提交
690 691
  ROCKS_LOG_HEADER(log, "                         Options.max_open_files: %d",
                   max_open_files);
692 693 694 695 696 697
  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);
698 699 700
  ROCKS_LOG_HEADER(log,
                   "                  Options.strict_bytes_per_sync: %d",
                   strict_bytes_per_sync);
701 702 703
  ROCKS_LOG_HEADER(log,
                   "      Options.compaction_readahead_size: %" ROCKSDB_PRIszt,
                   compaction_readahead_size);
704 705
  ROCKS_LOG_HEADER(log, "                 Options.max_background_flushes: %d",
                          max_background_flushes);
706
}
707

708
}  // namespace ROCKSDB_NAMESPACE