db_options.cc 15.8 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 12 13
#include "port/port.h"
#include "rocksdb/cache.h"
#include "rocksdb/env.h"
14
#include "rocksdb/file_system.h"
15 16 17 18 19 20 21 22 23 24 25 26 27
#include "rocksdb/sst_file_manager.h"
#include "rocksdb/wal_filter.h"

namespace rocksdb {

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),
28
      fs(options.file_system),
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      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_background_flushes(options.max_background_flushes),
      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),
49 50
      max_write_batch_group_size_bytes(
          options.max_write_batch_group_size_bytes),
51 52 53
      manifest_preallocation_size(options.manifest_preallocation_size),
      allow_mmap_reads(options.allow_mmap_reads),
      allow_mmap_writes(options.allow_mmap_writes),
54
      use_direct_reads(options.use_direct_reads),
55 56
      use_direct_io_for_flush_and_compaction(
          options.use_direct_io_for_flush_and_compaction),
57 58 59 60 61 62 63 64 65 66 67 68
      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),
69
      enable_pipelined_write(options.enable_pipelined_write),
M
Maysam Yabandeh 已提交
70
      unordered_write(options.unordered_write),
71 72 73 74 75 76
      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),
77 78
      skip_checking_sst_file_sizes_on_db_open(
          options.skip_checking_sst_file_sizes_on_db_open),
79 80 81 82 83 84 85 86
      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),
87
      avoid_flush_during_recovery(options.avoid_flush_during_recovery),
88
      allow_ingest_behind(options.allow_ingest_behind),
89
      preserve_deletes(options.preserve_deletes),
90
      two_write_queues(options.two_write_queues),
91
      manual_wal_flush(options.manual_wal_flush),
92
      atomic_flush(options.atomic_flush),
93
      avoid_unnecessary_blocking_io(options.avoid_unnecessary_blocking_io),
94
      persist_stats_to_disk(options.persist_stats_to_disk),
95
      write_dbid_to_manifest(options.write_dbid_to_manifest),
96
      log_readahead_size(options.log_readahead_size) {
97 98 99
}

void ImmutableDBOptions::Dump(Logger* log) const {
100 101 102 103 104 105 106 107
  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);
108 109
  ROCKS_LOG_HEADER(log, "                                     Options.fs: %s",
                   fs->Name());
110 111 112 113
  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);
114 115
  ROCKS_LOG_HEADER(log, "                             Options.statistics: %p",
                   statistics.get());
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
  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);
141 142 143 144
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.use_direct_io_for_flush_and_compaction: %d",
                   use_direct_io_for_flush_and_compaction);
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  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.max_background_flushes: %d",
                   max_background_flushes);
  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);
164 165 166 167
  ROCKS_LOG_HEADER(log,
                   "                       "
                   "Options.max_write_batch_group_size_bytes: %" PRIu64,
                   max_write_batch_group_size_bytes);
168 169 170 171 172 173 174 175 176 177
  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);
178 179
  ROCKS_LOG_HEADER(log, "                   Options.write_buffer_manager: %p",
                   write_buffer_manager.get());
180 181 182 183 184 185 186 187 188 189 190
  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());
191 192 193
  Header(
      log, "    Options.sst_file_manager.rate_bytes_per_sec: %" PRIi64,
      sst_file_manager ? sst_file_manager->GetDeleteRateBytesPerSecond() : 0);
194
  ROCKS_LOG_HEADER(log, "                      Options.wal_recovery_mode: %d",
195
                   static_cast<int>(wal_recovery_mode));
196 197
  ROCKS_LOG_HEADER(log, "                 Options.enable_thread_tracking: %d",
                   enable_thread_tracking);
198 199
  ROCKS_LOG_HEADER(log, "                 Options.enable_pipelined_write: %d",
                   enable_pipelined_write);
M
Maysam Yabandeh 已提交
200 201
  ROCKS_LOG_HEADER(log, "                 Options.unordered_write: %d",
                   unordered_write);
202 203 204 205 206 207 208 209 210 211
  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);
212
  if (row_cache) {
213
    ROCKS_LOG_HEADER(
214 215
        log,
        "                              Options.row_cache: %" ROCKSDB_PRIszt,
216
        row_cache->GetCapacity());
217
  } else {
218 219
    ROCKS_LOG_HEADER(log,
                     "                              Options.row_cache: None");
220 221
  }
#ifndef ROCKSDB_LITE
222 223
  ROCKS_LOG_HEADER(log, "                             Options.wal_filter: %s",
                   wal_filter ? wal_filter->Name() : "None");
224
#endif  // ROCKDB_LITE
225

226 227
  ROCKS_LOG_HEADER(log, "            Options.avoid_flush_during_recovery: %d",
                   avoid_flush_during_recovery);
228 229
  ROCKS_LOG_HEADER(log, "            Options.allow_ingest_behind: %d",
                   allow_ingest_behind);
230 231
  ROCKS_LOG_HEADER(log, "            Options.preserve_deletes: %d",
                   preserve_deletes);
232 233
  ROCKS_LOG_HEADER(log, "            Options.two_write_queues: %d",
                   two_write_queues);
234 235
  ROCKS_LOG_HEADER(log, "            Options.manual_wal_flush: %d",
                   manual_wal_flush);
236 237 238 239
  ROCKS_LOG_HEADER(log, "            Options.atomic_flush: %d", atomic_flush);
  ROCKS_LOG_HEADER(log,
                   "            Options.avoid_unnecessary_blocking_io: %d",
                   avoid_unnecessary_blocking_io);
240 241
  ROCKS_LOG_HEADER(log, "                Options.persist_stats_to_disk: %u",
                   persist_stats_to_disk);
242 243
  ROCKS_LOG_HEADER(log, "                Options.write_dbid_to_manifest: %d",
                   write_dbid_to_manifest);
244 245 246
  ROCKS_LOG_HEADER(
      log, "                Options.log_readahead_size: %" ROCKSDB_PRIszt,
      log_readahead_size);
247 248
}

249
MutableDBOptions::MutableDBOptions()
250 251 252
    : max_background_jobs(2),
      base_background_compactions(-1),
      max_background_compactions(-1),
253
      avoid_flush_during_shutdown(false),
254
      writable_file_max_buffer_size(1024 * 1024),
255
      delayed_write_rate(2 * 1024U * 1024U),
256
      max_total_wal_size(0),
257
      delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
L
Leonidas Galanis 已提交
258
      stats_dump_period_sec(600),
259 260
      stats_persist_period_sec(600),
      stats_history_buffer_size(1024 * 1024),
261 262
      max_open_files(-1),
      bytes_per_sync(0),
263
      wal_bytes_per_sync(0),
264
      strict_bytes_per_sync(false),
265
      compaction_readahead_size(0) {}
266 267

MutableDBOptions::MutableDBOptions(const DBOptions& options)
268 269
    : max_background_jobs(options.max_background_jobs),
      base_background_compactions(options.base_background_compactions),
Y
Yi Wu 已提交
270
      max_background_compactions(options.max_background_compactions),
271
      avoid_flush_during_shutdown(options.avoid_flush_during_shutdown),
272
      writable_file_max_buffer_size(options.writable_file_max_buffer_size),
273
      delayed_write_rate(options.delayed_write_rate),
274 275
      max_total_wal_size(options.max_total_wal_size),
      delete_obsolete_files_period_micros(
276
          options.delete_obsolete_files_period_micros),
L
Leonidas Galanis 已提交
277
      stats_dump_period_sec(options.stats_dump_period_sec),
278 279
      stats_persist_period_sec(options.stats_persist_period_sec),
      stats_history_buffer_size(options.stats_history_buffer_size),
280 281
      max_open_files(options.max_open_files),
      bytes_per_sync(options.bytes_per_sync),
282
      wal_bytes_per_sync(options.wal_bytes_per_sync),
283
      strict_bytes_per_sync(options.strict_bytes_per_sync),
284
      compaction_readahead_size(options.compaction_readahead_size) {}
285

286
void MutableDBOptions::Dump(Logger* log) const {
287 288
  ROCKS_LOG_HEADER(log, "            Options.max_background_jobs: %d",
                   max_background_jobs);
289 290 291 292
  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);
293 294 295
  ROCKS_LOG_HEADER(
      log, "          Options.writable_file_max_buffer_size: %" ROCKSDB_PRIszt,
      writable_file_max_buffer_size);
296 297 298 299 300 301 302
  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);
303 304
  ROCKS_LOG_HEADER(log, "                  Options.stats_dump_period_sec: %u",
                   stats_dump_period_sec);
305 306
  ROCKS_LOG_HEADER(log, "                Options.stats_persist_period_sec: %d",
                   stats_persist_period_sec);
307 308 309 310
  ROCKS_LOG_HEADER(
      log,
      "                Options.stats_history_buffer_size: %" ROCKSDB_PRIszt,
      stats_history_buffer_size);
L
Leonidas Galanis 已提交
311 312
  ROCKS_LOG_HEADER(log, "                         Options.max_open_files: %d",
                   max_open_files);
313 314 315 316 317 318
  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);
319 320 321
  ROCKS_LOG_HEADER(log,
                   "                  Options.strict_bytes_per_sync: %d",
                   strict_bytes_per_sync);
322 323 324
  ROCKS_LOG_HEADER(log,
                   "      Options.compaction_readahead_size: %" ROCKSDB_PRIszt,
                   compaction_readahead_size);
325
}
326 327

}  // namespace rocksdb