db_options.cc 39.6 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/rate_limiter.h"
19
#include "rocksdb/sst_file_manager.h"
20
#include "rocksdb/utilities/options_type.h"
21
#include "rocksdb/wal_filter.h"
22
#include "util/string_util.h"
23

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

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
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 = {
130 131 132 133 134 135 136 137 138 139 140
        /*
         // 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",
141
         {offsetof(struct ImmutableDBOptions, advise_random_on_open),
142
          OptionType::kBoolean, OptionVerificationType::kNormal,
143
          OptionTypeFlags::kNone}},
144
        {"allow_mmap_reads",
145 146 147
         {offsetof(struct ImmutableDBOptions, allow_mmap_reads),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
148
        {"allow_fallocate",
149 150 151
         {offsetof(struct ImmutableDBOptions, allow_fallocate),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
152
        {"allow_mmap_writes",
153 154 155
         {offsetof(struct ImmutableDBOptions, allow_mmap_writes),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
156
        {"use_direct_reads",
157 158 159
         {offsetof(struct ImmutableDBOptions, use_direct_reads),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
160 161
        {"use_direct_writes",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
162
          OptionTypeFlags::kNone}},
163
        {"use_direct_io_for_flush_and_compaction",
164 165
         {offsetof(struct ImmutableDBOptions,
                   use_direct_io_for_flush_and_compaction),
166
          OptionType::kBoolean, OptionVerificationType::kNormal,
167
          OptionTypeFlags::kNone}},
168
        {"allow_2pc",
169 170
         {offsetof(struct ImmutableDBOptions, allow_2pc), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
171
        {"create_if_missing",
172 173 174
         {offsetof(struct ImmutableDBOptions, create_if_missing),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
175
        {"create_missing_column_families",
176
         {offsetof(struct ImmutableDBOptions, create_missing_column_families),
177
          OptionType::kBoolean, OptionVerificationType::kNormal,
178
          OptionTypeFlags::kNone}},
179 180
        {"disableDataSync",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
181
          OptionTypeFlags::kNone}},
182 183
        {"disable_data_sync",  // for compatibility
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
184
          OptionTypeFlags::kNone}},
185
        {"enable_thread_tracking",
186
         {offsetof(struct ImmutableDBOptions, enable_thread_tracking),
187
          OptionType::kBoolean, OptionVerificationType::kNormal,
188
          OptionTypeFlags::kNone}},
189
        {"error_if_exists",
190 191 192
         {offsetof(struct ImmutableDBOptions, error_if_exists),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
193
        {"is_fd_close_on_exec",
194 195 196
         {offsetof(struct ImmutableDBOptions, is_fd_close_on_exec),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
197
        {"paranoid_checks",
198
         {offsetof(struct ImmutableDBOptions, paranoid_checks),
199
          OptionType::kBoolean, OptionVerificationType::kNormal,
200
          OptionTypeFlags::kNone}},
201 202 203 204 205
        {"track_and_verify_wals_in_manifest",
         {offsetof(struct ImmutableDBOptions,
                   track_and_verify_wals_in_manifest),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
206 207 208
        {"skip_log_error_on_recovery",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
          OptionTypeFlags::kNone}},
209
        {"skip_stats_update_on_db_open",
210
         {offsetof(struct ImmutableDBOptions, skip_stats_update_on_db_open),
211
          OptionType::kBoolean, OptionVerificationType::kNormal,
212
          OptionTypeFlags::kNone}},
213
        {"skip_checking_sst_file_sizes_on_db_open",
214 215
         {offsetof(struct ImmutableDBOptions,
                   skip_checking_sst_file_sizes_on_db_open),
216
          OptionType::kBoolean, OptionVerificationType::kNormal,
217
          OptionTypeFlags::kNone}},
218
        {"new_table_reader_for_compaction_inputs",
219 220
         {offsetof(struct ImmutableDBOptions,
                   new_table_reader_for_compaction_inputs),
221
          OptionType::kBoolean, OptionVerificationType::kNormal,
222
          OptionTypeFlags::kNone}},
223
        {"random_access_max_buffer_size",
224
         {offsetof(struct ImmutableDBOptions, random_access_max_buffer_size),
225
          OptionType::kSizeT, OptionVerificationType::kNormal,
226
          OptionTypeFlags::kNone}},
227
        {"use_adaptive_mutex",
228 229 230
         {offsetof(struct ImmutableDBOptions, use_adaptive_mutex),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
231
        {"use_fsync",
232 233
         {offsetof(struct ImmutableDBOptions, use_fsync), OptionType::kBoolean,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
234
        {"max_file_opening_threads",
235
         {offsetof(struct ImmutableDBOptions, max_file_opening_threads),
236
          OptionType::kInt, OptionVerificationType::kNormal,
237
          OptionTypeFlags::kNone}},
238
        {"table_cache_numshardbits",
239
         {offsetof(struct ImmutableDBOptions, table_cache_numshardbits),
240
          OptionType::kInt, OptionVerificationType::kNormal,
241
          OptionTypeFlags::kNone}},
242
        {"db_write_buffer_size",
243 244 245
         {offsetof(struct ImmutableDBOptions, db_write_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
246
        {"keep_log_file_num",
247 248 249
         {offsetof(struct ImmutableDBOptions, keep_log_file_num),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
250
        {"recycle_log_file_num",
251 252 253
         {offsetof(struct ImmutableDBOptions, recycle_log_file_num),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
254
        {"log_file_time_to_roll",
255 256 257
         {offsetof(struct ImmutableDBOptions, log_file_time_to_roll),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
258
        {"manifest_preallocation_size",
259
         {offsetof(struct ImmutableDBOptions, manifest_preallocation_size),
260
          OptionType::kSizeT, OptionVerificationType::kNormal,
261
          OptionTypeFlags::kNone}},
262
        {"max_log_file_size",
263 264 265
         {offsetof(struct ImmutableDBOptions, max_log_file_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
266
        {"db_log_dir",
267 268
         {offsetof(struct ImmutableDBOptions, db_log_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
269
        {"wal_dir",
270 271
         {offsetof(struct ImmutableDBOptions, wal_dir), OptionType::kString,
          OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
272
        {"WAL_size_limit_MB",
273 274 275
         {offsetof(struct ImmutableDBOptions, wal_size_limit_mb),
          OptionType::kUInt64T, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
276
        {"WAL_ttl_seconds",
277
         {offsetof(struct ImmutableDBOptions, wal_ttl_seconds),
278
          OptionType::kUInt64T, OptionVerificationType::kNormal,
279
          OptionTypeFlags::kNone}},
280
        {"max_manifest_file_size",
281
         {offsetof(struct ImmutableDBOptions, max_manifest_file_size),
282
          OptionType::kUInt64T, OptionVerificationType::kNormal,
283
          OptionTypeFlags::kNone}},
284
        {"persist_stats_to_disk",
285
         {offsetof(struct ImmutableDBOptions, persist_stats_to_disk),
286
          OptionType::kBoolean, OptionVerificationType::kNormal,
287
          OptionTypeFlags::kNone}},
288
        {"fail_if_options_file_error",
289
         {offsetof(struct ImmutableDBOptions, fail_if_options_file_error),
290
          OptionType::kBoolean, OptionVerificationType::kNormal,
291
          OptionTypeFlags::kNone}},
292
        {"enable_pipelined_write",
293
         {offsetof(struct ImmutableDBOptions, enable_pipelined_write),
294
          OptionType::kBoolean, OptionVerificationType::kNormal,
295
          OptionTypeFlags::kNone}},
296
        {"unordered_write",
297 298 299
         {offsetof(struct ImmutableDBOptions, unordered_write),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
300
        {"allow_concurrent_memtable_write",
301
         {offsetof(struct ImmutableDBOptions, allow_concurrent_memtable_write),
302
          OptionType::kBoolean, OptionVerificationType::kNormal,
303 304 305 306 307
          OptionTypeFlags::kNone}},
        {"wal_recovery_mode",
         OptionTypeInfo::Enum<WALRecoveryMode>(
             offsetof(struct ImmutableDBOptions, wal_recovery_mode),
             &wal_recovery_mode_string_map)},
308
        {"enable_write_thread_adaptive_yield",
309 310
         {offsetof(struct ImmutableDBOptions,
                   enable_write_thread_adaptive_yield),
311
          OptionType::kBoolean, OptionVerificationType::kNormal,
312
          OptionTypeFlags::kNone}},
313
        {"write_thread_slow_yield_usec",
314
         {offsetof(struct ImmutableDBOptions, write_thread_slow_yield_usec),
315
          OptionType::kUInt64T, OptionVerificationType::kNormal,
316
          OptionTypeFlags::kNone}},
317
        {"max_write_batch_group_size_bytes",
318
         {offsetof(struct ImmutableDBOptions, max_write_batch_group_size_bytes),
319
          OptionType::kUInt64T, OptionVerificationType::kNormal,
320
          OptionTypeFlags::kNone}},
321
        {"write_thread_max_yield_usec",
322
         {offsetof(struct ImmutableDBOptions, write_thread_max_yield_usec),
323
          OptionType::kUInt64T, OptionVerificationType::kNormal,
324
          OptionTypeFlags::kNone}},
325
        {"access_hint_on_compaction_start",
326
         OptionTypeInfo::Enum<DBOptions::AccessHint>(
327 328
             offsetof(struct ImmutableDBOptions,
                      access_hint_on_compaction_start),
329
             &access_hint_string_map)},
330 331 332 333
        {"info_log_level",
         OptionTypeInfo::Enum<InfoLogLevel>(
             offsetof(struct ImmutableDBOptions, info_log_level),
             &info_log_level_string_map)},
334
        {"dump_malloc_stats",
335
         {offsetof(struct ImmutableDBOptions, dump_malloc_stats),
336
          OptionType::kBoolean, OptionVerificationType::kNormal,
337 338 339
          OptionTypeFlags::kNone}},
        {"avoid_flush_during_recovery",
         {offsetof(struct ImmutableDBOptions, avoid_flush_during_recovery),
340
          OptionType::kBoolean, OptionVerificationType::kNormal,
341
          OptionTypeFlags::kNone}},
342
        {"allow_ingest_behind",
343 344 345
         {offsetof(struct ImmutableDBOptions, allow_ingest_behind),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
346
        {"preserve_deletes",
347 348 349
         {offsetof(struct ImmutableDBOptions, preserve_deletes),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
350 351
        {"concurrent_prepare",  // Deprecated by two_write_queues
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
352
          OptionTypeFlags::kNone}},
353
        {"two_write_queues",
354 355 356
         {offsetof(struct ImmutableDBOptions, two_write_queues),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
357
        {"manual_wal_flush",
358 359 360
         {offsetof(struct ImmutableDBOptions, manual_wal_flush),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
361 362
        {"seq_per_batch",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
363
          OptionTypeFlags::kNone}},
364
        {"atomic_flush",
365 366 367
         {offsetof(struct ImmutableDBOptions, atomic_flush),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
368
        {"avoid_unnecessary_blocking_io",
369
         {offsetof(struct ImmutableDBOptions, avoid_unnecessary_blocking_io),
370
          OptionType::kBoolean, OptionVerificationType::kNormal,
371
          OptionTypeFlags::kNone}},
372
        {"write_dbid_to_manifest",
373
         {offsetof(struct ImmutableDBOptions, write_dbid_to_manifest),
374
          OptionType::kBoolean, OptionVerificationType::kNormal,
375
          OptionTypeFlags::kNone}},
376
        {"log_readahead_size",
377 378 379
         {offsetof(struct ImmutableDBOptions, log_readahead_size),
          OptionType::kSizeT, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
380
        {"best_efforts_recovery",
381
         {offsetof(struct ImmutableDBOptions, best_efforts_recovery),
382
          OptionType::kBoolean, OptionVerificationType::kNormal,
383
          OptionTypeFlags::kNone}},
384
        {"max_bgerror_resume_count",
385
         {offsetof(struct ImmutableDBOptions, max_bgerror_resume_count),
386
          OptionType::kInt, OptionVerificationType::kNormal,
387
          OptionTypeFlags::kNone}},
388
        {"bgerror_resume_retry_interval",
389
         {offsetof(struct ImmutableDBOptions, bgerror_resume_retry_interval),
390
          OptionType::kUInt64T, OptionVerificationType::kNormal,
391
          OptionTypeFlags::kNone}},
392 393 394 395
        // 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",
396 397 398
         {offsetof(struct ImmutableDBOptions, rate_limiter),
          OptionType::kUnknown, OptionVerificationType::kNormal,
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever),
399 400 401 402 403 404 405 406 407 408
          // 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",
409
         {offsetof(struct ImmutableDBOptions, env), OptionType::kUnknown,
410
          OptionVerificationType::kNormal,
411
          (OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever),
412 413 414 415 416 417 418 419 420 421 422
          // 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;
          }}},
423 424 425 426
        {"allow_data_in_errors",
         {offsetof(struct ImmutableDBOptions, allow_data_in_errors),
          OptionType::kBoolean, OptionVerificationType::kNormal,
          OptionTypeFlags::kNone}},
427
};
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495

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

class MutableDBConfigurable : public Configurable {
 public:
  MutableDBConfigurable(const MutableDBOptions& mdb) {
    mutable_ = mdb;
    ConfigurableHelper::RegisterOptions(*this, &mutable_,
                                        &db_mutable_options_type_info);
  }

 protected:
  MutableDBOptions mutable_;
};

class DBOptionsConfigurable : public MutableDBConfigurable {
 public:
  DBOptionsConfigurable(const DBOptions& opts)
      : MutableDBConfigurable(MutableDBOptions(opts)), db_options_(opts) {
    // 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);
    }
    ConfigurableHelper::RegisterOptions(*this, &immutable_,
                                        &db_immutable_options_type_info);
  }

 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 {
    Status s = ConfigurableHelper::ConfigureOptions(config_options, *this,
                                                    opts_map, unused);
    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;
}
std::unique_ptr<Configurable> DBOptionsAsConfigurable(const DBOptions& opts) {
  std::unique_ptr<Configurable> ptr(new DBOptionsConfigurable(opts));
  return ptr;
}
496
#endif  // ROCKSDB_LITE
497 498 499 500 501 502 503 504

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),
505 506
      track_and_verify_wals_in_manifest(
          options.track_and_verify_wals_in_manifest),
507
      env(options.env),
508
      fs(options.env->GetFileSystem()),
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
      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),
      wal_ttl_seconds(options.WAL_ttl_seconds),
      wal_size_limit_mb(options.WAL_size_limit_MB),
527 528
      max_write_batch_group_size_bytes(
          options.max_write_batch_group_size_bytes),
529 530 531
      manifest_preallocation_size(options.manifest_preallocation_size),
      allow_mmap_reads(options.allow_mmap_reads),
      allow_mmap_writes(options.allow_mmap_writes),
532
      use_direct_reads(options.use_direct_reads),
533 534
      use_direct_io_for_flush_and_compaction(
          options.use_direct_io_for_flush_and_compaction),
535 536 537 538 539 540 541 542 543 544 545 546
      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),
547
      enable_pipelined_write(options.enable_pipelined_write),
M
Maysam Yabandeh 已提交
548
      unordered_write(options.unordered_write),
549 550 551 552 553 554
      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),
555 556
      skip_checking_sst_file_sizes_on_db_open(
          options.skip_checking_sst_file_sizes_on_db_open),
557 558 559 560 561 562 563 564
      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),
565
      avoid_flush_during_recovery(options.avoid_flush_during_recovery),
566
      allow_ingest_behind(options.allow_ingest_behind),
567
      preserve_deletes(options.preserve_deletes),
568
      two_write_queues(options.two_write_queues),
569
      manual_wal_flush(options.manual_wal_flush),
570
      atomic_flush(options.atomic_flush),
571
      avoid_unnecessary_blocking_io(options.avoid_unnecessary_blocking_io),
572
      persist_stats_to_disk(options.persist_stats_to_disk),
573
      write_dbid_to_manifest(options.write_dbid_to_manifest),
574
      log_readahead_size(options.log_readahead_size),
575
      file_checksum_gen_factory(options.file_checksum_gen_factory),
576 577
      best_efforts_recovery(options.best_efforts_recovery),
      max_bgerror_resume_count(options.max_bgerror_resume_count),
578 579
      bgerror_resume_retry_interval(options.bgerror_resume_retry_interval),
      allow_data_in_errors(options.allow_data_in_errors) {
580 581 582
}

void ImmutableDBOptions::Dump(Logger* log) const {
583 584 585 586 587 588
  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);
589 590 591 592
  ROCKS_LOG_HEADER(log,
                   "                              "
                   "Options.track_and_verify_wals_in_manifest: %d",
                   track_and_verify_wals_in_manifest);
593 594
  ROCKS_LOG_HEADER(log, "                                    Options.env: %p",
                   env);
595 596
  ROCKS_LOG_HEADER(log, "                                     Options.fs: %s",
                   fs->Name());
597 598 599 600
  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);
601 602
  ROCKS_LOG_HEADER(log, "                             Options.statistics: %p",
                   statistics.get());
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
  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);
628 629 630 631
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.use_direct_io_for_flush_and_compaction: %d",
                   use_direct_io_for_flush_and_compaction);
632 633 634 635 636 637 638 639 640 641 642 643 644 645
  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,
                   wal_ttl_seconds);
  ROCKS_LOG_HEADER(log,
                   "                      Options.WAL_size_limit_MB: %" PRIu64,
                   wal_size_limit_mb);
646 647 648 649
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.max_write_batch_group_size_bytes: %" PRIu64,
                   max_write_batch_group_size_bytes);
650 651 652 653 654 655 656 657 658 659
  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);
660 661
  ROCKS_LOG_HEADER(log, "                   Options.write_buffer_manager: %p",
                   write_buffer_manager.get());
662 663 664 665 666 667 668 669 670 671 672
  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());
673 674 675
  Header(
      log, "    Options.sst_file_manager.rate_bytes_per_sec: %" PRIi64,
      sst_file_manager ? sst_file_manager->GetDeleteRateBytesPerSecond() : 0);
676
  ROCKS_LOG_HEADER(log, "                      Options.wal_recovery_mode: %d",
677
                   static_cast<int>(wal_recovery_mode));
678 679
  ROCKS_LOG_HEADER(log, "                 Options.enable_thread_tracking: %d",
                   enable_thread_tracking);
680 681
  ROCKS_LOG_HEADER(log, "                 Options.enable_pipelined_write: %d",
                   enable_pipelined_write);
M
Maysam Yabandeh 已提交
682 683
  ROCKS_LOG_HEADER(log, "                 Options.unordered_write: %d",
                   unordered_write);
684 685 686 687 688 689 690 691 692 693
  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);
694
  if (row_cache) {
695
    ROCKS_LOG_HEADER(
696 697
        log,
        "                              Options.row_cache: %" ROCKSDB_PRIszt,
698
        row_cache->GetCapacity());
699
  } else {
700 701
    ROCKS_LOG_HEADER(log,
                     "                              Options.row_cache: None");
702 703
  }
#ifndef ROCKSDB_LITE
704 705
  ROCKS_LOG_HEADER(log, "                             Options.wal_filter: %s",
                   wal_filter ? wal_filter->Name() : "None");
706
#endif  // ROCKDB_LITE
707

708 709
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_recovery: %d",
                   avoid_flush_during_recovery);
710 711
  ROCKS_LOG_HEADER(log, "            Options.allow_ingest_behind: %d",
                   allow_ingest_behind);
712 713
  ROCKS_LOG_HEADER(log, "            Options.preserve_deletes: %d",
                   preserve_deletes);
714 715
  ROCKS_LOG_HEADER(log, "            Options.two_write_queues: %d",
                   two_write_queues);
716 717
  ROCKS_LOG_HEADER(log, "            Options.manual_wal_flush: %d",
                   manual_wal_flush);
718 719 720 721
  ROCKS_LOG_HEADER(log, "            Options.atomic_flush: %d", atomic_flush);
  ROCKS_LOG_HEADER(log,
                   "            Options.avoid_unnecessary_blocking_io: %d",
                   avoid_unnecessary_blocking_io);
722 723
  ROCKS_LOG_HEADER(log, "                Options.persist_stats_to_disk: %u",
                   persist_stats_to_disk);
724 725
  ROCKS_LOG_HEADER(log, "                Options.write_dbid_to_manifest: %d",
                   write_dbid_to_manifest);
726 727 728
  ROCKS_LOG_HEADER(
      log, "                Options.log_readahead_size: %" ROCKSDB_PRIszt,
      log_readahead_size);
729
  ROCKS_LOG_HEADER(log, "                Options.file_checksum_gen_factory: %s",
730 731
                   file_checksum_gen_factory ? file_checksum_gen_factory->Name()
                                             : kUnknownFileChecksumFuncName);
732 733
  ROCKS_LOG_HEADER(log, "                Options.best_efforts_recovery: %d",
                   static_cast<int>(best_efforts_recovery));
734 735 736 737 738
  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);
739 740
  ROCKS_LOG_HEADER(log, "            Options.allow_data_in_errors: %d",
                   allow_data_in_errors);
741 742
}

743
MutableDBOptions::MutableDBOptions()
744 745 746
    : max_background_jobs(2),
      base_background_compactions(-1),
      max_background_compactions(-1),
747
      max_subcompactions(0),
748
      avoid_flush_during_shutdown(false),
749
      writable_file_max_buffer_size(1024 * 1024),
750
      delayed_write_rate(2 * 1024U * 1024U),
751
      max_total_wal_size(0),
752
      delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
L
Leonidas Galanis 已提交
753
      stats_dump_period_sec(600),
754 755
      stats_persist_period_sec(600),
      stats_history_buffer_size(1024 * 1024),
756 757
      max_open_files(-1),
      bytes_per_sync(0),
758
      wal_bytes_per_sync(0),
759
      strict_bytes_per_sync(false),
760 761
      compaction_readahead_size(0),
      max_background_flushes(-1) {}
762 763

MutableDBOptions::MutableDBOptions(const DBOptions& options)
764 765
    : max_background_jobs(options.max_background_jobs),
      base_background_compactions(options.base_background_compactions),
Y
Yi Wu 已提交
766
      max_background_compactions(options.max_background_compactions),
767
      max_subcompactions(options.max_subcompactions),
768
      avoid_flush_during_shutdown(options.avoid_flush_during_shutdown),
769
      writable_file_max_buffer_size(options.writable_file_max_buffer_size),
770
      delayed_write_rate(options.delayed_write_rate),
771 772
      max_total_wal_size(options.max_total_wal_size),
      delete_obsolete_files_period_micros(
773
          options.delete_obsolete_files_period_micros),
L
Leonidas Galanis 已提交
774
      stats_dump_period_sec(options.stats_dump_period_sec),
775 776
      stats_persist_period_sec(options.stats_persist_period_sec),
      stats_history_buffer_size(options.stats_history_buffer_size),
777 778
      max_open_files(options.max_open_files),
      bytes_per_sync(options.bytes_per_sync),
779
      wal_bytes_per_sync(options.wal_bytes_per_sync),
780
      strict_bytes_per_sync(options.strict_bytes_per_sync),
781 782
      compaction_readahead_size(options.compaction_readahead_size),
      max_background_flushes(options.max_background_flushes) {}
783

784
void MutableDBOptions::Dump(Logger* log) const {
785 786
  ROCKS_LOG_HEADER(log, "            Options.max_background_jobs: %d",
                   max_background_jobs);
787 788
  ROCKS_LOG_HEADER(log, "            Options.max_background_compactions: %d",
                   max_background_compactions);
789 790
  ROCKS_LOG_HEADER(log, "            Options.max_subcompactions: %" PRIu32,
                   max_subcompactions);
791 792
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_shutdown: %d",
                   avoid_flush_during_shutdown);
793 794 795
  ROCKS_LOG_HEADER(
      log, "          Options.writable_file_max_buffer_size: %" ROCKSDB_PRIszt,
      writable_file_max_buffer_size);
796 797 798 799 800 801 802
  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);
803 804
  ROCKS_LOG_HEADER(log, "                  Options.stats_dump_period_sec: %u",
                   stats_dump_period_sec);
805 806
  ROCKS_LOG_HEADER(log, "                Options.stats_persist_period_sec: %d",
                   stats_persist_period_sec);
807 808 809 810
  ROCKS_LOG_HEADER(
      log,
      "                Options.stats_history_buffer_size: %" ROCKSDB_PRIszt,
      stats_history_buffer_size);
L
Leonidas Galanis 已提交
811 812
  ROCKS_LOG_HEADER(log, "                         Options.max_open_files: %d",
                   max_open_files);
813 814 815 816 817 818
  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);
819 820 821
  ROCKS_LOG_HEADER(log,
                   "                  Options.strict_bytes_per_sync: %d",
                   strict_bytes_per_sync);
822 823 824
  ROCKS_LOG_HEADER(log,
                   "      Options.compaction_readahead_size: %" ROCKSDB_PRIszt,
                   compaction_readahead_size);
825 826
  ROCKS_LOG_HEADER(log, "                 Options.max_background_flushes: %d",
                          max_background_flushes);
827
}
828

829
}  // namespace ROCKSDB_NAMESPACE