options_helper.cc 93.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
#include "options/options_helper.h"
6 7

#include <cassert>
L
Lei Jin 已提交
8
#include <cctype>
S
sdong 已提交
9
#include <cstdlib>
10
#include <unordered_set>
11
#include <vector>
12

13
#include "rocksdb/cache.h"
14
#include "rocksdb/compaction_filter.h"
A
agiardullo 已提交
15
#include "rocksdb/convenience.h"
16
#include "rocksdb/filter_policy.h"
17 18
#include "rocksdb/memtablerep.h"
#include "rocksdb/merge_operator.h"
19
#include "rocksdb/options.h"
I
Igor Canadi 已提交
20
#include "rocksdb/rate_limiter.h"
21
#include "rocksdb/slice_transform.h"
22
#include "rocksdb/table.h"
23
#include "rocksdb/utilities/object_registry.h"
24
#include "table/block_based/block_based_table_factory.h"
25
#include "table/plain/plain_table_factory.h"
S
Siying Dong 已提交
26
#include "util/cast_util.h"
27
#include "util/string_util.h"
28

29
namespace ROCKSDB_NAMESPACE {
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44
DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
                         const MutableDBOptions& mutable_db_options) {
  DBOptions options;

  options.create_if_missing = immutable_db_options.create_if_missing;
  options.create_missing_column_families =
      immutable_db_options.create_missing_column_families;
  options.error_if_exists = immutable_db_options.error_if_exists;
  options.paranoid_checks = immutable_db_options.paranoid_checks;
  options.env = immutable_db_options.env;
  options.rate_limiter = immutable_db_options.rate_limiter;
  options.sst_file_manager = immutable_db_options.sst_file_manager;
  options.info_log = immutable_db_options.info_log;
  options.info_log_level = immutable_db_options.info_log_level;
L
Leonidas Galanis 已提交
45
  options.max_open_files = mutable_db_options.max_open_files;
46 47
  options.max_file_opening_threads =
      immutable_db_options.max_file_opening_threads;
48
  options.max_total_wal_size = mutable_db_options.max_total_wal_size;
49 50 51 52 53 54
  options.statistics = immutable_db_options.statistics;
  options.use_fsync = immutable_db_options.use_fsync;
  options.db_paths = immutable_db_options.db_paths;
  options.db_log_dir = immutable_db_options.db_log_dir;
  options.wal_dir = immutable_db_options.wal_dir;
  options.delete_obsolete_files_period_micros =
55
      mutable_db_options.delete_obsolete_files_period_micros;
56
  options.max_background_jobs = mutable_db_options.max_background_jobs;
57
  options.base_background_compactions =
58
      mutable_db_options.base_background_compactions;
59
  options.max_background_compactions =
60
      mutable_db_options.max_background_compactions;
61 62
  options.bytes_per_sync = mutable_db_options.bytes_per_sync;
  options.wal_bytes_per_sync = mutable_db_options.wal_bytes_per_sync;
63
  options.strict_bytes_per_sync = mutable_db_options.strict_bytes_per_sync;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  options.max_subcompactions = immutable_db_options.max_subcompactions;
  options.max_background_flushes = immutable_db_options.max_background_flushes;
  options.max_log_file_size = immutable_db_options.max_log_file_size;
  options.log_file_time_to_roll = immutable_db_options.log_file_time_to_roll;
  options.keep_log_file_num = immutable_db_options.keep_log_file_num;
  options.recycle_log_file_num = immutable_db_options.recycle_log_file_num;
  options.max_manifest_file_size = immutable_db_options.max_manifest_file_size;
  options.table_cache_numshardbits =
      immutable_db_options.table_cache_numshardbits;
  options.WAL_ttl_seconds = immutable_db_options.wal_ttl_seconds;
  options.WAL_size_limit_MB = immutable_db_options.wal_size_limit_mb;
  options.manifest_preallocation_size =
      immutable_db_options.manifest_preallocation_size;
  options.allow_mmap_reads = immutable_db_options.allow_mmap_reads;
  options.allow_mmap_writes = immutable_db_options.allow_mmap_writes;
79
  options.use_direct_reads = immutable_db_options.use_direct_reads;
80 81
  options.use_direct_io_for_flush_and_compaction =
      immutable_db_options.use_direct_io_for_flush_and_compaction;
82 83
  options.allow_fallocate = immutable_db_options.allow_fallocate;
  options.is_fd_close_on_exec = immutable_db_options.is_fd_close_on_exec;
84
  options.stats_dump_period_sec = mutable_db_options.stats_dump_period_sec;
85 86
  options.stats_persist_period_sec =
      mutable_db_options.stats_persist_period_sec;
87
  options.persist_stats_to_disk = immutable_db_options.persist_stats_to_disk;
88 89
  options.stats_history_buffer_size =
      mutable_db_options.stats_history_buffer_size;
90 91 92 93 94 95 96 97
  options.advise_random_on_open = immutable_db_options.advise_random_on_open;
  options.db_write_buffer_size = immutable_db_options.db_write_buffer_size;
  options.write_buffer_manager = immutable_db_options.write_buffer_manager;
  options.access_hint_on_compaction_start =
      immutable_db_options.access_hint_on_compaction_start;
  options.new_table_reader_for_compaction_inputs =
      immutable_db_options.new_table_reader_for_compaction_inputs;
  options.compaction_readahead_size =
98
      mutable_db_options.compaction_readahead_size;
99 100 101
  options.random_access_max_buffer_size =
      immutable_db_options.random_access_max_buffer_size;
  options.writable_file_max_buffer_size =
102
      mutable_db_options.writable_file_max_buffer_size;
103 104 105
  options.use_adaptive_mutex = immutable_db_options.use_adaptive_mutex;
  options.listeners = immutable_db_options.listeners;
  options.enable_thread_tracking = immutable_db_options.enable_thread_tracking;
106
  options.delayed_write_rate = mutable_db_options.delayed_write_rate;
107
  options.enable_pipelined_write = immutable_db_options.enable_pipelined_write;
M
Maysam Yabandeh 已提交
108
  options.unordered_write = immutable_db_options.unordered_write;
109 110 111 112
  options.allow_concurrent_memtable_write =
      immutable_db_options.allow_concurrent_memtable_write;
  options.enable_write_thread_adaptive_yield =
      immutable_db_options.enable_write_thread_adaptive_yield;
113 114
  options.max_write_batch_group_size_bytes =
      immutable_db_options.max_write_batch_group_size_bytes;
115 116 117 118 119 120
  options.write_thread_max_yield_usec =
      immutable_db_options.write_thread_max_yield_usec;
  options.write_thread_slow_yield_usec =
      immutable_db_options.write_thread_slow_yield_usec;
  options.skip_stats_update_on_db_open =
      immutable_db_options.skip_stats_update_on_db_open;
121 122
  options.skip_checking_sst_file_sizes_on_db_open =
      immutable_db_options.skip_checking_sst_file_sizes_on_db_open;
123 124 125 126 127 128 129 130 131 132 133
  options.wal_recovery_mode = immutable_db_options.wal_recovery_mode;
  options.allow_2pc = immutable_db_options.allow_2pc;
  options.row_cache = immutable_db_options.row_cache;
#ifndef ROCKSDB_LITE
  options.wal_filter = immutable_db_options.wal_filter;
#endif  // ROCKSDB_LITE
  options.fail_if_options_file_error =
      immutable_db_options.fail_if_options_file_error;
  options.dump_malloc_stats = immutable_db_options.dump_malloc_stats;
  options.avoid_flush_during_recovery =
      immutable_db_options.avoid_flush_during_recovery;
Y
Yi Wu 已提交
134 135
  options.avoid_flush_during_shutdown =
      mutable_db_options.avoid_flush_during_shutdown;
136 137
  options.allow_ingest_behind =
      immutable_db_options.allow_ingest_behind;
138 139
  options.preserve_deletes =
      immutable_db_options.preserve_deletes;
140 141
  options.two_write_queues = immutable_db_options.two_write_queues;
  options.manual_wal_flush = immutable_db_options.manual_wal_flush;
142
  options.atomic_flush = immutable_db_options.atomic_flush;
143 144
  options.avoid_unnecessary_blocking_io =
      immutable_db_options.avoid_unnecessary_blocking_io;
145
  options.log_readahead_size = immutable_db_options.log_readahead_size;
146 147
  options.file_checksum_gen_factory =
      immutable_db_options.file_checksum_gen_factory;
148
  options.best_efforts_recovery = immutable_db_options.best_efforts_recovery;
149 150 151
  return options;
}

152 153 154 155 156 157 158 159 160 161 162
ColumnFamilyOptions BuildColumnFamilyOptions(
    const ColumnFamilyOptions& options,
    const MutableCFOptions& mutable_cf_options) {
  ColumnFamilyOptions cf_opts(options);

  // Memtable related options
  cf_opts.write_buffer_size = mutable_cf_options.write_buffer_size;
  cf_opts.max_write_buffer_number = mutable_cf_options.max_write_buffer_number;
  cf_opts.arena_block_size = mutable_cf_options.arena_block_size;
  cf_opts.memtable_prefix_bloom_size_ratio =
      mutable_cf_options.memtable_prefix_bloom_size_ratio;
163 164
  cf_opts.memtable_whole_key_filtering =
      mutable_cf_options.memtable_whole_key_filtering;
165 166 167 168
  cf_opts.memtable_huge_page_size = mutable_cf_options.memtable_huge_page_size;
  cf_opts.max_successive_merges = mutable_cf_options.max_successive_merges;
  cf_opts.inplace_update_num_locks =
      mutable_cf_options.inplace_update_num_locks;
169
  cf_opts.prefix_extractor = mutable_cf_options.prefix_extractor;
170 171 172 173

  // Compaction related options
  cf_opts.disable_auto_compactions =
      mutable_cf_options.disable_auto_compactions;
174 175 176 177
  cf_opts.soft_pending_compaction_bytes_limit =
      mutable_cf_options.soft_pending_compaction_bytes_limit;
  cf_opts.hard_pending_compaction_bytes_limit =
      mutable_cf_options.hard_pending_compaction_bytes_limit;
178 179 180 181 182 183 184 185 186 187 188 189 190 191
  cf_opts.level0_file_num_compaction_trigger =
      mutable_cf_options.level0_file_num_compaction_trigger;
  cf_opts.level0_slowdown_writes_trigger =
      mutable_cf_options.level0_slowdown_writes_trigger;
  cf_opts.level0_stop_writes_trigger =
      mutable_cf_options.level0_stop_writes_trigger;
  cf_opts.max_compaction_bytes = mutable_cf_options.max_compaction_bytes;
  cf_opts.target_file_size_base = mutable_cf_options.target_file_size_base;
  cf_opts.target_file_size_multiplier =
      mutable_cf_options.target_file_size_multiplier;
  cf_opts.max_bytes_for_level_base =
      mutable_cf_options.max_bytes_for_level_base;
  cf_opts.max_bytes_for_level_multiplier =
      mutable_cf_options.max_bytes_for_level_multiplier;
192
  cf_opts.ttl = mutable_cf_options.ttl;
S
Sagar Vemuri 已提交
193 194
  cf_opts.periodic_compaction_seconds =
      mutable_cf_options.periodic_compaction_seconds;
195 196 197 198 199 200 201

  cf_opts.max_bytes_for_level_multiplier_additional.clear();
  for (auto value :
       mutable_cf_options.max_bytes_for_level_multiplier_additional) {
    cf_opts.max_bytes_for_level_multiplier_additional.emplace_back(value);
  }

202
  cf_opts.compaction_options_fifo = mutable_cf_options.compaction_options_fifo;
203 204
  cf_opts.compaction_options_universal =
      mutable_cf_options.compaction_options_universal;
205

206 207 208 209 210 211
  // Misc options
  cf_opts.max_sequential_skip_in_iterations =
      mutable_cf_options.max_sequential_skip_in_iterations;
  cf_opts.paranoid_file_checks = mutable_cf_options.paranoid_file_checks;
  cf_opts.report_bg_io_stats = mutable_cf_options.report_bg_io_stats;
  cf_opts.compression = mutable_cf_options.compression;
212
  cf_opts.sample_for_compression = mutable_cf_options.sample_for_compression;
213 214 215 216 217 218 219 220

  cf_opts.table_factory = options.table_factory;
  // TODO(yhchiang): find some way to handle the following derived options
  // * max_file_size

  return cf_opts;
}

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
std::map<CompactionStyle, std::string>
    OptionsHelper::compaction_style_to_string = {
        {kCompactionStyleLevel, "kCompactionStyleLevel"},
        {kCompactionStyleUniversal, "kCompactionStyleUniversal"},
        {kCompactionStyleFIFO, "kCompactionStyleFIFO"},
        {kCompactionStyleNone, "kCompactionStyleNone"}};

std::map<CompactionPri, std::string> OptionsHelper::compaction_pri_to_string = {
    {kByCompensatedSize, "kByCompensatedSize"},
    {kOldestLargestSeqFirst, "kOldestLargestSeqFirst"},
    {kOldestSmallestSeqFirst, "kOldestSmallestSeqFirst"},
    {kMinOverlappingRatio, "kMinOverlappingRatio"}};

std::map<CompactionStopStyle, std::string>
    OptionsHelper::compaction_stop_style_to_string = {
        {kCompactionStopStyleSimilarSize, "kCompactionStopStyleSimilarSize"},
        {kCompactionStopStyleTotalSize, "kCompactionStopStyleTotalSize"}};

std::unordered_map<std::string, ChecksumType>
    OptionsHelper::checksum_type_string_map = {{"kNoChecksum", kNoChecksum},
                                               {"kCRC32c", kCRC32c},
B
Bo Hou 已提交
242 243
                                               {"kxxHash", kxxHash},
                                               {"kxxHash64", kxxHash64}};
244

245 246 247 248 249 250 251 252 253 254 255 256
std::unordered_map<std::string, CompressionType>
    OptionsHelper::compression_type_string_map = {
        {"kNoCompression", kNoCompression},
        {"kSnappyCompression", kSnappyCompression},
        {"kZlibCompression", kZlibCompression},
        {"kBZip2Compression", kBZip2Compression},
        {"kLZ4Compression", kLZ4Compression},
        {"kLZ4HCCompression", kLZ4HCCompression},
        {"kXpressCompression", kXpressCompression},
        {"kZSTD", kZSTD},
        {"kZSTDNotFinalCompression", kZSTDNotFinalCompression},
        {"kDisableCompressionOption", kDisableCompressionOption}};
257
#ifndef ROCKSDB_LITE
258

259
const std::string kNameComparator = "comparator";
260
const std::string kNameEnv = "env";
261
const std::string kNameMergeOperator = "merge_operator";
262 263
const std::string kOptNameBMCompOpts = "bottommost_compression_opts";
const std::string kOptNameCompOpts = "compression_opts";
264

265 266 267
template <typename T>
Status GetStringFromStruct(
    std::string* opt_string, const T& options,
268
    const std::unordered_map<std::string, OptionTypeInfo>& type_info,
269 270
    const std::string& delimiter);

D
Dmitri Smirnov 已提交
271
namespace {
272 273
template <typename T>
bool ParseEnum(const std::unordered_map<std::string, T>& type_map,
S
SherlockNoMad 已提交
274 275 276 277 278 279 280 281 282
               const std::string& type, T* value) {
  auto iter = type_map.find(type);
  if (iter != type_map.end()) {
    *value = iter->second;
    return true;
  }
  return false;
}

283 284
template <typename T>
bool SerializeEnum(const std::unordered_map<std::string, T>& type_map,
S
SherlockNoMad 已提交
285 286 287 288
                   const T& type, std::string* value) {
  for (const auto& pair : type_map) {
    if (pair.second == type) {
      *value = pair.first;
289
      return true;
S
SherlockNoMad 已提交
290
    }
291
  }
S
SherlockNoMad 已提交
292
  return false;
293 294 295 296 297 298 299 300 301 302 303
}

bool SerializeVectorCompressionType(const std::vector<CompressionType>& types,
                                    std::string* value) {
  std::stringstream ss;
  bool result;
  for (size_t i = 0; i < types.size(); ++i) {
    if (i > 0) {
      ss << ':';
    }
    std::string string_type;
S
SherlockNoMad 已提交
304
    result = SerializeEnum<CompressionType>(compression_type_string_map,
305
                                            types[i], &string_type);
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    if (result == false) {
      return result;
    }
    ss << string_type;
  }
  *value = ss.str();
  return true;
}

bool ParseVectorCompressionType(
    const std::string& value,
    std::vector<CompressionType>* compression_per_level) {
  compression_per_level->clear();
  size_t start = 0;
  while (start < value.size()) {
    size_t end = value.find(':', start);
    bool is_ok;
    CompressionType type;
    if (end == std::string::npos) {
325 326
      is_ok = ParseEnum<CompressionType>(compression_type_string_map,
                                         value.substr(start), &type);
327 328 329 330 331 332
      if (!is_ok) {
        return false;
      }
      compression_per_level->emplace_back(type);
      break;
    } else {
333 334
      is_ok = ParseEnum<CompressionType>(
          compression_type_string_map, value.substr(start, end - start), &type);
335 336 337 338 339 340 341 342 343 344
      if (!is_ok) {
        return false;
      }
      compression_per_level->emplace_back(type);
      start = end + 1;
    }
  }
  return true;
}

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
// This is to handle backward compatibility, where compaction_options_fifo
// could be assigned a single scalar value, say, like "23", which would be
// assigned to max_table_files_size.
bool FIFOCompactionOptionsSpecialCase(const std::string& opt_str,
                                      CompactionOptionsFIFO* options) {
  if (opt_str.find("=") != std::string::npos) {
    // New format. Go do your new parsing using ParseStructOptions.
    return false;
  }

  // Old format. Parse just a single uint64_t value.
  options->max_table_files_size = ParseUint64(opt_str);
  return true;
}

template <typename T>
bool SerializeStruct(
    const T& options, std::string* value,
363
    const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
364 365 366 367 368 369 370 371 372 373 374 375
  std::string opt_str;
  Status s = GetStringFromStruct(&opt_str, options, type_info_map, ";");
  if (!s.ok()) {
    return false;
  }
  *value = "{" + opt_str + "}";
  return true;
}

template <typename T>
bool ParseSingleStructOption(
    const std::string& opt_val_str, T* options,
376
    const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
377 378 379 380 381 382 383 384
  size_t end = opt_val_str.find('=');
  std::string key = opt_val_str.substr(0, end);
  std::string value = opt_val_str.substr(end + 1);
  auto iter = type_info_map.find(key);
  if (iter == type_info_map.end()) {
    return false;
  }
  const auto& opt_info = iter->second;
385 386 387 388 389
  if (opt_info.verification == OptionVerificationType::kDeprecated) {
    // Should also skip deprecated sub-options such as
    // fifo_compaction_options_type_info.ttl
    return true;
  }
390 391 392 393 394 395 396 397
  return ParseOptionHelper(
      reinterpret_cast<char*>(options) + opt_info.mutable_offset, opt_info.type,
      value);
}

template <typename T>
bool ParseStructOptions(
    const std::string& opt_str, T* options,
398
    const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
  assert(!opt_str.empty());

  size_t start = 0;
  if (opt_str[0] == '{') {
    start++;
  }
  while ((start != std::string::npos) && (start < opt_str.size())) {
    if (opt_str[start] == '}') {
      break;
    }
    size_t end = opt_str.find(';', start);
    size_t len = (end == std::string::npos) ? end : end - start;
    if (!ParseSingleStructOption(opt_str.substr(start, len), options,
                                 type_info_map)) {
      return false;
    }
    start = (end == std::string::npos) ? end : end + 1;
  }
  return true;
}
419
}  // anonymouse namespace
420

421 422 423 424
bool ParseSliceTransformHelper(
    const std::string& kFixedPrefixName, const std::string& kCappedPrefixName,
    const std::string& value,
    std::shared_ptr<const SliceTransform>* slice_transform) {
425 426
  const char* no_op_name = "rocksdb.Noop";
  size_t no_op_length = strlen(no_op_name);
427 428 429 430 431 432 433 434 435 436 437
  auto& pe_value = value;
  if (pe_value.size() > kFixedPrefixName.size() &&
      pe_value.compare(0, kFixedPrefixName.size(), kFixedPrefixName) == 0) {
    int prefix_length = ParseInt(trim(value.substr(kFixedPrefixName.size())));
    slice_transform->reset(NewFixedPrefixTransform(prefix_length));
  } else if (pe_value.size() > kCappedPrefixName.size() &&
             pe_value.compare(0, kCappedPrefixName.size(), kCappedPrefixName) ==
                 0) {
    int prefix_length =
        ParseInt(trim(pe_value.substr(kCappedPrefixName.size())));
    slice_transform->reset(NewCappedPrefixTransform(prefix_length));
438 439 440 441
  } else if (pe_value.size() == no_op_length &&
             pe_value.compare(0, no_op_length, no_op_name) == 0) {
    const SliceTransform* no_op_transform = NewNoopTransform();
    slice_transform->reset(no_op_transform);
442
  } else if (value == kNullptrString) {
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
    slice_transform->reset();
  } else {
    return false;
  }

  return true;
}

bool ParseSliceTransform(
    const std::string& value,
    std::shared_ptr<const SliceTransform>* slice_transform) {
  // While we normally don't convert the string representation of a
  // pointer-typed option into its instance, here we do so for backward
  // compatibility as we allow this action in SetOption().

  // TODO(yhchiang): A possible better place for these serialization /
  // deserialization is inside the class definition of pointer-typed
  // option itself, but this requires a bigger change of public API.
  bool result =
      ParseSliceTransformHelper("fixed:", "capped:", value, slice_transform);
  if (result) {
    return result;
  }
  result = ParseSliceTransformHelper(
      "rocksdb.FixedPrefix.", "rocksdb.CappedPrefix.", value, slice_transform);
  if (result) {
    return result;
  }
  // TODO(yhchiang): we can further support other default
  //                 SliceTransforms here.
  return false;
}

476 477 478 479 480 481 482 483 484
bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
                       const std::string& value) {
  switch (opt_type) {
    case OptionType::kBoolean:
      *reinterpret_cast<bool*>(opt_address) = ParseBoolean("", value);
      break;
    case OptionType::kInt:
      *reinterpret_cast<int*>(opt_address) = ParseInt(value);
      break;
Z
Zhongyi Xie 已提交
485 486 487 488 489 490
    case OptionType::kInt32T:
      *reinterpret_cast<int32_t*>(opt_address) = ParseInt32(value);
      break;
    case OptionType::kInt64T:
      PutUnaligned(reinterpret_cast<int64_t*>(opt_address), ParseInt64(value));
      break;
Y
Yi Wu 已提交
491 492 493
    case OptionType::kVectorInt:
      *reinterpret_cast<std::vector<int>*>(opt_address) = ParseVectorInt(value);
      break;
494 495 496 497 498 499 500
    case OptionType::kUInt:
      *reinterpret_cast<unsigned int*>(opt_address) = ParseUint32(value);
      break;
    case OptionType::kUInt32T:
      *reinterpret_cast<uint32_t*>(opt_address) = ParseUint32(value);
      break;
    case OptionType::kUInt64T:
T
Tomas Kolda 已提交
501
      PutUnaligned(reinterpret_cast<uint64_t*>(opt_address), ParseUint64(value));
502 503
      break;
    case OptionType::kSizeT:
T
Tomas Kolda 已提交
504
      PutUnaligned(reinterpret_cast<size_t*>(opt_address), ParseSizeT(value));
505 506 507 508 509 510 511 512
      break;
    case OptionType::kString:
      *reinterpret_cast<std::string*>(opt_address) = value;
      break;
    case OptionType::kDouble:
      *reinterpret_cast<double*>(opt_address) = ParseDouble(value);
      break;
    case OptionType::kCompactionStyle:
513 514 515
      return ParseEnum<CompactionStyle>(
          compaction_style_string_map, value,
          reinterpret_cast<CompactionStyle*>(opt_address));
516 517 518 519
    case OptionType::kCompactionPri:
      return ParseEnum<CompactionPri>(
          compaction_pri_string_map, value,
          reinterpret_cast<CompactionPri*>(opt_address));
520
    case OptionType::kCompressionType:
521 522 523
      return ParseEnum<CompressionType>(
          compression_type_string_map, value,
          reinterpret_cast<CompressionType*>(opt_address));
524 525 526 527 528 529 530
    case OptionType::kVectorCompressionType:
      return ParseVectorCompressionType(
          value, reinterpret_cast<std::vector<CompressionType>*>(opt_address));
    case OptionType::kSliceTransform:
      return ParseSliceTransform(
          value, reinterpret_cast<std::shared_ptr<const SliceTransform>*>(
                     opt_address));
531
    case OptionType::kChecksumType:
532 533 534
      return ParseEnum<ChecksumType>(
          checksum_type_string_map, value,
          reinterpret_cast<ChecksumType*>(opt_address));
535
    case OptionType::kBlockBasedTableIndexType:
S
SherlockNoMad 已提交
536
      return ParseEnum<BlockBasedTableOptions::IndexType>(
537 538
          block_base_table_index_type_string_map, value,
          reinterpret_cast<BlockBasedTableOptions::IndexType*>(opt_address));
539 540 541 542 543
    case OptionType::kBlockBasedTableDataBlockIndexType:
      return ParseEnum<BlockBasedTableOptions::DataBlockIndexType>(
          block_base_table_data_block_index_type_string_map, value,
          reinterpret_cast<BlockBasedTableOptions::DataBlockIndexType*>(
              opt_address));
544 545
    case OptionType::kBlockBasedTableIndexShorteningMode:
      return ParseEnum<BlockBasedTableOptions::IndexShorteningMode>(
546 547 548
          block_base_table_index_shortening_mode_string_map, value,
          reinterpret_cast<BlockBasedTableOptions::IndexShorteningMode*>(
              opt_address));
549
    case OptionType::kEncodingType:
550 551 552
      return ParseEnum<EncodingType>(
          encoding_type_string_map, value,
          reinterpret_cast<EncodingType*>(opt_address));
553 554 555 556 557 558 559 560 561 562 563 564
    case OptionType::kWALRecoveryMode:
      return ParseEnum<WALRecoveryMode>(
          wal_recovery_mode_string_map, value,
          reinterpret_cast<WALRecoveryMode*>(opt_address));
    case OptionType::kAccessHint:
      return ParseEnum<DBOptions::AccessHint>(
          access_hint_string_map, value,
          reinterpret_cast<DBOptions::AccessHint*>(opt_address));
    case OptionType::kInfoLogLevel:
      return ParseEnum<InfoLogLevel>(
          info_log_level_string_map, value,
          reinterpret_cast<InfoLogLevel*>(opt_address));
565 566 567 568 569 570 571 572 573
    case OptionType::kCompactionOptionsFIFO: {
      if (!FIFOCompactionOptionsSpecialCase(
              value, reinterpret_cast<CompactionOptionsFIFO*>(opt_address))) {
        return ParseStructOptions<CompactionOptionsFIFO>(
            value, reinterpret_cast<CompactionOptionsFIFO*>(opt_address),
            fifo_compaction_options_type_info);
      }
      return true;
    }
574 575 576 577 578
    case OptionType::kLRUCacheOptions: {
      return ParseStructOptions<LRUCacheOptions>(value,
          reinterpret_cast<LRUCacheOptions*>(opt_address),
          lru_cache_options_type_info);
    }
579 580 581 582 583 584 585 586
    case OptionType::kCompactionOptionsUniversal:
      return ParseStructOptions<CompactionOptionsUniversal>(
          value, reinterpret_cast<CompactionOptionsUniversal*>(opt_address),
          universal_compaction_options_type_info);
    case OptionType::kCompactionStopStyle:
      return ParseEnum<CompactionStopStyle>(
          compaction_stop_style_string_map, value,
          reinterpret_cast<CompactionStopStyle*>(opt_address));
587 588 589 590 591 592 593 594 595
    default:
      return false;
  }
  return true;
}

bool SerializeSingleOptionHelper(const char* opt_address,
                                 const OptionType opt_type,
                                 std::string* value) {
596

597 598 599 600 601 602 603 604
  assert(value);
  switch (opt_type) {
    case OptionType::kBoolean:
      *value = *(reinterpret_cast<const bool*>(opt_address)) ? "true" : "false";
      break;
    case OptionType::kInt:
      *value = ToString(*(reinterpret_cast<const int*>(opt_address)));
      break;
Z
Zhongyi Xie 已提交
605 606 607 608 609 610 611 612 613 614
    case OptionType::kInt32T:
      *value = ToString(*(reinterpret_cast<const int32_t*>(opt_address)));
      break;
    case OptionType::kInt64T:
      {
        int64_t v;
        GetUnaligned(reinterpret_cast<const int64_t*>(opt_address), &v);
        *value = ToString(v);
      }
      break;
Y
Yi Wu 已提交
615 616 617
    case OptionType::kVectorInt:
      return SerializeIntVector(
          *reinterpret_cast<const std::vector<int>*>(opt_address), value);
618 619 620 621 622 623 624
    case OptionType::kUInt:
      *value = ToString(*(reinterpret_cast<const unsigned int*>(opt_address)));
      break;
    case OptionType::kUInt32T:
      *value = ToString(*(reinterpret_cast<const uint32_t*>(opt_address)));
      break;
    case OptionType::kUInt64T:
T
Tomas Kolda 已提交
625 626 627 628 629
      {
        uint64_t v;
        GetUnaligned(reinterpret_cast<const uint64_t*>(opt_address), &v);
        *value = ToString(v);
      }
630 631
      break;
    case OptionType::kSizeT:
T
Tomas Kolda 已提交
632 633 634 635 636
      {
        size_t v;
        GetUnaligned(reinterpret_cast<const size_t*>(opt_address), &v);
        *value = ToString(v);
      }
637 638 639 640 641
      break;
    case OptionType::kDouble:
      *value = ToString(*(reinterpret_cast<const double*>(opt_address)));
      break;
    case OptionType::kString:
642 643
      *value = EscapeOptionString(
          *(reinterpret_cast<const std::string*>(opt_address)));
644 645
      break;
    case OptionType::kCompactionStyle:
646 647
      return SerializeEnum<CompactionStyle>(
          compaction_style_string_map,
S
SherlockNoMad 已提交
648
          *(reinterpret_cast<const CompactionStyle*>(opt_address)), value);
649 650 651 652
    case OptionType::kCompactionPri:
      return SerializeEnum<CompactionPri>(
          compaction_pri_string_map,
          *(reinterpret_cast<const CompactionPri*>(opt_address)), value);
653
    case OptionType::kCompressionType:
654 655
      return SerializeEnum<CompressionType>(
          compression_type_string_map,
656 657 658 659 660 661 662 663 664 665 666
          *(reinterpret_cast<const CompressionType*>(opt_address)), value);
    case OptionType::kVectorCompressionType:
      return SerializeVectorCompressionType(
          *(reinterpret_cast<const std::vector<CompressionType>*>(opt_address)),
          value);
      break;
    case OptionType::kSliceTransform: {
      const auto* slice_transform_ptr =
          reinterpret_cast<const std::shared_ptr<const SliceTransform>*>(
              opt_address);
      *value = slice_transform_ptr->get() ? slice_transform_ptr->get()->Name()
667
                                          : kNullptrString;
668 669 670 671 672 673 674
      break;
    }
    case OptionType::kTableFactory: {
      const auto* table_factory_ptr =
          reinterpret_cast<const std::shared_ptr<const TableFactory>*>(
              opt_address);
      *value = table_factory_ptr->get() ? table_factory_ptr->get()->Name()
675
                                        : kNullptrString;
676 677 678 679 680
      break;
    }
    case OptionType::kComparator: {
      // it's a const pointer of const Comparator*
      const auto* ptr = reinterpret_cast<const Comparator* const*>(opt_address);
681 682 683
      // Since the user-specified comparator will be wrapped by
      // InternalKeyComparator, we should persist the user-specified one
      // instead of InternalKeyComparator.
S
Siying Dong 已提交
684 685
      if (*ptr == nullptr) {
        *value = kNullptrString;
686
      } else {
S
Siying Dong 已提交
687 688 689 690 691
        const Comparator* root_comp = (*ptr)->GetRootComparator();
        if (root_comp == nullptr) {
          root_comp = (*ptr);
        }
        *value = root_comp->Name();
692
      }
693 694 695 696 697 698
      break;
    }
    case OptionType::kCompactionFilter: {
      // it's a const pointer of const CompactionFilter*
      const auto* ptr =
          reinterpret_cast<const CompactionFilter* const*>(opt_address);
699
      *value = *ptr ? (*ptr)->Name() : kNullptrString;
700 701 702 703 704 705
      break;
    }
    case OptionType::kCompactionFilterFactory: {
      const auto* ptr =
          reinterpret_cast<const std::shared_ptr<CompactionFilterFactory>*>(
              opt_address);
706
      *value = ptr->get() ? ptr->get()->Name() : kNullptrString;
707 708 709 710 711 712
      break;
    }
    case OptionType::kMemTableRepFactory: {
      const auto* ptr =
          reinterpret_cast<const std::shared_ptr<MemTableRepFactory>*>(
              opt_address);
713
      *value = ptr->get() ? ptr->get()->Name() : kNullptrString;
714 715 716 717 718
      break;
    }
    case OptionType::kMergeOperator: {
      const auto* ptr =
          reinterpret_cast<const std::shared_ptr<MergeOperator>*>(opt_address);
719 720 721 722 723 724 725 726 727 728
      *value = ptr->get() ? ptr->get()->Name() : kNullptrString;
      break;
    }
    case OptionType::kFilterPolicy: {
      const auto* ptr =
          reinterpret_cast<const std::shared_ptr<FilterPolicy>*>(opt_address);
      *value = ptr->get() ? ptr->get()->Name() : kNullptrString;
      break;
    }
    case OptionType::kChecksumType:
729 730
      return SerializeEnum<ChecksumType>(
          checksum_type_string_map,
731 732
          *reinterpret_cast<const ChecksumType*>(opt_address), value);
    case OptionType::kBlockBasedTableIndexType:
S
SherlockNoMad 已提交
733 734
      return SerializeEnum<BlockBasedTableOptions::IndexType>(
          block_base_table_index_type_string_map,
735 736 737
          *reinterpret_cast<const BlockBasedTableOptions::IndexType*>(
              opt_address),
          value);
738 739 740 741 742 743
    case OptionType::kBlockBasedTableDataBlockIndexType:
      return SerializeEnum<BlockBasedTableOptions::DataBlockIndexType>(
          block_base_table_data_block_index_type_string_map,
          *reinterpret_cast<const BlockBasedTableOptions::DataBlockIndexType*>(
              opt_address),
          value);
744 745 746 747 748 749
    case OptionType::kBlockBasedTableIndexShorteningMode:
      return SerializeEnum<BlockBasedTableOptions::IndexShorteningMode>(
          block_base_table_index_shortening_mode_string_map,
          *reinterpret_cast<const BlockBasedTableOptions::IndexShorteningMode*>(
              opt_address),
          value);
750 751 752 753 754
    case OptionType::kFlushBlockPolicyFactory: {
      const auto* ptr =
          reinterpret_cast<const std::shared_ptr<FlushBlockPolicyFactory>*>(
              opt_address);
      *value = ptr->get() ? ptr->get()->Name() : kNullptrString;
755 756
      break;
    }
757
    case OptionType::kEncodingType:
758 759
      return SerializeEnum<EncodingType>(
          encoding_type_string_map,
760
          *reinterpret_cast<const EncodingType*>(opt_address), value);
761 762 763 764 765 766 767 768 769 770 771 772
    case OptionType::kWALRecoveryMode:
      return SerializeEnum<WALRecoveryMode>(
          wal_recovery_mode_string_map,
          *reinterpret_cast<const WALRecoveryMode*>(opt_address), value);
    case OptionType::kAccessHint:
      return SerializeEnum<DBOptions::AccessHint>(
          access_hint_string_map,
          *reinterpret_cast<const DBOptions::AccessHint*>(opt_address), value);
    case OptionType::kInfoLogLevel:
      return SerializeEnum<InfoLogLevel>(
          info_log_level_string_map,
          *reinterpret_cast<const InfoLogLevel*>(opt_address), value);
773
    case OptionType::kCompactionOptionsFIFO:
774 775 776
      return SerializeStruct<CompactionOptionsFIFO>(
          *reinterpret_cast<const CompactionOptionsFIFO*>(opt_address), value,
          fifo_compaction_options_type_info);
777 778 779 780 781 782 783 784
    case OptionType::kCompactionOptionsUniversal:
      return SerializeStruct<CompactionOptionsUniversal>(
          *reinterpret_cast<const CompactionOptionsUniversal*>(opt_address),
          value, universal_compaction_options_type_info);
    case OptionType::kCompactionStopStyle:
      return SerializeEnum<CompactionStopStyle>(
          compaction_stop_style_string_map,
          *reinterpret_cast<const CompactionStopStyle*>(opt_address), value);
785 786 787 788 789 790
    default:
      return false;
  }
  return true;
}

791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
Status ParseCompressionOptions(const std::string& value,
                               const std::string& name,
                               CompressionOptions& compression_opts) {
  size_t start = 0;
  size_t end = value.find(':');
  if (end == std::string::npos) {
    return Status::InvalidArgument("unable to parse the specified CF option " +
                                   name);
  }
  compression_opts.window_bits = ParseInt(value.substr(start, end - start));
  start = end + 1;
  end = value.find(':', start);
  if (end == std::string::npos) {
    return Status::InvalidArgument("unable to parse the specified CF option " +
                                   name);
  }
  compression_opts.level = ParseInt(value.substr(start, end - start));
  start = end + 1;
  if (start >= value.size()) {
    return Status::InvalidArgument("unable to parse the specified CF option " +
                                   name);
  }
  end = value.find(':', start);
  compression_opts.strategy =
      ParseInt(value.substr(start, value.size() - start));
  // max_dict_bytes is optional for backwards compatibility
  if (end != std::string::npos) {
    start = end + 1;
    if (start >= value.size()) {
      return Status::InvalidArgument(
          "unable to parse the specified CF option " + name);
    }
    compression_opts.max_dict_bytes =
        ParseInt(value.substr(start, value.size() - start));
    end = value.find(':', start);
  }
  // zstd_max_train_bytes is optional for backwards compatibility
  if (end != std::string::npos) {
    start = end + 1;
    if (start >= value.size()) {
      return Status::InvalidArgument(
          "unable to parse the specified CF option " + name);
    }
    compression_opts.zstd_max_train_bytes =
        ParseInt(value.substr(start, value.size() - start));
    end = value.find(':', start);
  }
838 839 840 841 842 843 844 845 846 847 848
  // parallel_threads is optional for backwards compatibility
  if (end != std::string::npos) {
    start = end + 1;
    if (start >= value.size()) {
      return Status::InvalidArgument(
          "unable to parse the specified CF option " + name);
    }
    compression_opts.parallel_threads =
        ParseInt(value.substr(start, value.size() - start));
    end = value.find(':', start);
  }
849 850 851 852 853 854 855 856 857 858 859 860 861
  // enabled is optional for backwards compatibility
  if (end != std::string::npos) {
    start = end + 1;
    if (start >= value.size()) {
      return Status::InvalidArgument(
          "unable to parse the specified CF option " + name);
    }
    compression_opts.enabled =
        ParseBoolean("", value.substr(start, value.size() - start));
  }
  return Status::OK();
}

862
Status GetMutableOptionsFromStrings(
863 864
    const MutableCFOptions& base_options,
    const std::unordered_map<std::string, std::string>& options_map,
865
    Logger* info_log, MutableCFOptions* new_options) {
866 867
  assert(new_options);
  *new_options = base_options;
868
  for (const auto& o : options_map) {
869 870 871
    auto& option_name = o.first;
    auto& option_value = o.second;

872
    try {
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
      if (option_name == kOptNameBMCompOpts) {
        Status s =
            ParseCompressionOptions(option_value, option_name,
                                    new_options->bottommost_compression_opts);
        if (!s.ok()) {
          return s;
        }
      } else if (option_name == kOptNameCompOpts) {
        Status s = ParseCompressionOptions(option_value, option_name,
                                           new_options->compression_opts);
        if (!s.ok()) {
          return s;
        }
      } else {
        auto iter = cf_options_type_info.find(option_name);
        if (iter == cf_options_type_info.end()) {
          return Status::InvalidArgument("Unrecognized option: " + option_name);
        }
        const auto& opt_info = iter->second;
        if (!opt_info.is_mutable) {
          return Status::InvalidArgument("Option not changeable: " +
                                         option_name);
        }
        if (opt_info.verification == OptionVerificationType::kDeprecated) {
          // log warning when user tries to set a deprecated option but don't
          // fail the call for compatibility.
          ROCKS_LOG_WARN(info_log,
                         "%s is a deprecated option and cannot be set",
                         option_name.c_str());
          continue;
        }
        bool is_ok = ParseOptionHelper(
            reinterpret_cast<char*>(new_options) + opt_info.mutable_offset,
            opt_info.type, option_value);
        if (!is_ok) {
          return Status::InvalidArgument("Error parsing " + option_name);
        }
910
      }
911
    } catch (std::exception& e) {
912
      return Status::InvalidArgument("Error parsing " + option_name + ":" +
913
                                     std::string(e.what()));
914 915
    }
  }
916
  return Status::OK();
917 918
}

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
Status GetMutableDBOptionsFromStrings(
    const MutableDBOptions& base_options,
    const std::unordered_map<std::string, std::string>& options_map,
    MutableDBOptions* new_options) {
  assert(new_options);
  *new_options = base_options;
  for (const auto& o : options_map) {
    try {
      auto iter = db_options_type_info.find(o.first);
      if (iter == db_options_type_info.end()) {
        return Status::InvalidArgument("Unrecognized option: " + o.first);
      }
      const auto& opt_info = iter->second;
      if (!opt_info.is_mutable) {
        return Status::InvalidArgument("Option not changeable: " + o.first);
      }
      bool is_ok = ParseOptionHelper(
          reinterpret_cast<char*>(new_options) + opt_info.mutable_offset,
          opt_info.type, o.second);
      if (!is_ok) {
        return Status::InvalidArgument("Error parsing " + o.first);
      }
    } catch (std::exception& e) {
      return Status::InvalidArgument("Error parsing " + o.first + ":" +
                                     std::string(e.what()));
    }
  }
  return Status::OK();
}

949 950
Status StringToMap(const std::string& opts_str,
                   std::unordered_map<std::string, std::string>* opts_map) {
L
Lei Jin 已提交
951 952
  assert(opts_map);
  // Example:
953 954
  //   opts_str = "write_buffer_size=1024;max_write_buffer_number=2;"
  //              "nested_opt={opt1=1;opt2=2};max_bytes_for_level_base=100"
L
Lei Jin 已提交
955 956 957 958 959
  size_t pos = 0;
  std::string opts = trim(opts_str);
  while (pos < opts.size()) {
    size_t eq_pos = opts.find('=', pos);
    if (eq_pos == std::string::npos) {
960
      return Status::InvalidArgument("Mismatched key value pair, '=' expected");
L
Lei Jin 已提交
961 962
    }
    std::string key = trim(opts.substr(pos, eq_pos - pos));
963 964 965
    if (key.empty()) {
      return Status::InvalidArgument("Empty key found");
    }
L
Lei Jin 已提交
966

967 968 969 970 971 972 973 974
    // skip space after '=' and look for '{' for possible nested options
    pos = eq_pos + 1;
    while (pos < opts.size() && isspace(opts[pos])) {
      ++pos;
    }
    // Empty value at the end
    if (pos >= opts.size()) {
      (*opts_map)[key] = "";
L
Lei Jin 已提交
975
      break;
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
    }
    if (opts[pos] == '{') {
      int count = 1;
      size_t brace_pos = pos + 1;
      while (brace_pos < opts.size()) {
        if (opts[brace_pos] == '{') {
          ++count;
        } else if (opts[brace_pos] == '}') {
          --count;
          if (count == 0) {
            break;
          }
        }
        ++brace_pos;
      }
      // found the matching closing brace
      if (count == 0) {
        (*opts_map)[key] = trim(opts.substr(pos + 1, brace_pos - pos - 1));
        // skip all whitespace and move to the next ';'
        // brace_pos points to the next position after the matching '}'
        pos = brace_pos + 1;
        while (pos < opts.size() && isspace(opts[pos])) {
          ++pos;
        }
        if (pos < opts.size() && opts[pos] != ';') {
          return Status::InvalidArgument(
              "Unexpected chars after nested options");
        }
        ++pos;
      } else {
        return Status::InvalidArgument(
            "Mismatched curly braces for nested options");
      }
L
Lei Jin 已提交
1009
    } else {
1010 1011 1012 1013 1014 1015 1016 1017 1018
      size_t sc_pos = opts.find(';', pos);
      if (sc_pos == std::string::npos) {
        (*opts_map)[key] = trim(opts.substr(pos));
        // It either ends with a trailing semi-colon or the last key-value pair
        break;
      } else {
        (*opts_map)[key] = trim(opts.substr(pos, sc_pos - pos));
      }
      pos = sc_pos + 1;
L
Lei Jin 已提交
1019 1020 1021
    }
  }

1022
  return Status::OK();
L
Lei Jin 已提交
1023 1024
}

1025 1026 1027 1028
Status ParseColumnFamilyOption(const std::string& name,
                               const std::string& org_value,
                               ColumnFamilyOptions* new_options,
                               bool input_strings_escaped = false) {
1029
  const std::string& value =
1030
      input_strings_escaped ? UnescapeOptionString(org_value) : org_value;
1031
  try {
Y
Yi Wu 已提交
1032
    if (name == "block_based_table_factory") {
1033 1034
      // Nested options
      BlockBasedTableOptions table_opt, base_table_options;
S
Siying Dong 已提交
1035 1036 1037
      BlockBasedTableFactory* block_based_table_factory =
          static_cast_with_check<BlockBasedTableFactory, TableFactory>(
              new_options->table_factory.get());
1038
      if (block_based_table_factory != nullptr) {
S
SherlockNoMad 已提交
1039
        base_table_options = block_based_table_factory->table_options();
1040 1041 1042 1043
      }
      Status table_opt_s = GetBlockBasedTableOptionsFromString(
          base_table_options, value, &table_opt);
      if (!table_opt_s.ok()) {
1044 1045
        return Status::InvalidArgument(
            "unable to parse the specified CF option " + name);
1046 1047
      }
      new_options->table_factory.reset(NewBlockBasedTableFactory(table_opt));
1048 1049 1050
    } else if (name == "plain_table_factory") {
      // Nested options
      PlainTableOptions table_opt, base_table_options;
S
Siying Dong 已提交
1051 1052 1053
      PlainTableFactory* plain_table_factory =
          static_cast_with_check<PlainTableFactory, TableFactory>(
              new_options->table_factory.get());
1054
      if (plain_table_factory != nullptr) {
S
SherlockNoMad 已提交
1055
        base_table_options = plain_table_factory->table_options();
1056 1057 1058 1059
      }
      Status table_opt_s = GetPlainTableOptionsFromString(
          base_table_options, value, &table_opt);
      if (!table_opt_s.ok()) {
1060 1061
        return Status::InvalidArgument(
            "unable to parse the specified CF option " + name);
1062 1063
      }
      new_options->table_factory.reset(NewPlainTableFactory(table_opt));
1064 1065 1066 1067 1068 1069 1070 1071 1072
    } else if (name == "memtable") {
      std::unique_ptr<MemTableRepFactory> new_mem_factory;
      Status mem_factory_s =
          GetMemTableRepFactoryFromString(value, &new_mem_factory);
      if (!mem_factory_s.ok()) {
        return Status::InvalidArgument(
            "unable to parse the specified CF option " + name);
      }
      new_options->memtable_factory.reset(new_mem_factory.release());
1073 1074 1075 1076 1077
    } else if (name == "bottommost_compression_opts") {
      Status s = ParseCompressionOptions(
          value, name, new_options->bottommost_compression_opts);
      if (!s.ok()) {
        return s;
1078
      }
1079 1080 1081 1082 1083
    } else if (name == "compression_opts") {
      Status s =
          ParseCompressionOptions(value, name, new_options->compression_opts);
      if (!s.ok()) {
        return s;
1084
      }
1085
    } else {
1086 1087 1088
      if (name == kNameComparator) {
        // Try to get comparator from object registry first.
        // Only support static comparator for now.
1089 1090 1091 1092
        Status status = ObjectRegistry::NewInstance()->NewStaticObject(
            value, &new_options->comparator);
        if (status.ok()) {
          return status;
1093
        }
1094 1095
      } else if (name == kNameMergeOperator) {
        // Try to get merge operator from object registry first.
1096 1097 1098 1099
        std::shared_ptr<MergeOperator> mo;
        Status status =
            ObjectRegistry::NewInstance()->NewSharedObject<MergeOperator>(
                value, &new_options->merge_operator);
1100
        // Only support static comparator for now.
1101 1102
        if (status.ok()) {
          return status;
1103
        }
1104
      }
1105

1106 1107
      auto iter = cf_options_type_info.find(name);
      if (iter == cf_options_type_info.end()) {
1108 1109
        return Status::InvalidArgument(
            "Unable to parse the specified CF option " + name);
1110 1111
      }
      const auto& opt_info = iter->second;
1112 1113
      if (opt_info.verification != OptionVerificationType::kDeprecated &&
          ParseOptionHelper(
1114 1115 1116 1117 1118 1119
              reinterpret_cast<char*>(new_options) + opt_info.offset,
              opt_info.type, value)) {
        return Status::OK();
      }
      switch (opt_info.verification) {
        case OptionVerificationType::kByName:
1120
        case OptionVerificationType::kByNameAllowNull:
1121
        case OptionVerificationType::kByNameAllowFromNull:
1122 1123 1124 1125 1126 1127 1128 1129 1130
          return Status::NotSupported(
              "Deserializing the specified CF option " + name +
                  " is not supported");
        case OptionVerificationType::kDeprecated:
          return Status::OK();
        default:
          return Status::InvalidArgument(
              "Unable to parse the specified CF option " + name);
      }
1131
    }
D
Dmitri Smirnov 已提交
1132
  } catch (const std::exception&) {
1133 1134
    return Status::InvalidArgument(
        "unable to parse the specified option " + name);
1135
  }
1136
  return Status::OK();
1137 1138
}

1139 1140 1141
template <typename T>
bool SerializeSingleStructOption(
    std::string* opt_string, const T& options,
1142
    const std::unordered_map<std::string, OptionTypeInfo>& type_info,
1143 1144 1145
    const std::string& name, const std::string& delimiter) {
  auto iter = type_info.find(name);
  if (iter == type_info.end()) {
1146 1147 1148 1149
    return false;
  }
  auto& opt_info = iter->second;
  const char* opt_address =
1150
      reinterpret_cast<const char*>(&options) + opt_info.offset;
1151
  std::string value;
1152 1153
  bool result = SerializeSingleOptionHelper(opt_address, opt_info.type, &value);
  if (result) {
1154
    *opt_string = name + "=" + value + delimiter;
1155
  }
1156
  return result;
1157 1158
}

1159 1160 1161
template <typename T>
Status GetStringFromStruct(
    std::string* opt_string, const T& options,
1162
    const std::unordered_map<std::string, OptionTypeInfo>& type_info,
1163
    const std::string& delimiter) {
1164 1165
  assert(opt_string);
  opt_string->clear();
1166
  for (auto iter = type_info.begin(); iter != type_info.end(); ++iter) {
1167 1168 1169 1170 1171
    if (iter->second.verification == OptionVerificationType::kDeprecated) {
      // If the option is no longer used in rocksdb and marked as deprecated,
      // we skip it in the serialization.
      continue;
    }
1172
    std::string single_output;
1173 1174
    bool result = SerializeSingleStructOption<T>(
        &single_output, options, type_info, iter->first, delimiter);
1175 1176
    if (result) {
      opt_string->append(single_output);
1177 1178 1179
    } else {
      return Status::InvalidArgument("failed to serialize %s\n",
                                     iter->first.c_str());
1180
    }
1181
    assert(result);
1182 1183 1184 1185
  }
  return Status::OK();
}

1186 1187 1188 1189 1190
Status GetStringFromDBOptions(std::string* opt_string,
                              const DBOptions& db_options,
                              const std::string& delimiter) {
  return GetStringFromStruct<DBOptions>(opt_string, db_options,
                                        db_options_type_info, delimiter);
1191 1192
}

1193 1194 1195
Status GetStringFromColumnFamilyOptions(std::string* opt_string,
                                        const ColumnFamilyOptions& cf_options,
                                        const std::string& delimiter) {
1196 1197
  return GetStringFromStruct<ColumnFamilyOptions>(
      opt_string, cf_options, cf_options_type_info, delimiter);
1198 1199
}

1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
Status GetStringFromCompressionType(std::string* compression_str,
                                    CompressionType compression_type) {
  bool ok = SerializeEnum<CompressionType>(compression_type_string_map,
                                           compression_type, compression_str);
  if (ok) {
    return Status::OK();
  } else {
    return Status::InvalidArgument("Invalid compression types");
  }
}

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
std::vector<CompressionType> GetSupportedCompressions() {
  std::vector<CompressionType> supported_compressions;
  for (const auto& comp_to_name : compression_type_string_map) {
    CompressionType t = comp_to_name.second;
    if (t != kDisableCompressionOption && CompressionTypeSupported(t)) {
      supported_compressions.push_back(t);
    }
  }
  return supported_compressions;
}

1222 1223 1224 1225
Status ParseDBOption(const std::string& name,
                     const std::string& org_value,
                     DBOptions* new_options,
                     bool input_strings_escaped = false) {
1226
  const std::string& value =
1227
      input_strings_escaped ? UnescapeOptionString(org_value) : org_value;
1228
  try {
1229
    if (name == "rate_limiter_bytes_per_sec") {
I
Igor Canadi 已提交
1230 1231
      new_options->rate_limiter.reset(
          NewGenericRateLimiter(static_cast<int64_t>(ParseUint64(value))));
1232 1233
    } else if (name == kNameEnv) {
      // Currently `Env` can be deserialized from object registry only.
1234 1235
      Env* env = new_options->env;
      Status status = Env::LoadEnv(value, &env);
1236
      // Only support static env for now.
1237
      if (status.ok()) {
1238 1239
        new_options->env = env;
      }
1240
    } else {
1241 1242
      auto iter = db_options_type_info.find(name);
      if (iter == db_options_type_info.end()) {
1243
        return Status::InvalidArgument("Unrecognized option DBOptions:", name);
1244
      }
1245
      const auto& opt_info = iter->second;
1246 1247
      if (opt_info.verification != OptionVerificationType::kDeprecated &&
          ParseOptionHelper(
1248 1249 1250 1251 1252 1253
              reinterpret_cast<char*>(new_options) + opt_info.offset,
              opt_info.type, value)) {
        return Status::OK();
      }
      switch (opt_info.verification) {
        case OptionVerificationType::kByName:
1254
        case OptionVerificationType::kByNameAllowNull:
1255 1256 1257 1258 1259 1260 1261 1262
          return Status::NotSupported(
              "Deserializing the specified DB option " + name +
                  " is not supported");
        case OptionVerificationType::kDeprecated:
          return Status::OK();
        default:
          return Status::InvalidArgument(
              "Unable to parse the specified DB option " + name);
1263
      }
1264
    }
D
Dmitri Smirnov 已提交
1265
  } catch (const std::exception&) {
1266
    return Status::InvalidArgument("Unable to parse DBOptions:", name);
1267
  }
1268
  return Status::OK();
1269
}
L
Lei Jin 已提交
1270

1271
Status GetColumnFamilyOptionsFromMap(
L
Lei Jin 已提交
1272 1273
    const ColumnFamilyOptions& base_options,
    const std::unordered_map<std::string, std::string>& opts_map,
1274 1275
    ColumnFamilyOptions* new_options, bool input_strings_escaped,
    bool ignore_unknown_options) {
1276
  return GetColumnFamilyOptionsFromMapInternal(
1277 1278
      base_options, opts_map, new_options, input_strings_escaped, nullptr,
      ignore_unknown_options);
1279 1280 1281 1282 1283 1284
}

Status GetColumnFamilyOptionsFromMapInternal(
    const ColumnFamilyOptions& base_options,
    const std::unordered_map<std::string, std::string>& opts_map,
    ColumnFamilyOptions* new_options, bool input_strings_escaped,
1285 1286
    std::vector<std::string>* unsupported_options_names,
    bool ignore_unknown_options) {
1287 1288
  assert(new_options);
  *new_options = base_options;
1289 1290 1291
  if (unsupported_options_names) {
    unsupported_options_names->clear();
  }
L
Lei Jin 已提交
1292
  for (const auto& o : opts_map) {
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
    auto s = ParseColumnFamilyOption(o.first, o.second, new_options,
                                 input_strings_escaped);
    if (!s.ok()) {
      if (s.IsNotSupported()) {
        // If the deserialization of the specified option is not supported
        // and an output vector of unsupported_options is provided, then
        // we log the name of the unsupported option and proceed.
        if (unsupported_options_names != nullptr) {
          unsupported_options_names->push_back(o.first);
        }
        // Note that we still return Status::OK in such case to maintain
        // the backward compatibility in the old public API defined in
        // rocksdb/convenience.h
1306 1307
      } else if (s.IsInvalidArgument() && ignore_unknown_options) {
        continue;
1308
      } else {
1309 1310
        // Restore "new_options" to the default "base_options".
        *new_options = base_options;
1311
        return s;
1312
      }
L
Lei Jin 已提交
1313 1314
    }
  }
1315
  return Status::OK();
L
Lei Jin 已提交
1316 1317
}

1318
Status GetColumnFamilyOptionsFromString(
L
Lei Jin 已提交
1319 1320 1321 1322
    const ColumnFamilyOptions& base_options,
    const std::string& opts_str,
    ColumnFamilyOptions* new_options) {
  std::unordered_map<std::string, std::string> opts_map;
1323 1324
  Status s = StringToMap(opts_str, &opts_map);
  if (!s.ok()) {
1325
    *new_options = base_options;
1326
    return s;
L
Lei Jin 已提交
1327 1328 1329 1330
  }
  return GetColumnFamilyOptionsFromMap(base_options, opts_map, new_options);
}

1331
Status GetDBOptionsFromMap(
L
Lei Jin 已提交
1332 1333
    const DBOptions& base_options,
    const std::unordered_map<std::string, std::string>& opts_map,
1334 1335 1336 1337 1338
    DBOptions* new_options, bool input_strings_escaped,
    bool ignore_unknown_options) {
  return GetDBOptionsFromMapInternal(base_options, opts_map, new_options,
                                     input_strings_escaped, nullptr,
                                     ignore_unknown_options);
1339 1340 1341 1342 1343 1344
}

Status GetDBOptionsFromMapInternal(
    const DBOptions& base_options,
    const std::unordered_map<std::string, std::string>& opts_map,
    DBOptions* new_options, bool input_strings_escaped,
1345 1346
    std::vector<std::string>* unsupported_options_names,
    bool ignore_unknown_options) {
L
Lei Jin 已提交
1347 1348
  assert(new_options);
  *new_options = base_options;
1349 1350 1351
  if (unsupported_options_names) {
    unsupported_options_names->clear();
  }
L
Lei Jin 已提交
1352
  for (const auto& o : opts_map) {
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
    auto s = ParseDBOption(o.first, o.second,
                           new_options, input_strings_escaped);
    if (!s.ok()) {
      if (s.IsNotSupported()) {
        // If the deserialization of the specified option is not supported
        // and an output vector of unsupported_options is provided, then
        // we log the name of the unsupported option and proceed.
        if (unsupported_options_names != nullptr) {
          unsupported_options_names->push_back(o.first);
        }
        // Note that we still return Status::OK in such case to maintain
        // the backward compatibility in the old public API defined in
        // rocksdb/convenience.h
1366 1367
      } else if (s.IsInvalidArgument() && ignore_unknown_options) {
        continue;
1368
      } else {
1369 1370
        // Restore "new_options" to the default "base_options".
        *new_options = base_options;
1371 1372
        return s;
      }
1373 1374
    }
  }
1375
  return Status::OK();
1376 1377
}

1378
Status GetDBOptionsFromString(
L
Lei Jin 已提交
1379 1380 1381 1382
    const DBOptions& base_options,
    const std::string& opts_str,
    DBOptions* new_options) {
  std::unordered_map<std::string, std::string> opts_map;
1383 1384
  Status s = StringToMap(opts_str, &opts_map);
  if (!s.ok()) {
1385
    *new_options = base_options;
1386
    return s;
L
Lei Jin 已提交
1387 1388 1389 1390
  }
  return GetDBOptionsFromMap(base_options, opts_map, new_options);
}

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
Status GetOptionsFromString(const Options& base_options,
                            const std::string& opts_str, Options* new_options) {
  std::unordered_map<std::string, std::string> opts_map;
  Status s = StringToMap(opts_str, &opts_map);
  if (!s.ok()) {
    return s;
  }
  DBOptions new_db_options(base_options);
  ColumnFamilyOptions new_cf_options(base_options);
  for (const auto& o : opts_map) {
1401 1402 1403
    if (ParseDBOption(o.first, o.second, &new_db_options).ok()) {
    } else if (ParseColumnFamilyOption(
        o.first, o.second, &new_cf_options).ok()) {
1404 1405 1406 1407 1408 1409 1410 1411
    } else {
      return Status::InvalidArgument("Can't parse option " + o.first);
    }
  }
  *new_options = Options(new_db_options, new_cf_options);
  return Status::OK();
}

1412 1413 1414
Status GetTableFactoryFromMap(
    const std::string& factory_name,
    const std::unordered_map<std::string, std::string>& opt_map,
1415
    std::shared_ptr<TableFactory>* table_factory, bool ignore_unknown_options) {
1416 1417 1418 1419
  Status s;
  if (factory_name == BlockBasedTableFactory().Name()) {
    BlockBasedTableOptions bbt_opt;
    s = GetBlockBasedTableOptionsFromMap(BlockBasedTableOptions(), opt_map,
1420 1421 1422
                                         &bbt_opt,
                                         true, /* input_strings_escaped */
                                         ignore_unknown_options);
1423 1424 1425 1426 1427
    if (!s.ok()) {
      return s;
    }
    table_factory->reset(new BlockBasedTableFactory(bbt_opt));
    return Status::OK();
1428 1429
  } else if (factory_name == PlainTableFactory().Name()) {
    PlainTableOptions pt_opt;
I
Islam AbdelRahman 已提交
1430
    s = GetPlainTableOptionsFromMap(PlainTableOptions(), opt_map, &pt_opt,
1431 1432
                                    true, /* input_strings_escaped */
                                    ignore_unknown_options);
1433 1434 1435 1436 1437
    if (!s.ok()) {
      return s;
    }
    table_factory->reset(new PlainTableFactory(pt_opt));
    return Status::OK();
1438 1439 1440 1441 1442 1443 1444
  }
  // Return OK for not supported table factories as TableFactory
  // Deserialization is optional.
  table_factory->reset();
  return Status::OK();
}

1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
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, false, 0}},
        {"allow_mmap_reads",
         {offsetof(struct DBOptions, allow_mmap_reads), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"allow_fallocate",
         {offsetof(struct DBOptions, allow_fallocate), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"allow_mmap_writes",
         {offsetof(struct DBOptions, allow_mmap_writes), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"use_direct_reads",
         {offsetof(struct DBOptions, use_direct_reads), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"use_direct_writes",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
          0}},
        {"use_direct_io_for_flush_and_compaction",
         {offsetof(struct DBOptions, use_direct_io_for_flush_and_compaction),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"allow_2pc",
         {offsetof(struct DBOptions, allow_2pc), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"allow_os_buffer",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, true,
          0}},
        {"create_if_missing",
         {offsetof(struct DBOptions, create_if_missing), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"create_missing_column_families",
         {offsetof(struct DBOptions, create_missing_column_families),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"disableDataSync",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
          0}},
        {"disable_data_sync",  // for compatibility
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
          0}},
        {"enable_thread_tracking",
         {offsetof(struct DBOptions, enable_thread_tracking),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"error_if_exists",
         {offsetof(struct DBOptions, error_if_exists), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"is_fd_close_on_exec",
         {offsetof(struct DBOptions, is_fd_close_on_exec), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"paranoid_checks",
         {offsetof(struct DBOptions, paranoid_checks), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"skip_log_error_on_recovery",
         {offsetof(struct DBOptions, skip_log_error_on_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"skip_stats_update_on_db_open",
         {offsetof(struct DBOptions, skip_stats_update_on_db_open),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
1514 1515 1516
        {"skip_checking_sst_file_sizes_on_db_open",
         {offsetof(struct DBOptions, skip_checking_sst_file_sizes_on_db_open),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
        {"new_table_reader_for_compaction_inputs",
         {offsetof(struct DBOptions, new_table_reader_for_compaction_inputs),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"compaction_readahead_size",
         {offsetof(struct DBOptions, compaction_readahead_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, compaction_readahead_size)}},
        {"random_access_max_buffer_size",
         {offsetof(struct DBOptions, random_access_max_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, false, 0}},
        {"use_adaptive_mutex",
         {offsetof(struct DBOptions, use_adaptive_mutex), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"use_fsync",
         {offsetof(struct DBOptions, use_fsync), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"max_background_jobs",
         {offsetof(struct DBOptions, max_background_jobs), OptionType::kInt,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, max_background_jobs)}},
        {"max_background_compactions",
         {offsetof(struct DBOptions, max_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, max_background_compactions)}},
        {"base_background_compactions",
         {offsetof(struct DBOptions, base_background_compactions),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, base_background_compactions)}},
        {"max_background_flushes",
         {offsetof(struct DBOptions, max_background_flushes), OptionType::kInt,
          OptionVerificationType::kNormal, false, 0}},
        {"max_file_opening_threads",
         {offsetof(struct DBOptions, max_file_opening_threads),
          OptionType::kInt, OptionVerificationType::kNormal, false, 0}},
        {"max_open_files",
         {offsetof(struct DBOptions, max_open_files), OptionType::kInt,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, max_open_files)}},
        {"table_cache_numshardbits",
         {offsetof(struct DBOptions, table_cache_numshardbits),
          OptionType::kInt, OptionVerificationType::kNormal, false, 0}},
        {"db_write_buffer_size",
         {offsetof(struct DBOptions, db_write_buffer_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
        {"keep_log_file_num",
         {offsetof(struct DBOptions, keep_log_file_num), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
        {"recycle_log_file_num",
         {offsetof(struct DBOptions, recycle_log_file_num), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
        {"log_file_time_to_roll",
         {offsetof(struct DBOptions, log_file_time_to_roll), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
        {"manifest_preallocation_size",
         {offsetof(struct DBOptions, manifest_preallocation_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, false, 0}},
        {"max_log_file_size",
         {offsetof(struct DBOptions, max_log_file_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
        {"db_log_dir",
         {offsetof(struct DBOptions, db_log_dir), OptionType::kString,
          OptionVerificationType::kNormal, false, 0}},
        {"wal_dir",
         {offsetof(struct DBOptions, wal_dir), OptionType::kString,
          OptionVerificationType::kNormal, false, 0}},
        {"max_subcompactions",
         {offsetof(struct DBOptions, max_subcompactions), OptionType::kUInt32T,
          OptionVerificationType::kNormal, false, 0}},
        {"WAL_size_limit_MB",
         {offsetof(struct DBOptions, WAL_size_limit_MB), OptionType::kUInt64T,
          OptionVerificationType::kNormal, false, 0}},
        {"WAL_ttl_seconds",
         {offsetof(struct DBOptions, WAL_ttl_seconds), OptionType::kUInt64T,
          OptionVerificationType::kNormal, false, 0}},
        {"bytes_per_sync",
         {offsetof(struct DBOptions, bytes_per_sync), OptionType::kUInt64T,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, bytes_per_sync)}},
        {"delayed_write_rate",
         {offsetof(struct DBOptions, delayed_write_rate), OptionType::kUInt64T,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, delayed_write_rate)}},
        {"delete_obsolete_files_period_micros",
         {offsetof(struct DBOptions, delete_obsolete_files_period_micros),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions,
                   delete_obsolete_files_period_micros)}},
        {"max_manifest_file_size",
         {offsetof(struct DBOptions, max_manifest_file_size),
          OptionType::kUInt64T, OptionVerificationType::kNormal, false, 0}},
        {"max_total_wal_size",
         {offsetof(struct DBOptions, max_total_wal_size), OptionType::kUInt64T,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, max_total_wal_size)}},
        {"wal_bytes_per_sync",
         {offsetof(struct DBOptions, wal_bytes_per_sync), OptionType::kUInt64T,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, wal_bytes_per_sync)}},
1615
        {"strict_bytes_per_sync",
1616 1617
         {offsetof(struct DBOptions, strict_bytes_per_sync),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
1618
          offsetof(struct MutableDBOptions, strict_bytes_per_sync)}},
1619 1620 1621 1622
        {"stats_dump_period_sec",
         {offsetof(struct DBOptions, stats_dump_period_sec), OptionType::kUInt,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, stats_dump_period_sec)}},
1623 1624 1625 1626
        {"stats_persist_period_sec",
         {offsetof(struct DBOptions, stats_persist_period_sec),
          OptionType::kUInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, stats_persist_period_sec)}},
1627 1628 1629 1630
        {"persist_stats_to_disk",
         {offsetof(struct DBOptions, persist_stats_to_disk),
          OptionType::kBoolean, OptionVerificationType::kNormal, false,
          offsetof(struct ImmutableDBOptions, persist_stats_to_disk)}},
1631 1632 1633 1634
        {"stats_history_buffer_size",
         {offsetof(struct DBOptions, stats_history_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, stats_history_buffer_size)}},
1635 1636 1637 1638 1639 1640
        {"fail_if_options_file_error",
         {offsetof(struct DBOptions, fail_if_options_file_error),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"enable_pipelined_write",
         {offsetof(struct DBOptions, enable_pipelined_write),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
M
Maysam Yabandeh 已提交
1641 1642 1643
        {"unordered_write",
         {offsetof(struct DBOptions, unordered_write), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
        {"allow_concurrent_memtable_write",
         {offsetof(struct DBOptions, allow_concurrent_memtable_write),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"wal_recovery_mode",
         {offsetof(struct DBOptions, wal_recovery_mode),
          OptionType::kWALRecoveryMode, OptionVerificationType::kNormal, false,
          0}},
        {"enable_write_thread_adaptive_yield",
         {offsetof(struct DBOptions, enable_write_thread_adaptive_yield),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"write_thread_slow_yield_usec",
         {offsetof(struct DBOptions, write_thread_slow_yield_usec),
          OptionType::kUInt64T, OptionVerificationType::kNormal, false, 0}},
1657 1658 1659
        {"max_write_batch_group_size_bytes",
         {offsetof(struct DBOptions, max_write_batch_group_size_bytes),
          OptionType::kUInt64T, OptionVerificationType::kNormal, false, 0}},
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
        {"write_thread_max_yield_usec",
         {offsetof(struct DBOptions, write_thread_max_yield_usec),
          OptionType::kUInt64T, OptionVerificationType::kNormal, false, 0}},
        {"access_hint_on_compaction_start",
         {offsetof(struct DBOptions, access_hint_on_compaction_start),
          OptionType::kAccessHint, OptionVerificationType::kNormal, false, 0}},
        {"info_log_level",
         {offsetof(struct DBOptions, info_log_level), OptionType::kInfoLogLevel,
          OptionVerificationType::kNormal, false, 0}},
        {"dump_malloc_stats",
         {offsetof(struct DBOptions, dump_malloc_stats), OptionType::kBoolean,
          OptionVerificationType::kNormal, false, 0}},
        {"avoid_flush_during_recovery",
         {offsetof(struct DBOptions, avoid_flush_during_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"avoid_flush_during_shutdown",
         {offsetof(struct DBOptions, avoid_flush_during_shutdown),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, avoid_flush_during_shutdown)}},
        {"writable_file_max_buffer_size",
         {offsetof(struct DBOptions, writable_file_max_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableDBOptions, writable_file_max_buffer_size)}},
        {"allow_ingest_behind",
         {offsetof(struct DBOptions, allow_ingest_behind), OptionType::kBoolean,
          OptionVerificationType::kNormal, false,
          offsetof(struct ImmutableDBOptions, allow_ingest_behind)}},
        {"preserve_deletes",
         {offsetof(struct DBOptions, preserve_deletes), OptionType::kBoolean,
          OptionVerificationType::kNormal, false,
          offsetof(struct ImmutableDBOptions, preserve_deletes)}},
        {"concurrent_prepare",  // Deprecated by two_write_queues
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
          0}},
        {"two_write_queues",
         {offsetof(struct DBOptions, two_write_queues), OptionType::kBoolean,
          OptionVerificationType::kNormal, false,
          offsetof(struct ImmutableDBOptions, two_write_queues)}},
        {"manual_wal_flush",
         {offsetof(struct DBOptions, manual_wal_flush), OptionType::kBoolean,
          OptionVerificationType::kNormal, false,
          offsetof(struct ImmutableDBOptions, manual_wal_flush)}},
        {"seq_per_batch",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
Y
Yanqin Jin 已提交
1704 1705 1706 1707
          0}},
        {"atomic_flush",
         {offsetof(struct DBOptions, atomic_flush), OptionType::kBoolean,
          OptionVerificationType::kNormal, false,
1708 1709 1710 1711
          offsetof(struct ImmutableDBOptions, atomic_flush)}},
        {"avoid_unnecessary_blocking_io",
         {offsetof(struct DBOptions, avoid_unnecessary_blocking_io),
          OptionType::kBoolean, OptionVerificationType::kNormal, false,
1712
          offsetof(struct ImmutableDBOptions, avoid_unnecessary_blocking_io)}},
1713 1714 1715
        {"write_dbid_to_manifest",
         {offsetof(struct DBOptions, write_dbid_to_manifest),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
1716 1717 1718
        {"log_readahead_size",
         {offsetof(struct DBOptions, log_readahead_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, false, 0}},
1719 1720 1721
        {"best_efforts_recovery",
         {offsetof(struct DBOptions, best_efforts_recovery),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
1722
};
1723 1724 1725 1726 1727 1728

std::unordered_map<std::string, BlockBasedTableOptions::IndexType>
    OptionsHelper::block_base_table_index_type_string_map = {
        {"kBinarySearch", BlockBasedTableOptions::IndexType::kBinarySearch},
        {"kHashSearch", BlockBasedTableOptions::IndexType::kHashSearch},
        {"kTwoLevelIndexSearch",
1729 1730 1731
         BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch},
        {"kBinarySearchWithFirstKey",
         BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey}};
1732

1733 1734 1735 1736
std::unordered_map<std::string, BlockBasedTableOptions::DataBlockIndexType>
    OptionsHelper::block_base_table_data_block_index_type_string_map = {
        {"kDataBlockBinarySearch",
         BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinarySearch},
1737 1738
        {"kDataBlockBinaryAndHash",
         BlockBasedTableOptions::DataBlockIndexType::kDataBlockBinaryAndHash}};
1739

1740 1741
std::unordered_map<std::string, BlockBasedTableOptions::IndexShorteningMode>
    OptionsHelper::block_base_table_index_shortening_mode_string_map = {
1742 1743 1744 1745 1746 1747 1748
        {"kNoShortening",
         BlockBasedTableOptions::IndexShorteningMode::kNoShortening},
        {"kShortenSeparators",
         BlockBasedTableOptions::IndexShorteningMode::kShortenSeparators},
        {"kShortenSeparatorsAndSuccessor",
         BlockBasedTableOptions::IndexShorteningMode::
             kShortenSeparatorsAndSuccessor}};
1749

1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
std::unordered_map<std::string, EncodingType>
    OptionsHelper::encoding_type_string_map = {{"kPlain", kPlain},
                                               {"kPrefix", kPrefix}};

std::unordered_map<std::string, CompactionStyle>
    OptionsHelper::compaction_style_string_map = {
        {"kCompactionStyleLevel", kCompactionStyleLevel},
        {"kCompactionStyleUniversal", kCompactionStyleUniversal},
        {"kCompactionStyleFIFO", kCompactionStyleFIFO},
        {"kCompactionStyleNone", kCompactionStyleNone}};

std::unordered_map<std::string, CompactionPri>
    OptionsHelper::compaction_pri_string_map = {
        {"kByCompensatedSize", kByCompensatedSize},
        {"kOldestLargestSeqFirst", kOldestLargestSeqFirst},
        {"kOldestSmallestSeqFirst", kOldestSmallestSeqFirst},
        {"kMinOverlappingRatio", kMinOverlappingRatio}};

std::unordered_map<std::string, WALRecoveryMode>
    OptionsHelper::wal_recovery_mode_string_map = {
        {"kTolerateCorruptedTailRecords",
         WALRecoveryMode::kTolerateCorruptedTailRecords},
        {"kAbsoluteConsistency", WALRecoveryMode::kAbsoluteConsistency},
        {"kPointInTimeRecovery", WALRecoveryMode::kPointInTimeRecovery},
        {"kSkipAnyCorruptedRecords",
         WALRecoveryMode::kSkipAnyCorruptedRecords}};

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

std::unordered_map<std::string, InfoLogLevel>
    OptionsHelper::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}};

ColumnFamilyOptions OptionsHelper::dummy_cf_options;
CompactionOptionsFIFO OptionsHelper::dummy_comp_options;
1795
LRUCacheOptions OptionsHelper::dummy_lru_cache_options;
1796
CompactionOptionsUniversal OptionsHelper::dummy_comp_options_universal;
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821

// offset_of is used to get the offset of a class data member
// ex: offset_of(&ColumnFamilyOptions::num_levels)
// This call will return the offset of num_levels in ColumnFamilyOptions class
//
// This is the same as offsetof() but allow us to work with non standard-layout
// classes and structures
// refs:
// http://en.cppreference.com/w/cpp/concept/StandardLayoutType
// https://gist.github.com/graphitemaster/494f21190bb2c63c5516
template <typename T1>
int offset_of(T1 ColumnFamilyOptions::*member) {
  return int(size_t(&(OptionsHelper::dummy_cf_options.*member)) -
             size_t(&OptionsHelper::dummy_cf_options));
}
template <typename T1>
int offset_of(T1 AdvancedColumnFamilyOptions::*member) {
  return int(size_t(&(OptionsHelper::dummy_cf_options.*member)) -
             size_t(&OptionsHelper::dummy_cf_options));
}
template <typename T1>
int offset_of(T1 CompactionOptionsFIFO::*member) {
  return int(size_t(&(OptionsHelper::dummy_comp_options.*member)) -
             size_t(&OptionsHelper::dummy_comp_options));
}
1822 1823 1824 1825 1826
template <typename T1>
int offset_of(T1 LRUCacheOptions::*member) {
  return int(size_t(&(OptionsHelper::dummy_lru_cache_options.*member)) -
             size_t(&OptionsHelper::dummy_lru_cache_options));
}
1827 1828 1829 1830 1831
template <typename T1>
int offset_of(T1 CompactionOptionsUniversal::*member) {
  return int(size_t(&(OptionsHelper::dummy_comp_options_universal.*member)) -
             size_t(&OptionsHelper::dummy_comp_options_universal));
}
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843

std::unordered_map<std::string, OptionTypeInfo>
    OptionsHelper::cf_options_type_info = {
        /* not yet supported
        CompressionOptions compression_opts;
        TablePropertiesCollectorFactories table_properties_collector_factories;
        typedef std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>
            TablePropertiesCollectorFactories;
        UpdateStatus (*inplace_callback)(char* existing_value,
                                         uint34_t* existing_value_size,
                                         Slice delta_value,
                                         std::string* merged_value);
1844
        std::vector<DbPath> cf_paths;
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
         */
        {"report_bg_io_stats",
         {offset_of(&ColumnFamilyOptions::report_bg_io_stats),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, report_bg_io_stats)}},
        {"compaction_measure_io_stats",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, false,
          0}},
        {"disable_auto_compactions",
         {offset_of(&ColumnFamilyOptions::disable_auto_compactions),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, disable_auto_compactions)}},
        {"filter_deletes",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, true,
          0}},
        {"inplace_update_support",
         {offset_of(&ColumnFamilyOptions::inplace_update_support),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"level_compaction_dynamic_level_bytes",
         {offset_of(&ColumnFamilyOptions::level_compaction_dynamic_level_bytes),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"optimize_filters_for_hits",
         {offset_of(&ColumnFamilyOptions::optimize_filters_for_hits),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"paranoid_file_checks",
         {offset_of(&ColumnFamilyOptions::paranoid_file_checks),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, paranoid_file_checks)}},
        {"force_consistency_checks",
         {offset_of(&ColumnFamilyOptions::force_consistency_checks),
          OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},
        {"purge_redundant_kvs_while_flush",
         {offset_of(&ColumnFamilyOptions::purge_redundant_kvs_while_flush),
          OptionType::kBoolean, OptionVerificationType::kDeprecated, false, 0}},
        {"verify_checksums_in_compaction",
         {0, OptionType::kBoolean, OptionVerificationType::kDeprecated, true,
          0}},
        {"soft_pending_compaction_bytes_limit",
         {offset_of(&ColumnFamilyOptions::soft_pending_compaction_bytes_limit),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions,
                   soft_pending_compaction_bytes_limit)}},
        {"hard_pending_compaction_bytes_limit",
         {offset_of(&ColumnFamilyOptions::hard_pending_compaction_bytes_limit),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions,
                   hard_pending_compaction_bytes_limit)}},
        {"hard_rate_limit",
         {0, OptionType::kDouble, OptionVerificationType::kDeprecated, true,
          0}},
        {"soft_rate_limit",
         {0, OptionType::kDouble, OptionVerificationType::kDeprecated, true,
          0}},
        {"max_compaction_bytes",
         {offset_of(&ColumnFamilyOptions::max_compaction_bytes),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, max_compaction_bytes)}},
        {"expanded_compaction_factor",
         {0, OptionType::kInt, OptionVerificationType::kDeprecated, true, 0}},
        {"level0_file_num_compaction_trigger",
         {offset_of(&ColumnFamilyOptions::level0_file_num_compaction_trigger),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions,
                   level0_file_num_compaction_trigger)}},
        {"level0_slowdown_writes_trigger",
         {offset_of(&ColumnFamilyOptions::level0_slowdown_writes_trigger),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, level0_slowdown_writes_trigger)}},
        {"level0_stop_writes_trigger",
         {offset_of(&ColumnFamilyOptions::level0_stop_writes_trigger),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, level0_stop_writes_trigger)}},
        {"max_grandparent_overlap_factor",
         {0, OptionType::kInt, OptionVerificationType::kDeprecated, true, 0}},
        {"max_mem_compaction_level",
         {0, OptionType::kInt, OptionVerificationType::kDeprecated, false, 0}},
        {"max_write_buffer_number",
         {offset_of(&ColumnFamilyOptions::max_write_buffer_number),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, max_write_buffer_number)}},
        {"max_write_buffer_number_to_maintain",
         {offset_of(&ColumnFamilyOptions::max_write_buffer_number_to_maintain),
          OptionType::kInt, OptionVerificationType::kNormal, false, 0}},
1928 1929 1930
        {"max_write_buffer_size_to_maintain",
         {offset_of(&ColumnFamilyOptions::max_write_buffer_size_to_maintain),
          OptionType::kInt64T, OptionVerificationType::kNormal, false, 0}},
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
        {"min_write_buffer_number_to_merge",
         {offset_of(&ColumnFamilyOptions::min_write_buffer_number_to_merge),
          OptionType::kInt, OptionVerificationType::kNormal, false, 0}},
        {"num_levels",
         {offset_of(&ColumnFamilyOptions::num_levels), OptionType::kInt,
          OptionVerificationType::kNormal, false, 0}},
        {"source_compaction_factor",
         {0, OptionType::kInt, OptionVerificationType::kDeprecated, true, 0}},
        {"target_file_size_multiplier",
         {offset_of(&ColumnFamilyOptions::target_file_size_multiplier),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, target_file_size_multiplier)}},
        {"arena_block_size",
         {offset_of(&ColumnFamilyOptions::arena_block_size), OptionType::kSizeT,
          OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, arena_block_size)}},
        {"inplace_update_num_locks",
         {offset_of(&ColumnFamilyOptions::inplace_update_num_locks),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, inplace_update_num_locks)}},
        {"max_successive_merges",
         {offset_of(&ColumnFamilyOptions::max_successive_merges),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, max_successive_merges)}},
        {"memtable_huge_page_size",
         {offset_of(&ColumnFamilyOptions::memtable_huge_page_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, memtable_huge_page_size)}},
        {"memtable_prefix_bloom_huge_page_tlb_size",
         {0, OptionType::kSizeT, OptionVerificationType::kDeprecated, true, 0}},
        {"write_buffer_size",
         {offset_of(&ColumnFamilyOptions::write_buffer_size),
          OptionType::kSizeT, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, write_buffer_size)}},
        {"bloom_locality",
         {offset_of(&ColumnFamilyOptions::bloom_locality), OptionType::kUInt32T,
          OptionVerificationType::kNormal, false, 0}},
        {"memtable_prefix_bloom_bits",
         {0, OptionType::kUInt32T, OptionVerificationType::kDeprecated, true,
          0}},
        {"memtable_prefix_bloom_size_ratio",
         {offset_of(&ColumnFamilyOptions::memtable_prefix_bloom_size_ratio),
          OptionType::kDouble, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, memtable_prefix_bloom_size_ratio)}},
        {"memtable_prefix_bloom_probes",
         {0, OptionType::kUInt32T, OptionVerificationType::kDeprecated, true,
          0}},
1978 1979 1980 1981
        {"memtable_whole_key_filtering",
         {offset_of(&ColumnFamilyOptions::memtable_whole_key_filtering),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, memtable_whole_key_filtering)}},
1982 1983 1984 1985 1986 1987 1988
        {"min_partial_merge_operands",
         {0, OptionType::kUInt32T, OptionVerificationType::kDeprecated, true,
          0}},
        {"max_bytes_for_level_base",
         {offset_of(&ColumnFamilyOptions::max_bytes_for_level_base),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, max_bytes_for_level_base)}},
1989
        {"snap_refresh_nanos",
1990 1991
         {0, OptionType::kUInt64T, OptionVerificationType::kDeprecated, true,
          0}},
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
        {"max_bytes_for_level_multiplier",
         {offset_of(&ColumnFamilyOptions::max_bytes_for_level_multiplier),
          OptionType::kDouble, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, max_bytes_for_level_multiplier)}},
        {"max_bytes_for_level_multiplier_additional",
         {offset_of(
              &ColumnFamilyOptions::max_bytes_for_level_multiplier_additional),
          OptionType::kVectorInt, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions,
                   max_bytes_for_level_multiplier_additional)}},
        {"max_sequential_skip_in_iterations",
         {offset_of(&ColumnFamilyOptions::max_sequential_skip_in_iterations),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions,
                   max_sequential_skip_in_iterations)}},
        {"target_file_size_base",
         {offset_of(&ColumnFamilyOptions::target_file_size_base),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, target_file_size_base)}},
        {"rate_limit_delay_max_milliseconds",
         {0, OptionType::kUInt, OptionVerificationType::kDeprecated, false, 0}},
        {"compression",
         {offset_of(&ColumnFamilyOptions::compression),
          OptionType::kCompressionType, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, compression)}},
        {"compression_per_level",
         {offset_of(&ColumnFamilyOptions::compression_per_level),
          OptionType::kVectorCompressionType, OptionVerificationType::kNormal,
          false, 0}},
        {"bottommost_compression",
         {offset_of(&ColumnFamilyOptions::bottommost_compression),
2023 2024
          OptionType::kCompressionType, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, bottommost_compression)}},
2025
        {kNameComparator,
2026 2027 2028 2029 2030
         {offset_of(&ColumnFamilyOptions::comparator), OptionType::kComparator,
          OptionVerificationType::kByName, false, 0}},
        {"prefix_extractor",
         {offset_of(&ColumnFamilyOptions::prefix_extractor),
          OptionType::kSliceTransform, OptionVerificationType::kByNameAllowNull,
2031
          true, offsetof(struct MutableCFOptions, prefix_extractor)}},
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052
        {"memtable_insert_with_hint_prefix_extractor",
         {offset_of(
              &ColumnFamilyOptions::memtable_insert_with_hint_prefix_extractor),
          OptionType::kSliceTransform, OptionVerificationType::kByNameAllowNull,
          false, 0}},
        {"memtable_factory",
         {offset_of(&ColumnFamilyOptions::memtable_factory),
          OptionType::kMemTableRepFactory, OptionVerificationType::kByName,
          false, 0}},
        {"table_factory",
         {offset_of(&ColumnFamilyOptions::table_factory),
          OptionType::kTableFactory, OptionVerificationType::kByName, false,
          0}},
        {"compaction_filter",
         {offset_of(&ColumnFamilyOptions::compaction_filter),
          OptionType::kCompactionFilter, OptionVerificationType::kByName, false,
          0}},
        {"compaction_filter_factory",
         {offset_of(&ColumnFamilyOptions::compaction_filter_factory),
          OptionType::kCompactionFilterFactory, OptionVerificationType::kByName,
          false, 0}},
2053
        {kNameMergeOperator,
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
         {offset_of(&ColumnFamilyOptions::merge_operator),
          OptionType::kMergeOperator,
          OptionVerificationType::kByNameAllowFromNull, false, 0}},
        {"compaction_style",
         {offset_of(&ColumnFamilyOptions::compaction_style),
          OptionType::kCompactionStyle, OptionVerificationType::kNormal, false,
          0}},
        {"compaction_pri",
         {offset_of(&ColumnFamilyOptions::compaction_pri),
          OptionType::kCompactionPri, OptionVerificationType::kNormal, false,
          0}},
        {"compaction_options_fifo",
         {offset_of(&ColumnFamilyOptions::compaction_options_fifo),
          OptionType::kCompactionOptionsFIFO, OptionVerificationType::kNormal,
2068 2069 2070 2071 2072
          true, offsetof(struct MutableCFOptions, compaction_options_fifo)}},
        {"compaction_options_universal",
         {offset_of(&ColumnFamilyOptions::compaction_options_universal),
          OptionType::kCompactionOptionsUniversal,
          OptionVerificationType::kNormal, true,
S
Sagar Vemuri 已提交
2073 2074 2075
          offsetof(struct MutableCFOptions, compaction_options_universal)}},
        {"ttl",
         {offset_of(&ColumnFamilyOptions::ttl), OptionType::kUInt64T,
2076
          OptionVerificationType::kNormal, true,
2077
          offsetof(struct MutableCFOptions, ttl)}},
S
Sagar Vemuri 已提交
2078 2079 2080 2081
        {"periodic_compaction_seconds",
         {offset_of(&ColumnFamilyOptions::periodic_compaction_seconds),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, periodic_compaction_seconds)}},
2082 2083 2084 2085
        {"sample_for_compression",
         {offset_of(&ColumnFamilyOptions::sample_for_compression),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct MutableCFOptions, sample_for_compression)}}};
2086 2087 2088 2089 2090 2091 2092 2093

std::unordered_map<std::string, OptionTypeInfo>
    OptionsHelper::fifo_compaction_options_type_info = {
        {"max_table_files_size",
         {offset_of(&CompactionOptionsFIFO::max_table_files_size),
          OptionType::kUInt64T, OptionVerificationType::kNormal, true,
          offsetof(struct CompactionOptionsFIFO, max_table_files_size)}},
        {"ttl",
2094 2095 2096
         {0, OptionType::kUInt64T,
          OptionVerificationType::kDeprecated, false,
          0}},
2097 2098 2099 2100 2101
        {"allow_compaction",
         {offset_of(&CompactionOptionsFIFO::allow_compaction),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct CompactionOptionsFIFO, allow_compaction)}}};

2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140
std::unordered_map<std::string, OptionTypeInfo>
    OptionsHelper::universal_compaction_options_type_info = {
        {"size_ratio",
         {offset_of(&CompactionOptionsUniversal::size_ratio), OptionType::kUInt,
          OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal, size_ratio)}},
        {"min_merge_width",
         {offset_of(&CompactionOptionsUniversal::min_merge_width),
          OptionType::kUInt, OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal, min_merge_width)}},
        {"max_merge_width",
         {offset_of(&CompactionOptionsUniversal::max_merge_width),
          OptionType::kUInt, OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal, max_merge_width)}},
        {"max_size_amplification_percent",
         {offset_of(
              &CompactionOptionsUniversal::max_size_amplification_percent),
          OptionType::kUInt, OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal,
                   max_size_amplification_percent)}},
        {"compression_size_percent",
         {offset_of(&CompactionOptionsUniversal::compression_size_percent),
          OptionType::kInt, OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal,
                   compression_size_percent)}},
        {"stop_style",
         {offset_of(&CompactionOptionsUniversal::stop_style),
          OptionType::kCompactionStopStyle, OptionVerificationType::kNormal,
          true, offsetof(class CompactionOptionsUniversal, stop_style)}},
        {"allow_trivial_move",
         {offset_of(&CompactionOptionsUniversal::allow_trivial_move),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(class CompactionOptionsUniversal, allow_trivial_move)}}};

std::unordered_map<std::string, CompactionStopStyle>
    OptionsHelper::compaction_stop_style_string_map = {
        {"kCompactionStopStyleSimilarSize", kCompactionStopStyleSimilarSize},
        {"kCompactionStopStyleTotalSize", kCompactionStopStyleTotalSize}};

2141 2142
std::unordered_map<std::string, OptionTypeInfo>
    OptionsHelper::lru_cache_options_type_info = {
2143 2144 2145
        {"capacity",
         {offset_of(&LRUCacheOptions::capacity), OptionType::kSizeT,
          OptionVerificationType::kNormal, true,
2146
          offsetof(struct LRUCacheOptions, capacity)}},
2147 2148 2149
        {"num_shard_bits",
         {offset_of(&LRUCacheOptions::num_shard_bits), OptionType::kInt,
          OptionVerificationType::kNormal, true,
2150 2151 2152 2153 2154 2155
          offsetof(struct LRUCacheOptions, num_shard_bits)}},
        {"strict_capacity_limit",
         {offset_of(&LRUCacheOptions::strict_capacity_limit),
          OptionType::kBoolean, OptionVerificationType::kNormal, true,
          offsetof(struct LRUCacheOptions, strict_capacity_limit)}},
        {"high_pri_pool_ratio",
2156 2157
         {offset_of(&LRUCacheOptions::high_pri_pool_ratio), OptionType::kDouble,
          OptionVerificationType::kNormal, true,
2158 2159
          offsetof(struct LRUCacheOptions, high_pri_pool_ratio)}}};

2160
#endif  // !ROCKSDB_LITE
2161

2162
}  // namespace ROCKSDB_NAMESPACE