2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "options/options_helper.h"
|
2014-09-17 19:46:32 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2014-10-10 17:00:12 +00:00
|
|
|
#include <cctype>
|
2015-04-24 02:17:57 +00:00
|
|
|
#include <cstdlib>
|
2014-10-01 23:19:16 +00:00
|
|
|
#include <unordered_set>
|
2015-10-02 22:35:32 +00:00
|
|
|
#include <vector>
|
2019-05-30 21:47:29 +00:00
|
|
|
|
2020-04-22 00:35:28 +00:00
|
|
|
#include "options/options_type.h"
|
2014-12-22 21:18:57 +00:00
|
|
|
#include "rocksdb/cache.h"
|
2015-10-02 22:35:32 +00:00
|
|
|
#include "rocksdb/compaction_filter.h"
|
2015-07-15 21:51:51 +00:00
|
|
|
#include "rocksdb/convenience.h"
|
2014-12-22 21:18:57 +00:00
|
|
|
#include "rocksdb/filter_policy.h"
|
2015-10-02 22:35:32 +00:00
|
|
|
#include "rocksdb/memtablerep.h"
|
|
|
|
#include "rocksdb/merge_operator.h"
|
2014-09-17 19:46:32 +00:00
|
|
|
#include "rocksdb/options.h"
|
2015-03-06 22:21:15 +00:00
|
|
|
#include "rocksdb/rate_limiter.h"
|
2015-01-15 23:33:12 +00:00
|
|
|
#include "rocksdb/slice_transform.h"
|
2014-12-22 21:18:57 +00:00
|
|
|
#include "rocksdb/table.h"
|
2019-03-26 21:15:26 +00:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2019-05-30 21:47:29 +00:00
|
|
|
#include "table/block_based/block_based_table_factory.h"
|
2019-05-31 00:39:43 +00:00
|
|
|
#include "table/plain/plain_table_factory.h"
|
2015-08-18 20:30:18 +00:00
|
|
|
#include "util/string_util.h"
|
2014-09-17 19:46:32 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-09-17 19:46:32 +00:00
|
|
|
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
2017-05-04 03:46:17 +00:00
|
|
|
options.max_open_files = mutable_db_options.max_open_files;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.max_file_opening_threads =
|
|
|
|
immutable_db_options.max_file_opening_threads;
|
2016-11-15 06:45:16 +00:00
|
|
|
options.max_total_wal_size = mutable_db_options.max_total_wal_size;
|
2016-09-23 23:34:04 +00:00
|
|
|
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 =
|
2016-12-05 22:09:35 +00:00
|
|
|
mutable_db_options.delete_obsolete_files_period_micros;
|
2017-05-24 18:25:38 +00:00
|
|
|
options.max_background_jobs = mutable_db_options.max_background_jobs;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.base_background_compactions =
|
2016-10-14 19:25:39 +00:00
|
|
|
mutable_db_options.base_background_compactions;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.max_background_compactions =
|
2016-10-14 19:25:39 +00:00
|
|
|
mutable_db_options.max_background_compactions;
|
2017-09-28 00:37:08 +00:00
|
|
|
options.bytes_per_sync = mutable_db_options.bytes_per_sync;
|
|
|
|
options.wal_bytes_per_sync = mutable_db_options.wal_bytes_per_sync;
|
Optionally wait on bytes_per_sync to smooth I/O (#5183)
Summary:
The existing implementation does not guarantee bytes reach disk every `bytes_per_sync` when writing SST files, or every `wal_bytes_per_sync` when writing WALs. This can cause confusing behavior for users who enable this feature to avoid large syncs during flush and compaction, but then end up hitting them anyways.
My understanding of the existing behavior is we used `sync_file_range` with `SYNC_FILE_RANGE_WRITE` to submit ranges for async writeback, such that we could continue processing the next range of bytes while that I/O is happening. I believe we can preserve that benefit while also limiting how far the processing can get ahead of the I/O, which prevents huge syncs from happening when the file finishes.
Consider this `sync_file_range` usage: `sync_file_range(fd_, 0, static_cast<off_t>(offset + nbytes), SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE)`. Expanding the range to start at 0 and adding the `SYNC_FILE_RANGE_WAIT_BEFORE` flag causes any pending writeback (like from a previous call to `sync_file_range`) to finish before it proceeds to submit the latest `nbytes` for writeback. The latest `nbytes` are still written back asynchronously, unless processing exceeds I/O speed, in which case the following `sync_file_range` will need to wait on it.
There is a second change in this PR to use `fdatasync` when `sync_file_range` is unavailable (determined statically) or has some known problem with the underlying filesystem (determined dynamically).
The above two changes only apply when the user enables a new option, `strict_bytes_per_sync`.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5183
Differential Revision: D14953553
Pulled By: siying
fbshipit-source-id: 445c3862e019fb7b470f9c7f314fc231b62706e9
2019-04-22 18:48:45 +00:00
|
|
|
options.strict_bytes_per_sync = mutable_db_options.strict_bytes_per_sync;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.max_subcompactions = immutable_db_options.max_subcompactions;
|
2020-04-20 23:17:25 +00:00
|
|
|
options.max_background_flushes = mutable_db_options.max_background_flushes;
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
2016-10-28 17:36:05 +00:00
|
|
|
options.use_direct_reads = immutable_db_options.use_direct_reads;
|
2017-04-13 20:07:33 +00:00
|
|
|
options.use_direct_io_for_flush_and_compaction =
|
|
|
|
immutable_db_options.use_direct_io_for_flush_and_compaction;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.allow_fallocate = immutable_db_options.allow_fallocate;
|
|
|
|
options.is_fd_close_on_exec = immutable_db_options.is_fd_close_on_exec;
|
2017-03-21 05:50:56 +00:00
|
|
|
options.stats_dump_period_sec = mutable_db_options.stats_dump_period_sec;
|
2019-02-20 23:46:59 +00:00
|
|
|
options.stats_persist_period_sec =
|
|
|
|
mutable_db_options.stats_persist_period_sec;
|
2019-06-17 22:17:43 +00:00
|
|
|
options.persist_stats_to_disk = immutable_db_options.persist_stats_to_disk;
|
2019-02-20 23:46:59 +00:00
|
|
|
options.stats_history_buffer_size =
|
|
|
|
mutable_db_options.stats_history_buffer_size;
|
2016-09-23 23:34:04 +00:00
|
|
|
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 =
|
2017-11-17 01:46:43 +00:00
|
|
|
mutable_db_options.compaction_readahead_size;
|
2016-09-23 23:34:04 +00:00
|
|
|
options.random_access_max_buffer_size =
|
|
|
|
immutable_db_options.random_access_max_buffer_size;
|
|
|
|
options.writable_file_max_buffer_size =
|
2017-10-31 20:49:25 +00:00
|
|
|
mutable_db_options.writable_file_max_buffer_size;
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
2016-11-12 23:43:33 +00:00
|
|
|
options.delayed_write_rate = mutable_db_options.delayed_write_rate;
|
2018-03-13 18:50:16 +00:00
|
|
|
options.enable_pipelined_write = immutable_db_options.enable_pipelined_write;
|
2019-05-14 00:43:47 +00:00
|
|
|
options.unordered_write = immutable_db_options.unordered_write;
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
2019-09-12 01:26:22 +00:00
|
|
|
options.max_write_batch_group_size_bytes =
|
|
|
|
immutable_db_options.max_write_batch_group_size_bytes;
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
Add an option to prevent DB::Open() from querying sizes of all sst files (#6353)
Summary:
When paranoid_checks is on, DBImpl::CheckConsistency() iterates over all sst files and calls Env::GetFileSize() for each of them. As far as I could understand, this is pretty arbitrary and doesn't affect correctness - if filesystem doesn't corrupt fsynced files, the file sizes will always match; if it does, it may as well corrupt contents as well as sizes, and rocksdb doesn't check contents on open.
If there are thousands of sst files, getting all their sizes takes a while. If, on top of that, Env is overridden to use some remote storage instead of local filesystem, it can be *really* slow and overload the remote storage service. This PR adds an option to not do GetFileSize(); instead it does GetChildren() for parent directory to check that all the expected sst files are at least present, but doesn't check their sizes.
We can't just disable paranoid_checks instead because paranoid_checks do a few other important things: make the DB read-only on write errors, print error messages on read errors, etc.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6353
Test Plan: ran the added sanity check unit test. Will try it out in a LogDevice test cluster where the GetFileSize() calls are causing a lot of trouble.
Differential Revision: D19656425
Pulled By: al13n321
fbshipit-source-id: c2c421b367633033760d1f56747bad206d1fbf82
2020-02-04 09:24:29 +00:00
|
|
|
options.skip_checking_sst_file_sizes_on_db_open =
|
|
|
|
immutable_db_options.skip_checking_sst_file_sizes_on_db_open;
|
2016-09-23 23:34:04 +00:00
|
|
|
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;
|
2016-11-02 22:22:13 +00:00
|
|
|
options.avoid_flush_during_shutdown =
|
|
|
|
mutable_db_options.avoid_flush_during_shutdown;
|
2017-05-17 18:32:26 +00:00
|
|
|
options.allow_ingest_behind =
|
|
|
|
immutable_db_options.allow_ingest_behind;
|
Added support for differential snapshots
Summary:
The motivation for this PR is to add to RocksDB support for differential (incremental) snapshots, as snapshot of the DB changes between two points in time (one can think of it as diff between to sequence numbers, or the diff D which can be thought of as an SST file or just set of KVs that can be applied to sequence number S1 to get the database to the state at sequence number S2).
This feature would be useful for various distributed storages layers built on top of RocksDB, as it should help reduce resources (time and network bandwidth) needed to recover and rebuilt DB instances as replicas in the context of distributed storages.
From the API standpoint that would like client app requesting iterator between (start seqnum) and current DB state, and reading the "diff".
This is a very draft PR for initial review in the discussion on the approach, i'm going to rework some parts and keep updating the PR.
For now, what's done here according to initial discussions:
Preserving deletes:
- We want to be able to optionally preserve recent deletes for some defined period of time, so that if a delete came in recently and might need to be included in the next incremental snapshot it would't get dropped by a compaction. This is done by adding new param to Options (preserve deletes flag) and new variable to DB Impl where we keep track of the sequence number after which we don't want to drop tombstones, even if they are otherwise eligible for deletion.
- I also added a new API call for clients to be able to advance this cutoff seqnum after which we drop deletes; i assume it's more flexible to let clients control this, since otherwise we'd need to keep some kind of timestamp < -- > seqnum mapping inside the DB, which sounds messy and painful to support. Clients could make use of it by periodically calling GetLatestSequenceNumber(), noting the timestamp, doing some calculation and figuring out by how much we need to advance the cutoff seqnum.
- Compaction codepath in compaction_iterator.cc has been modified to avoid dropping tombstones with seqnum > cutoff seqnum.
Iterator changes:
- couple params added to ReadOptions, to optionally allow client to request internal keys instead of user keys (so that client can get the latest value of a key, be it delete marker or a put), as well as min timestamp and min seqnum.
TableCache changes:
- I modified table_cache code to be able to quickly exclude SST files from iterators heep if creation_time on the file is less then iter_start_ts as passed in ReadOptions. That would help a lot in some DB settings (like reading very recent data only or using FIFO compactions), but not so much for universal compaction with more or less long iterator time span.
What's left:
- Still looking at how to best plug that inside DBIter codepath. So far it seems that FindNextUserKeyInternal only parses values as UserKeys, and iter->key() call generally returns user key. Can we add new API to DBIter as internal_key(), and modify this internal method to optionally set saved_key_ to point to the full internal key? I don't need to store actual seqnum there, but I do need to store type.
Closes https://github.com/facebook/rocksdb/pull/2999
Differential Revision: D6175602
Pulled By: mikhail-antonov
fbshipit-source-id: c779a6696ee2d574d86c69cec866a3ae095aa900
2017-11-02 01:43:29 +00:00
|
|
|
options.preserve_deletes =
|
|
|
|
immutable_db_options.preserve_deletes;
|
2018-05-14 17:53:32 +00:00
|
|
|
options.two_write_queues = immutable_db_options.two_write_queues;
|
|
|
|
options.manual_wal_flush = immutable_db_options.manual_wal_flush;
|
2018-11-12 20:22:10 +00:00
|
|
|
options.atomic_flush = immutable_db_options.atomic_flush;
|
2019-04-02 00:07:38 +00:00
|
|
|
options.avoid_unnecessary_blocking_io =
|
|
|
|
immutable_db_options.avoid_unnecessary_blocking_io;
|
2019-07-19 18:54:38 +00:00
|
|
|
options.log_readahead_size = immutable_db_options.log_readahead_size;
|
2020-03-29 22:57:02 +00:00
|
|
|
options.file_checksum_gen_factory =
|
|
|
|
immutable_db_options.file_checksum_gen_factory;
|
2020-03-21 02:17:54 +00:00
|
|
|
options.best_efforts_recovery = immutable_db_options.best_efforts_recovery;
|
2016-09-23 23:34:04 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2016-09-15 05:10:28 +00:00
|
|
|
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;
|
2019-02-19 20:12:25 +00:00
|
|
|
cf_opts.memtable_whole_key_filtering =
|
|
|
|
mutable_cf_options.memtable_whole_key_filtering;
|
2016-09-15 05:10:28 +00:00
|
|
|
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;
|
2018-05-21 21:33:55 +00:00
|
|
|
cf_opts.prefix_extractor = mutable_cf_options.prefix_extractor;
|
2016-09-15 05:10:28 +00:00
|
|
|
|
|
|
|
// Compaction related options
|
|
|
|
cf_opts.disable_auto_compactions =
|
|
|
|
mutable_cf_options.disable_auto_compactions;
|
2018-05-08 19:06:01 +00:00
|
|
|
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;
|
2016-09-15 05:10:28 +00:00
|
|
|
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;
|
2018-07-16 21:24:33 +00:00
|
|
|
cf_opts.ttl = mutable_cf_options.ttl;
|
Periodic Compactions (#5166)
Summary:
Introducing Periodic Compactions.
This feature allows all the files in a CF to be periodically compacted. It could help in catching any corruptions that could creep into the DB proactively as every file is constantly getting re-compacted. And also, of course, it helps to cleanup data older than certain threshold.
- Introduced a new option `periodic_compaction_time` to control how long a file can live without being compacted in a CF.
- This works across all levels.
- The files are put in the same level after going through the compaction. (Related files in the same level are picked up as `ExpandInputstoCleanCut` is used).
- Compaction filters, if any, are invoked as usual.
- A new table property, `file_creation_time`, is introduced to implement this feature. This property is set to the time at which the SST file was created (and that time is given by the underlying Env/OS).
This feature can be enabled on its own, or in conjunction with `ttl`. It is possible to set a different time threshold for the bottom level when used in conjunction with ttl. Since `ttl` works only on 0 to last but one levels, you could set `ttl` to, say, 1 day, and `periodic_compaction_time` to, say, 7 days. Since `ttl < periodic_compaction_time` all files in last but one levels keep getting picked up based on ttl, and almost never based on periodic_compaction_time. The files in the bottom level get picked up for compaction based on `periodic_compaction_time`.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5166
Differential Revision: D14884441
Pulled By: sagar0
fbshipit-source-id: 408426cbacb409c06386a98632dcf90bfa1bda47
2019-04-11 02:24:25 +00:00
|
|
|
cf_opts.periodic_compaction_seconds =
|
|
|
|
mutable_cf_options.periodic_compaction_seconds;
|
2016-09-15 05:10:28 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:19:20 +00:00
|
|
|
cf_opts.compaction_options_fifo = mutable_cf_options.compaction_options_fifo;
|
2017-12-11 21:12:12 +00:00
|
|
|
cf_opts.compaction_options_universal =
|
|
|
|
mutable_cf_options.compaction_options_universal;
|
2017-10-19 22:19:20 +00:00
|
|
|
|
2016-09-15 05:10:28 +00:00
|
|
|
// 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;
|
2020-04-08 21:37:01 +00:00
|
|
|
cf_opts.compression_opts = mutable_cf_options.compression_opts;
|
|
|
|
cf_opts.bottommost_compression = mutable_cf_options.bottommost_compression;
|
|
|
|
cf_opts.bottommost_compression_opts =
|
|
|
|
mutable_cf_options.bottommost_compression_opts;
|
2019-03-18 19:07:35 +00:00
|
|
|
cf_opts.sample_for_compression = mutable_cf_options.sample_for_compression;
|
2016-09-15 05:10:28 +00:00
|
|
|
|
|
|
|
cf_opts.table_factory = options.table_factory;
|
|
|
|
// TODO(yhchiang): find some way to handle the following derived options
|
|
|
|
// * max_file_size
|
|
|
|
|
|
|
|
return cf_opts;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:02:13 +00:00
|
|
|
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},
|
2018-11-01 22:39:40 +00:00
|
|
|
{"kxxHash", kxxHash},
|
|
|
|
{"kxxHash64", kxxHash64}};
|
2017-11-18 01:02:13 +00:00
|
|
|
|
2018-01-23 22:36:54 +00:00
|
|
|
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}};
|
2020-04-27 23:51:42 +00:00
|
|
|
|
|
|
|
std::vector<CompressionType> GetSupportedCompressions() {
|
|
|
|
std::vector<CompressionType> supported_compressions;
|
|
|
|
for (const auto& comp_to_name : OptionsHelper::compression_type_string_map) {
|
|
|
|
CompressionType t = comp_to_name.second;
|
|
|
|
if (t != kDisableCompressionOption && CompressionTypeSupported(t)) {
|
|
|
|
supported_compressions.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return supported_compressions;
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:39:30 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2015-10-02 22:35:32 +00:00
|
|
|
bool ParseSliceTransformHelper(
|
|
|
|
const std::string& kFixedPrefixName, const std::string& kCappedPrefixName,
|
|
|
|
const std::string& value,
|
|
|
|
std::shared_ptr<const SliceTransform>* slice_transform) {
|
2018-05-21 21:33:55 +00:00
|
|
|
const char* no_op_name = "rocksdb.Noop";
|
|
|
|
size_t no_op_length = strlen(no_op_name);
|
2015-10-02 22:35:32 +00:00
|
|
|
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));
|
2018-05-21 21:33:55 +00:00
|
|
|
} 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);
|
2015-10-11 19:17:42 +00:00
|
|
|
} else if (value == kNullptrString) {
|
2015-10-02 22:35:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-08-26 23:13:56 +00:00
|
|
|
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;
|
2019-03-12 20:46:12 +00:00
|
|
|
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;
|
2015-08-26 23:13:56 +00:00
|
|
|
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:
|
2017-04-22 03:41:37 +00:00
|
|
|
PutUnaligned(reinterpret_cast<uint64_t*>(opt_address), ParseUint64(value));
|
2015-08-26 23:13:56 +00:00
|
|
|
break;
|
|
|
|
case OptionType::kSizeT:
|
2017-04-22 03:41:37 +00:00
|
|
|
PutUnaligned(reinterpret_cast<size_t*>(opt_address), ParseSizeT(value));
|
2015-08-26 23:13:56 +00:00
|
|
|
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:
|
2015-11-18 00:41:54 +00:00
|
|
|
return ParseEnum<CompactionStyle>(
|
|
|
|
compaction_style_string_map, value,
|
|
|
|
reinterpret_cast<CompactionStyle*>(opt_address));
|
2017-03-02 18:08:49 +00:00
|
|
|
case OptionType::kCompactionPri:
|
|
|
|
return ParseEnum<CompactionPri>(
|
|
|
|
compaction_pri_string_map, value,
|
|
|
|
reinterpret_cast<CompactionPri*>(opt_address));
|
2015-10-02 22:35:32 +00:00
|
|
|
case OptionType::kCompressionType:
|
2015-11-18 00:41:54 +00:00
|
|
|
return ParseEnum<CompressionType>(
|
|
|
|
compression_type_string_map, value,
|
|
|
|
reinterpret_cast<CompressionType*>(opt_address));
|
2015-10-02 22:35:32 +00:00
|
|
|
case OptionType::kSliceTransform:
|
|
|
|
return ParseSliceTransform(
|
|
|
|
value, reinterpret_cast<std::shared_ptr<const SliceTransform>*>(
|
|
|
|
opt_address));
|
2015-10-11 19:17:42 +00:00
|
|
|
case OptionType::kChecksumType:
|
2015-11-18 00:41:54 +00:00
|
|
|
return ParseEnum<ChecksumType>(
|
|
|
|
checksum_type_string_map, value,
|
|
|
|
reinterpret_cast<ChecksumType*>(opt_address));
|
2015-10-28 17:46:01 +00:00
|
|
|
case OptionType::kEncodingType:
|
2015-11-18 00:41:54 +00:00
|
|
|
return ParseEnum<EncodingType>(
|
|
|
|
encoding_type_string_map, value,
|
|
|
|
reinterpret_cast<EncodingType*>(opt_address));
|
2017-12-11 21:12:12 +00:00
|
|
|
case OptionType::kCompactionStopStyle:
|
|
|
|
return ParseEnum<CompactionStopStyle>(
|
|
|
|
compaction_stop_style_string_map, value,
|
|
|
|
reinterpret_cast<CompactionStopStyle*>(opt_address));
|
2015-08-26 23:13:56 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SerializeSingleOptionHelper(const char* opt_address,
|
|
|
|
const OptionType opt_type,
|
|
|
|
std::string* value) {
|
2016-10-14 20:09:18 +00:00
|
|
|
|
2015-08-26 23:13:56 +00:00
|
|
|
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;
|
2019-03-12 20:46:12 +00:00
|
|
|
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;
|
2015-08-26 23:13:56 +00:00
|
|
|
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:
|
2017-04-22 03:41:37 +00:00
|
|
|
{
|
|
|
|
uint64_t v;
|
|
|
|
GetUnaligned(reinterpret_cast<const uint64_t*>(opt_address), &v);
|
|
|
|
*value = ToString(v);
|
|
|
|
}
|
2015-08-26 23:13:56 +00:00
|
|
|
break;
|
|
|
|
case OptionType::kSizeT:
|
2017-04-22 03:41:37 +00:00
|
|
|
{
|
|
|
|
size_t v;
|
|
|
|
GetUnaligned(reinterpret_cast<const size_t*>(opt_address), &v);
|
|
|
|
*value = ToString(v);
|
|
|
|
}
|
2015-08-26 23:13:56 +00:00
|
|
|
break;
|
|
|
|
case OptionType::kDouble:
|
|
|
|
*value = ToString(*(reinterpret_cast<const double*>(opt_address)));
|
|
|
|
break;
|
|
|
|
case OptionType::kString:
|
RocksDB Options file format and its serialization / deserialization.
Summary:
This patch defines the format of RocksDB options file, which
follows the INI file format, and implements functions for its
serialization and deserialization. An example RocksDB options
file can be found in examples/rocksdb_option_file_example.ini.
A typical RocksDB options file has three sections, which are
Version, DBOptions, and more than one CFOptions. The RocksDB
options file in general follows the basic INI file format
with the following extensions / modifications:
* Escaped characters
We escaped the following characters:
- \n -- line feed - new line
- \r -- carriage return
- \\ -- backslash \
- \: -- colon symbol :
- \# -- hash tag #
* Comments
We support # style comments. Comments can appear at the ending
part of a line.
* Statements
A statement is of the form option_name = value.
Each statement contains a '=', where extra white-spaces
are supported. However, we don't support multi-lined statement.
Furthermore, each line can only contain at most one statement.
* Section
Sections are of the form [SecitonTitle "SectionArgument"],
where section argument is optional.
* List
We use colon-separated string to represent a list.
For instance, n1:n2:n3:n4 is a list containing four values.
Below is an example of a RocksDB options file:
[Version]
rocksdb_version=4.0.0
options_file_version=1.0
[DBOptions]
max_open_files=12345
max_background_flushes=301
[CFOptions "default"]
[CFOptions "the second column family"]
[CFOptions "the third column family"]
Test Plan: Added many tests in options_test.cc
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D46059
2015-09-29 21:42:40 +00:00
|
|
|
*value = EscapeOptionString(
|
|
|
|
*(reinterpret_cast<const std::string*>(opt_address)));
|
2015-08-26 23:13:56 +00:00
|
|
|
break;
|
|
|
|
case OptionType::kCompactionStyle:
|
2015-11-18 00:41:54 +00:00
|
|
|
return SerializeEnum<CompactionStyle>(
|
|
|
|
compaction_style_string_map,
|
2015-10-30 22:58:46 +00:00
|
|
|
*(reinterpret_cast<const CompactionStyle*>(opt_address)), value);
|
2017-03-02 18:08:49 +00:00
|
|
|
case OptionType::kCompactionPri:
|
|
|
|
return SerializeEnum<CompactionPri>(
|
|
|
|
compaction_pri_string_map,
|
|
|
|
*(reinterpret_cast<const CompactionPri*>(opt_address)), value);
|
2015-10-02 22:35:32 +00:00
|
|
|
case OptionType::kCompressionType:
|
2015-11-18 00:41:54 +00:00
|
|
|
return SerializeEnum<CompressionType>(
|
|
|
|
compression_type_string_map,
|
2015-10-02 22:35:32 +00:00
|
|
|
*(reinterpret_cast<const CompressionType*>(opt_address)), value);
|
|
|
|
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()
|
2015-10-11 19:17:42 +00:00
|
|
|
: kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
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()
|
2015-10-11 19:17:42 +00:00
|
|
|
: kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OptionType::kComparator: {
|
|
|
|
// it's a const pointer of const Comparator*
|
|
|
|
const auto* ptr = reinterpret_cast<const Comparator* const*>(opt_address);
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
// Since the user-specified comparator will be wrapped by
|
|
|
|
// InternalKeyComparator, we should persist the user-specified one
|
|
|
|
// instead of InternalKeyComparator.
|
2017-07-28 23:23:50 +00:00
|
|
|
if (*ptr == nullptr) {
|
|
|
|
*value = kNullptrString;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
} else {
|
2017-07-28 23:23:50 +00:00
|
|
|
const Comparator* root_comp = (*ptr)->GetRootComparator();
|
|
|
|
if (root_comp == nullptr) {
|
|
|
|
root_comp = (*ptr);
|
|
|
|
}
|
|
|
|
*value = root_comp->Name();
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
}
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OptionType::kCompactionFilter: {
|
|
|
|
// it's a const pointer of const CompactionFilter*
|
|
|
|
const auto* ptr =
|
|
|
|
reinterpret_cast<const CompactionFilter* const*>(opt_address);
|
2015-10-11 19:17:42 +00:00
|
|
|
*value = *ptr ? (*ptr)->Name() : kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OptionType::kCompactionFilterFactory: {
|
|
|
|
const auto* ptr =
|
|
|
|
reinterpret_cast<const std::shared_ptr<CompactionFilterFactory>*>(
|
|
|
|
opt_address);
|
2015-10-11 19:17:42 +00:00
|
|
|
*value = ptr->get() ? ptr->get()->Name() : kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OptionType::kMemTableRepFactory: {
|
|
|
|
const auto* ptr =
|
|
|
|
reinterpret_cast<const std::shared_ptr<MemTableRepFactory>*>(
|
|
|
|
opt_address);
|
2015-10-11 19:17:42 +00:00
|
|
|
*value = ptr->get() ? ptr->get()->Name() : kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OptionType::kMergeOperator: {
|
|
|
|
const auto* ptr =
|
|
|
|
reinterpret_cast<const std::shared_ptr<MergeOperator>*>(opt_address);
|
2015-10-11 19:17:42 +00:00
|
|
|
*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:
|
2015-11-18 00:41:54 +00:00
|
|
|
return SerializeEnum<ChecksumType>(
|
|
|
|
checksum_type_string_map,
|
2015-10-11 19:17:42 +00:00
|
|
|
*reinterpret_cast<const ChecksumType*>(opt_address), value);
|
|
|
|
case OptionType::kFlushBlockPolicyFactory: {
|
|
|
|
const auto* ptr =
|
|
|
|
reinterpret_cast<const std::shared_ptr<FlushBlockPolicyFactory>*>(
|
|
|
|
opt_address);
|
|
|
|
*value = ptr->get() ? ptr->get()->Name() : kNullptrString;
|
2015-10-02 22:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-10-28 17:46:01 +00:00
|
|
|
case OptionType::kEncodingType:
|
2015-11-18 00:41:54 +00:00
|
|
|
return SerializeEnum<EncodingType>(
|
|
|
|
encoding_type_string_map,
|
2015-10-28 17:46:01 +00:00
|
|
|
*reinterpret_cast<const EncodingType*>(opt_address), value);
|
2017-12-11 21:12:12 +00:00
|
|
|
case OptionType::kCompactionStopStyle:
|
|
|
|
return SerializeEnum<CompactionStopStyle>(
|
|
|
|
compaction_stop_style_string_map,
|
|
|
|
*reinterpret_cast<const CompactionStopStyle*>(opt_address), value);
|
2015-08-26 23:13:56 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-05 00:23:05 +00:00
|
|
|
Status GetMutableOptionsFromStrings(
|
2014-09-17 19:49:13 +00:00
|
|
|
const MutableCFOptions& base_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& options_map,
|
2018-04-11 01:48:49 +00:00
|
|
|
Logger* info_log, MutableCFOptions* new_options) {
|
2014-09-17 19:49:13 +00:00
|
|
|
assert(new_options);
|
|
|
|
*new_options = base_options;
|
2020-04-29 01:02:11 +00:00
|
|
|
ConfigOptions config_options;
|
2014-12-22 21:18:57 +00:00
|
|
|
for (const auto& o : options_map) {
|
2020-05-21 17:56:40 +00:00
|
|
|
std::string elem;
|
|
|
|
const auto opt_info =
|
|
|
|
OptionTypeInfo::Find(o.first, cf_options_type_info, &elem);
|
|
|
|
if (opt_info == nullptr) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return Status::InvalidArgument("Unrecognized option: " + o.first);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (!opt_info->IsMutable()) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return Status::InvalidArgument("Option not changeable: " + o.first);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (opt_info->IsDeprecated()) {
|
2020-04-29 01:02:11 +00:00
|
|
|
// 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",
|
|
|
|
o.first.c_str());
|
2020-05-21 17:56:40 +00:00
|
|
|
} else {
|
|
|
|
Status s = opt_info->Parse(
|
|
|
|
config_options, elem, o.second,
|
|
|
|
reinterpret_cast<char*>(new_options) + opt_info->mutable_offset_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2014-09-17 19:49:13 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 00:23:05 +00:00
|
|
|
return Status::OK();
|
2014-09-17 19:49:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 19:25:39 +00:00
|
|
|
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;
|
2020-04-29 01:02:11 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
|
2016-10-14 19:25:39 +00:00
|
|
|
for (const auto& o : options_map) {
|
|
|
|
try {
|
2020-05-21 17:56:40 +00:00
|
|
|
std::string elem;
|
|
|
|
const auto opt_info =
|
|
|
|
OptionTypeInfo::Find(o.first, db_options_type_info, &elem);
|
|
|
|
if (opt_info == nullptr) {
|
2016-10-14 19:25:39 +00:00
|
|
|
return Status::InvalidArgument("Unrecognized option: " + o.first);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (!opt_info->IsMutable()) {
|
2016-10-14 19:25:39 +00:00
|
|
|
return Status::InvalidArgument("Option not changeable: " + o.first);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else {
|
|
|
|
Status s = opt_info->Parse(
|
|
|
|
config_options, elem, o.second,
|
|
|
|
reinterpret_cast<char*>(new_options) + opt_info->mutable_offset_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2016-10-14 19:25:39 +00:00
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
return Status::InvalidArgument("Error parsing " + o.first + ":" +
|
|
|
|
std::string(e.what()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:18:57 +00:00
|
|
|
Status StringToMap(const std::string& opts_str,
|
|
|
|
std::unordered_map<std::string, std::string>* opts_map) {
|
2014-10-10 17:00:12 +00:00
|
|
|
assert(opts_map);
|
|
|
|
// Example:
|
2014-12-22 21:18:57 +00:00
|
|
|
// opts_str = "write_buffer_size=1024;max_write_buffer_number=2;"
|
|
|
|
// "nested_opt={opt1=1;opt2=2};max_bytes_for_level_base=100"
|
2014-10-10 17:00:12 +00:00
|
|
|
size_t pos = 0;
|
|
|
|
std::string opts = trim(opts_str);
|
2020-05-21 17:56:40 +00:00
|
|
|
// If the input string starts and ends with "{...}", strip off the brackets
|
|
|
|
while (opts.size() > 2 && opts[0] == '{' && opts[opts.size() - 1] == '}') {
|
|
|
|
opts = trim(opts.substr(1, opts.size() - 2));
|
|
|
|
}
|
|
|
|
|
2014-10-10 17:00:12 +00:00
|
|
|
while (pos < opts.size()) {
|
|
|
|
size_t eq_pos = opts.find('=', pos);
|
|
|
|
if (eq_pos == std::string::npos) {
|
2014-12-22 21:18:57 +00:00
|
|
|
return Status::InvalidArgument("Mismatched key value pair, '=' expected");
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
std::string key = trim(opts.substr(pos, eq_pos - pos));
|
2014-12-22 21:18:57 +00:00
|
|
|
if (key.empty()) {
|
|
|
|
return Status::InvalidArgument("Empty key found");
|
|
|
|
}
|
2014-10-10 17:00:12 +00:00
|
|
|
|
2020-06-03 19:19:54 +00:00
|
|
|
std::string value;
|
|
|
|
Status s = OptionTypeInfo::NextToken(opts, ';', eq_pos + 1, &pos, &value);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
2014-10-10 17:00:12 +00:00
|
|
|
} else {
|
2020-06-03 19:19:54 +00:00
|
|
|
(*opts_map)[key] = value;
|
|
|
|
if (pos == std::string::npos) {
|
2014-12-22 21:18:57 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2020-06-03 19:19:54 +00:00
|
|
|
pos++;
|
2014-12-22 21:18:57 +00:00
|
|
|
}
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 21:18:57 +00:00
|
|
|
return Status::OK();
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 22:19:20 +00:00
|
|
|
Status GetStringFromStruct(
|
2020-04-29 01:02:11 +00:00
|
|
|
const ConfigOptions& config_options, const void* const opt_ptr,
|
2019-05-15 21:19:04 +00:00
|
|
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info,
|
2020-04-22 00:35:28 +00:00
|
|
|
std::string* opt_string) {
|
2015-08-18 20:30:18 +00:00
|
|
|
assert(opt_string);
|
|
|
|
opt_string->clear();
|
2020-06-24 23:20:55 +00:00
|
|
|
for (const auto& iter : type_info) {
|
2020-04-03 17:48:46 +00:00
|
|
|
const auto& opt_info = iter.second;
|
2020-04-29 01:02:11 +00:00
|
|
|
// If the option is no longer used in rocksdb and marked as deprecated,
|
|
|
|
// we skip it in the serialization.
|
|
|
|
if (opt_info.ShouldSerialize()) {
|
|
|
|
const char* opt_addr =
|
2020-05-21 17:56:40 +00:00
|
|
|
reinterpret_cast<const char*>(opt_ptr) + opt_info.offset_;
|
2020-04-29 01:02:11 +00:00
|
|
|
std::string value;
|
2020-05-21 17:56:40 +00:00
|
|
|
Status s =
|
|
|
|
opt_info.Serialize(config_options, iter.first, opt_addr, &value);
|
2020-04-29 01:02:11 +00:00
|
|
|
if (s.ok()) {
|
|
|
|
opt_string->append(iter.first + "=" + value + config_options.delimiter);
|
|
|
|
} else {
|
|
|
|
return s;
|
|
|
|
}
|
2015-08-18 20:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:19:20 +00:00
|
|
|
Status GetStringFromDBOptions(std::string* opt_string,
|
|
|
|
const DBOptions& db_options,
|
|
|
|
const std::string& delimiter) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.delimiter = delimiter;
|
|
|
|
return GetStringFromDBOptions(config_options, db_options, opt_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetStringFromDBOptions(const ConfigOptions& cfg_options,
|
|
|
|
const DBOptions& db_options,
|
|
|
|
std::string* opt_string) {
|
|
|
|
return GetStringFromStruct(cfg_options, &db_options, db_options_type_info,
|
|
|
|
opt_string);
|
2015-08-26 23:13:56 +00:00
|
|
|
}
|
|
|
|
|
RocksDB Options file format and its serialization / deserialization.
Summary:
This patch defines the format of RocksDB options file, which
follows the INI file format, and implements functions for its
serialization and deserialization. An example RocksDB options
file can be found in examples/rocksdb_option_file_example.ini.
A typical RocksDB options file has three sections, which are
Version, DBOptions, and more than one CFOptions. The RocksDB
options file in general follows the basic INI file format
with the following extensions / modifications:
* Escaped characters
We escaped the following characters:
- \n -- line feed - new line
- \r -- carriage return
- \\ -- backslash \
- \: -- colon symbol :
- \# -- hash tag #
* Comments
We support # style comments. Comments can appear at the ending
part of a line.
* Statements
A statement is of the form option_name = value.
Each statement contains a '=', where extra white-spaces
are supported. However, we don't support multi-lined statement.
Furthermore, each line can only contain at most one statement.
* Section
Sections are of the form [SecitonTitle "SectionArgument"],
where section argument is optional.
* List
We use colon-separated string to represent a list.
For instance, n1:n2:n3:n4 is a list containing four values.
Below is an example of a RocksDB options file:
[Version]
rocksdb_version=4.0.0
options_file_version=1.0
[DBOptions]
max_open_files=12345
max_background_flushes=301
[CFOptions "default"]
[CFOptions "the second column family"]
[CFOptions "the third column family"]
Test Plan: Added many tests in options_test.cc
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D46059
2015-09-29 21:42:40 +00:00
|
|
|
Status GetStringFromColumnFamilyOptions(std::string* opt_string,
|
|
|
|
const ColumnFamilyOptions& cf_options,
|
|
|
|
const std::string& delimiter) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.delimiter = delimiter;
|
|
|
|
return GetStringFromColumnFamilyOptions(config_options, cf_options,
|
|
|
|
opt_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetStringFromColumnFamilyOptions(const ConfigOptions& config_options,
|
|
|
|
const ColumnFamilyOptions& cf_options,
|
|
|
|
std::string* opt_string) {
|
|
|
|
return GetStringFromStruct(config_options, &cf_options, cf_options_type_info,
|
|
|
|
opt_string);
|
2015-08-26 23:13:56 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 22:03:21 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 00:35:28 +00:00
|
|
|
static Status ParseDBOption(const ConfigOptions& config_options,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& org_value,
|
|
|
|
DBOptions* new_options) {
|
|
|
|
const std::string& value = config_options.input_strings_escaped
|
|
|
|
? UnescapeOptionString(org_value)
|
|
|
|
: org_value;
|
2020-05-21 17:56:40 +00:00
|
|
|
std::string elem;
|
|
|
|
const auto opt_info = OptionTypeInfo::Find(name, db_options_type_info, &elem);
|
|
|
|
if (opt_info == nullptr) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return Status::InvalidArgument("Unrecognized option DBOptions:", name);
|
|
|
|
} else {
|
2020-05-21 17:56:40 +00:00
|
|
|
return opt_info->Parse(
|
|
|
|
config_options, elem, value,
|
|
|
|
reinterpret_cast<char*>(new_options) + opt_info->offset_);
|
2015-02-20 03:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-10 17:00:12 +00:00
|
|
|
|
2014-12-22 21:18:57 +00:00
|
|
|
Status GetColumnFamilyOptionsFromMap(
|
2014-10-10 17:00:12 +00:00
|
|
|
const ColumnFamilyOptions& base_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
2017-06-13 23:55:08 +00:00
|
|
|
ColumnFamilyOptions* new_options, bool input_strings_escaped,
|
|
|
|
bool ignore_unknown_options) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.ignore_unknown_options = ignore_unknown_options;
|
|
|
|
config_options.input_strings_escaped = input_strings_escaped;
|
|
|
|
return GetColumnFamilyOptionsFromMap(config_options, base_options, opts_map,
|
|
|
|
new_options);
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 00:35:28 +00:00
|
|
|
Status GetColumnFamilyOptionsFromMap(
|
|
|
|
const ConfigOptions& config_options,
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
const ColumnFamilyOptions& base_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
2020-04-22 00:35:28 +00:00
|
|
|
ColumnFamilyOptions* new_options) {
|
2014-09-17 19:46:32 +00:00
|
|
|
assert(new_options);
|
|
|
|
*new_options = base_options;
|
2014-10-10 17:00:12 +00:00
|
|
|
for (const auto& o : opts_map) {
|
2020-04-22 00:35:28 +00:00
|
|
|
auto s =
|
|
|
|
ParseColumnFamilyOption(config_options, o.first, o.second, new_options);
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
if (s.IsNotSupported()) {
|
2020-04-22 00:35:28 +00:00
|
|
|
continue;
|
|
|
|
} else if (s.IsInvalidArgument() &&
|
|
|
|
config_options.ignore_unknown_options) {
|
2017-06-13 23:55:08 +00:00
|
|
|
continue;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
} else {
|
2016-08-11 21:54:29 +00:00
|
|
|
// Restore "new_options" to the default "base_options".
|
|
|
|
*new_options = base_options;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
return s;
|
2015-10-02 22:35:32 +00:00
|
|
|
}
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-22 21:18:57 +00:00
|
|
|
return Status::OK();
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 21:18:57 +00:00
|
|
|
Status GetColumnFamilyOptionsFromString(
|
2014-10-10 17:00:12 +00:00
|
|
|
const ColumnFamilyOptions& base_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
ColumnFamilyOptions* new_options) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = false;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
return GetColumnFamilyOptionsFromString(config_options, base_options,
|
|
|
|
opts_str, new_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetColumnFamilyOptionsFromString(const ConfigOptions& config_options,
|
|
|
|
const ColumnFamilyOptions& base_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
ColumnFamilyOptions* new_options) {
|
2014-10-10 17:00:12 +00:00
|
|
|
std::unordered_map<std::string, std::string> opts_map;
|
2014-12-22 21:18:57 +00:00
|
|
|
Status s = StringToMap(opts_str, &opts_map);
|
|
|
|
if (!s.ok()) {
|
2016-08-11 21:54:29 +00:00
|
|
|
*new_options = base_options;
|
2014-12-22 21:18:57 +00:00
|
|
|
return s;
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
2020-04-22 00:35:28 +00:00
|
|
|
return GetColumnFamilyOptionsFromMap(config_options, base_options, opts_map,
|
|
|
|
new_options);
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 21:18:57 +00:00
|
|
|
Status GetDBOptionsFromMap(
|
2014-10-10 17:00:12 +00:00
|
|
|
const DBOptions& base_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
2017-06-13 23:55:08 +00:00
|
|
|
DBOptions* new_options, bool input_strings_escaped,
|
|
|
|
bool ignore_unknown_options) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = input_strings_escaped;
|
|
|
|
config_options.ignore_unknown_options = ignore_unknown_options;
|
|
|
|
return GetDBOptionsFromMap(config_options, base_options, opts_map,
|
|
|
|
new_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetDBOptionsFromMap(
|
|
|
|
const ConfigOptions& config_options, const DBOptions& base_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
|
|
|
DBOptions* new_options) {
|
|
|
|
return GetDBOptionsFromMapInternal(config_options, base_options, opts_map,
|
|
|
|
new_options, nullptr);
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status GetDBOptionsFromMapInternal(
|
2020-04-22 00:35:28 +00:00
|
|
|
const ConfigOptions& config_options, const DBOptions& base_options,
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
2020-04-22 00:35:28 +00:00
|
|
|
DBOptions* new_options,
|
|
|
|
std::vector<std::string>* unsupported_options_names) {
|
2014-10-10 17:00:12 +00:00
|
|
|
assert(new_options);
|
|
|
|
*new_options = base_options;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
if (unsupported_options_names) {
|
|
|
|
unsupported_options_names->clear();
|
|
|
|
}
|
2014-10-10 17:00:12 +00:00
|
|
|
for (const auto& o : opts_map) {
|
2020-04-22 00:35:28 +00:00
|
|
|
auto s = ParseDBOption(config_options, o.first, o.second, new_options);
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
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
|
2020-04-22 00:35:28 +00:00
|
|
|
} else if (s.IsInvalidArgument() &&
|
|
|
|
config_options.ignore_unknown_options) {
|
2017-06-13 23:55:08 +00:00
|
|
|
continue;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
} else {
|
2016-08-11 21:54:29 +00:00
|
|
|
// Restore "new_options" to the default "base_options".
|
|
|
|
*new_options = base_options;
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
return s;
|
|
|
|
}
|
2014-09-17 19:46:32 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-22 21:18:57 +00:00
|
|
|
return Status::OK();
|
2014-09-17 19:46:32 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 00:35:28 +00:00
|
|
|
Status GetDBOptionsFromString(const DBOptions& base_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
DBOptions* new_options) {
|
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = false;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
|
|
|
|
return GetDBOptionsFromString(config_options, base_options, opts_str,
|
|
|
|
new_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetDBOptionsFromString(const ConfigOptions& config_options,
|
|
|
|
const DBOptions& base_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
DBOptions* new_options) {
|
2014-10-10 17:00:12 +00:00
|
|
|
std::unordered_map<std::string, std::string> opts_map;
|
2014-12-22 21:18:57 +00:00
|
|
|
Status s = StringToMap(opts_str, &opts_map);
|
|
|
|
if (!s.ok()) {
|
2016-08-11 21:54:29 +00:00
|
|
|
*new_options = base_options;
|
2014-12-22 21:18:57 +00:00
|
|
|
return s;
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
2020-04-22 00:35:28 +00:00
|
|
|
return GetDBOptionsFromMap(config_options, base_options, opts_map,
|
|
|
|
new_options);
|
2014-10-10 17:00:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 03:11:14 +00:00
|
|
|
Status GetOptionsFromString(const Options& base_options,
|
|
|
|
const std::string& opts_str, Options* new_options) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = false;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
|
|
|
|
return GetOptionsFromString(config_options, base_options, opts_str,
|
|
|
|
new_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetOptionsFromString(const ConfigOptions& config_options,
|
|
|
|
const Options& base_options,
|
|
|
|
const std::string& opts_str, Options* new_options) {
|
2015-02-20 03:11:14 +00:00
|
|
|
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) {
|
2020-04-22 00:35:28 +00:00
|
|
|
if (ParseDBOption(config_options, o.first, o.second, &new_db_options)
|
|
|
|
.ok()) {
|
|
|
|
} else if (ParseColumnFamilyOption(config_options, o.first, o.second,
|
|
|
|
&new_cf_options)
|
|
|
|
.ok()) {
|
2015-02-20 03:11:14 +00:00
|
|
|
} else {
|
|
|
|
return Status::InvalidArgument("Can't parse option " + o.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*new_options = Options(new_db_options, new_cf_options);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2015-10-11 19:17:42 +00:00
|
|
|
Status GetTableFactoryFromMap(
|
|
|
|
const std::string& factory_name,
|
|
|
|
const std::unordered_map<std::string, std::string>& opt_map,
|
2017-06-13 23:55:08 +00:00
|
|
|
std::shared_ptr<TableFactory>* table_factory, bool ignore_unknown_options) {
|
2020-04-22 00:35:28 +00:00
|
|
|
ConfigOptions
|
|
|
|
config_options; // Use default for escaped(true) and check (exact)
|
|
|
|
config_options.ignore_unknown_options = ignore_unknown_options;
|
|
|
|
return GetTableFactoryFromMap(config_options, factory_name, opt_map,
|
|
|
|
table_factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetTableFactoryFromMap(
|
|
|
|
const ConfigOptions& config_options, const std::string& factory_name,
|
|
|
|
const std::unordered_map<std::string, std::string>& opt_map,
|
|
|
|
std::shared_ptr<TableFactory>* table_factory) {
|
2015-10-11 19:17:42 +00:00
|
|
|
Status s;
|
|
|
|
if (factory_name == BlockBasedTableFactory().Name()) {
|
|
|
|
BlockBasedTableOptions bbt_opt;
|
2020-04-22 00:35:28 +00:00
|
|
|
s = GetBlockBasedTableOptionsFromMap(
|
|
|
|
config_options, BlockBasedTableOptions(), opt_map, &bbt_opt);
|
2015-10-11 19:17:42 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
table_factory->reset(new BlockBasedTableFactory(bbt_opt));
|
2020-05-08 19:36:49 +00:00
|
|
|
return s;
|
2015-10-28 17:46:01 +00:00
|
|
|
} else if (factory_name == PlainTableFactory().Name()) {
|
|
|
|
PlainTableOptions pt_opt;
|
2020-04-22 00:35:28 +00:00
|
|
|
s = GetPlainTableOptionsFromMap(config_options, PlainTableOptions(),
|
|
|
|
opt_map, &pt_opt);
|
2015-10-28 17:46:01 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
table_factory->reset(new PlainTableFactory(pt_opt));
|
2020-05-08 19:36:49 +00:00
|
|
|
return s;
|
2015-10-11 19:17:42 +00:00
|
|
|
}
|
|
|
|
// Return OK for not supported table factories as TableFactory
|
|
|
|
// Deserialization is optional.
|
|
|
|
table_factory->reset();
|
2020-05-08 19:36:49 +00:00
|
|
|
return s;
|
2015-10-11 19:17:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 01:02:13 +00:00
|
|
|
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}};
|
|
|
|
|
2017-12-11 21:12:12 +00:00
|
|
|
std::unordered_map<std::string, CompactionStopStyle>
|
|
|
|
OptionsHelper::compaction_stop_style_string_map = {
|
|
|
|
{"kCompactionStopStyleSimilarSize", kCompactionStopStyleSimilarSize},
|
|
|
|
{"kCompactionStopStyleTotalSize", kCompactionStopStyleTotalSize}};
|
|
|
|
|
2020-06-03 19:19:54 +00:00
|
|
|
Status OptionTypeInfo::NextToken(const std::string& opts, char delimiter,
|
|
|
|
size_t pos, size_t* end, std::string* token) {
|
|
|
|
while (pos < opts.size() && isspace(opts[pos])) {
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
// Empty value at the end
|
|
|
|
if (pos >= opts.size()) {
|
|
|
|
*token = "";
|
|
|
|
*end = std::string::npos;
|
|
|
|
return Status::OK();
|
|
|
|
} else 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) {
|
|
|
|
*token = trim(opts.substr(pos + 1, brace_pos - pos - 1));
|
|
|
|
// skip all whitespace and move to the next delimiter
|
|
|
|
// 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] != delimiter) {
|
|
|
|
return Status::InvalidArgument("Unexpected chars after nested options");
|
|
|
|
}
|
|
|
|
*end = pos;
|
|
|
|
} else {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"Mismatched curly braces for nested options");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*end = opts.find(delimiter, pos);
|
|
|
|
if (*end == std::string::npos) {
|
|
|
|
// It either ends with a trailing semi-colon or the last key-value pair
|
|
|
|
*token = trim(opts.substr(pos));
|
|
|
|
} else {
|
|
|
|
*token = trim(opts.substr(pos, *end - pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:56:40 +00:00
|
|
|
Status OptionTypeInfo::Parse(const ConfigOptions& config_options,
|
|
|
|
const std::string& opt_name,
|
|
|
|
const std::string& opt_value,
|
|
|
|
char* opt_addr) const {
|
2020-04-29 01:02:11 +00:00
|
|
|
if (IsDeprecated()) {
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (opt_addr == nullptr) {
|
|
|
|
return Status::NotFound("Could not find option: ", opt_name);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (parse_func_ != nullptr) {
|
|
|
|
return parse_func_(config_options, opt_name, opt_value, opt_addr);
|
|
|
|
} else if (ParseOptionHelper(opt_addr, type_, opt_value)) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return Status::OK();
|
|
|
|
} else if (IsByName()) {
|
|
|
|
return Status::NotSupported("Deserializing the option " + opt_name +
|
|
|
|
" is not supported");
|
|
|
|
} else {
|
|
|
|
return Status::InvalidArgument("Error parsing:", opt_name);
|
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
return Status::InvalidArgument("Error parsing " + opt_name + ":" +
|
|
|
|
std::string(e.what()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:56:40 +00:00
|
|
|
Status OptionTypeInfo::ParseStruct(
|
|
|
|
const ConfigOptions& config_options, const std::string& struct_name,
|
|
|
|
const std::unordered_map<std::string, OptionTypeInfo>* struct_map,
|
|
|
|
const std::string& opt_name, const std::string& opt_value, char* opt_addr) {
|
|
|
|
assert(struct_map);
|
|
|
|
Status status;
|
|
|
|
if (opt_name == struct_name || EndsWith(opt_name, "." + struct_name)) {
|
|
|
|
// This option represents the entire struct
|
|
|
|
std::unordered_map<std::string, std::string> opt_map;
|
|
|
|
status = StringToMap(opt_value, &opt_map);
|
2020-05-23 13:48:40 +00:00
|
|
|
for (const auto& map_iter : opt_map) {
|
|
|
|
if (!status.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const auto iter = struct_map->find(map_iter.first);
|
|
|
|
if (iter != struct_map->end()) {
|
|
|
|
status =
|
|
|
|
iter->second.Parse(config_options, map_iter.first, map_iter.second,
|
|
|
|
opt_addr + iter->second.offset_);
|
|
|
|
} else {
|
|
|
|
status = Status::InvalidArgument("Unrecognized option: ",
|
2020-05-21 17:56:40 +00:00
|
|
|
struct_name + "." + map_iter.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (StartsWith(opt_name, struct_name + ".")) {
|
|
|
|
// This option represents a nested field in the struct (e.g, struct.field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info =
|
|
|
|
Find(opt_name.substr(struct_name.size() + 1), *struct_map, &elem_name);
|
|
|
|
if (opt_info != nullptr) {
|
|
|
|
status = opt_info->Parse(config_options, elem_name, opt_value,
|
|
|
|
opt_addr + opt_info->offset_);
|
|
|
|
} else {
|
|
|
|
status = Status::InvalidArgument("Unrecognized option: ", opt_name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This option represents a field in the struct (e.g. field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info = Find(opt_name, *struct_map, &elem_name);
|
|
|
|
if (opt_info != nullptr) {
|
|
|
|
status = opt_info->Parse(config_options, elem_name, opt_value,
|
|
|
|
opt_addr + opt_info->offset_);
|
|
|
|
} else {
|
|
|
|
status = Status::InvalidArgument("Unrecognized option: ",
|
|
|
|
struct_name + "." + opt_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status OptionTypeInfo::Serialize(const ConfigOptions& config_options,
|
|
|
|
const std::string& opt_name,
|
|
|
|
const char* opt_addr,
|
|
|
|
std::string* opt_value) const {
|
2020-04-29 01:02:11 +00:00
|
|
|
// If the option is no longer used in rocksdb and marked as deprecated,
|
|
|
|
// we skip it in the serialization.
|
2020-05-21 17:56:40 +00:00
|
|
|
if (opt_addr != nullptr && ShouldSerialize()) {
|
|
|
|
if (serialize_func_ != nullptr) {
|
|
|
|
return serialize_func_(config_options, opt_name, opt_addr, opt_value);
|
|
|
|
} else if (!SerializeSingleOptionHelper(opt_addr, type_, opt_value)) {
|
|
|
|
return Status::InvalidArgument("Cannot serialize option: ", opt_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status OptionTypeInfo::SerializeStruct(
|
|
|
|
const ConfigOptions& config_options, const std::string& struct_name,
|
|
|
|
const std::unordered_map<std::string, OptionTypeInfo>* struct_map,
|
|
|
|
const std::string& opt_name, const char* opt_addr, std::string* value) {
|
|
|
|
assert(struct_map);
|
|
|
|
Status status;
|
|
|
|
if (EndsWith(opt_name, struct_name)) {
|
|
|
|
// We are going to write the struct as "{ prop1=value1; prop2=value2;}.
|
|
|
|
// Set the delimiter to ";" so that the everything will be on one line.
|
|
|
|
ConfigOptions embedded = config_options;
|
|
|
|
embedded.delimiter = ";";
|
|
|
|
|
|
|
|
// This option represents the entire struct
|
|
|
|
std::string result;
|
|
|
|
for (const auto& iter : *struct_map) {
|
|
|
|
std::string single;
|
|
|
|
const auto& opt_info = iter.second;
|
|
|
|
if (opt_info.ShouldSerialize()) {
|
|
|
|
status = opt_info.Serialize(embedded, iter.first,
|
|
|
|
opt_addr + opt_info.offset_, &single);
|
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
} else {
|
|
|
|
result.append(iter.first + "=" + single + embedded.delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*value = "{" + result + "}";
|
|
|
|
} else if (StartsWith(opt_name, struct_name + ".")) {
|
|
|
|
// This option represents a nested field in the struct (e.g, struct.field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info =
|
|
|
|
Find(opt_name.substr(struct_name.size() + 1), *struct_map, &elem_name);
|
|
|
|
if (opt_info != nullptr) {
|
|
|
|
status = opt_info->Serialize(config_options, elem_name,
|
|
|
|
opt_addr + opt_info->offset_, value);
|
|
|
|
} else {
|
|
|
|
status = Status::InvalidArgument("Unrecognized option: ", opt_name);
|
|
|
|
}
|
2020-04-29 01:02:11 +00:00
|
|
|
} else {
|
2020-05-21 17:56:40 +00:00
|
|
|
// This option represents a field in the struct (e.g. field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info = Find(opt_name, *struct_map, &elem_name);
|
|
|
|
if (opt_info == nullptr) {
|
2020-05-22 18:15:44 +00:00
|
|
|
status = Status::InvalidArgument("Unrecognized option: ", opt_name);
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (opt_info->ShouldSerialize()) {
|
2020-05-22 18:15:44 +00:00
|
|
|
status = opt_info->Serialize(config_options, opt_name + "." + elem_name,
|
|
|
|
opt_addr + opt_info->offset_, value);
|
2020-05-21 17:56:40 +00:00
|
|
|
}
|
2020-04-29 01:02:11 +00:00
|
|
|
}
|
2020-05-22 18:15:44 +00:00
|
|
|
return status;
|
2020-04-29 01:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool IsOptionEqual(const char* offset1, const char* offset2) {
|
|
|
|
return (*reinterpret_cast<const T*>(offset1) ==
|
|
|
|
*reinterpret_cast<const T*>(offset2));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool AreEqualDoubles(const double a, const double b) {
|
|
|
|
return (fabs(a - b) < 0.00001);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool AreOptionsEqual(OptionType type, const char* this_offset,
|
|
|
|
const char* that_offset) {
|
|
|
|
switch (type) {
|
|
|
|
case OptionType::kBoolean:
|
|
|
|
return IsOptionEqual<bool>(this_offset, that_offset);
|
|
|
|
case OptionType::kInt:
|
|
|
|
return IsOptionEqual<int>(this_offset, that_offset);
|
|
|
|
case OptionType::kUInt:
|
|
|
|
return IsOptionEqual<unsigned int>(this_offset, that_offset);
|
|
|
|
case OptionType::kInt32T:
|
|
|
|
return IsOptionEqual<int32_t>(this_offset, that_offset);
|
|
|
|
case OptionType::kInt64T: {
|
|
|
|
int64_t v1, v2;
|
|
|
|
GetUnaligned(reinterpret_cast<const int64_t*>(this_offset), &v1);
|
|
|
|
GetUnaligned(reinterpret_cast<const int64_t*>(that_offset), &v2);
|
|
|
|
return (v1 == v2);
|
|
|
|
}
|
|
|
|
case OptionType::kUInt32T:
|
|
|
|
return IsOptionEqual<uint32_t>(this_offset, that_offset);
|
|
|
|
case OptionType::kUInt64T: {
|
|
|
|
uint64_t v1, v2;
|
|
|
|
GetUnaligned(reinterpret_cast<const uint64_t*>(this_offset), &v1);
|
|
|
|
GetUnaligned(reinterpret_cast<const uint64_t*>(that_offset), &v2);
|
|
|
|
return (v1 == v2);
|
|
|
|
}
|
|
|
|
case OptionType::kSizeT: {
|
|
|
|
size_t v1, v2;
|
|
|
|
GetUnaligned(reinterpret_cast<const size_t*>(this_offset), &v1);
|
|
|
|
GetUnaligned(reinterpret_cast<const size_t*>(that_offset), &v2);
|
|
|
|
return (v1 == v2);
|
|
|
|
}
|
|
|
|
case OptionType::kString:
|
|
|
|
return IsOptionEqual<std::string>(this_offset, that_offset);
|
|
|
|
case OptionType::kDouble:
|
|
|
|
return AreEqualDoubles(*reinterpret_cast<const double*>(this_offset),
|
|
|
|
*reinterpret_cast<const double*>(that_offset));
|
|
|
|
case OptionType::kCompactionStyle:
|
|
|
|
return IsOptionEqual<CompactionStyle>(this_offset, that_offset);
|
|
|
|
case OptionType::kCompactionStopStyle:
|
|
|
|
return IsOptionEqual<CompactionStopStyle>(this_offset, that_offset);
|
|
|
|
case OptionType::kCompactionPri:
|
|
|
|
return IsOptionEqual<CompactionPri>(this_offset, that_offset);
|
|
|
|
case OptionType::kCompressionType:
|
|
|
|
return IsOptionEqual<CompressionType>(this_offset, that_offset);
|
|
|
|
case OptionType::kChecksumType:
|
|
|
|
return IsOptionEqual<ChecksumType>(this_offset, that_offset);
|
|
|
|
case OptionType::kEncodingType:
|
|
|
|
return IsOptionEqual<EncodingType>(this_offset, that_offset);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
} // End switch
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:56:40 +00:00
|
|
|
bool OptionTypeInfo::AreEqual(const ConfigOptions& config_options,
|
|
|
|
const std::string& opt_name,
|
|
|
|
const char* this_addr, const char* that_addr,
|
|
|
|
std::string* mismatch) const {
|
2020-04-29 01:02:11 +00:00
|
|
|
if (!config_options.IsCheckEnabled(GetSanityLevel())) {
|
|
|
|
return true; // If the sanity level is not being checked, skip it
|
|
|
|
}
|
|
|
|
if (this_addr == nullptr || that_addr == nullptr) {
|
|
|
|
if (this_addr == that_addr) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (equals_func_ != nullptr) {
|
|
|
|
if (equals_func_(config_options, opt_name, this_addr, that_addr,
|
|
|
|
mismatch)) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (AreOptionsEqual(type_, this_addr, that_addr)) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (mismatch->empty()) {
|
|
|
|
*mismatch = opt_name;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:56:40 +00:00
|
|
|
bool OptionTypeInfo::StructsAreEqual(
|
|
|
|
const ConfigOptions& config_options, const std::string& struct_name,
|
|
|
|
const std::unordered_map<std::string, OptionTypeInfo>* struct_map,
|
|
|
|
const std::string& opt_name, const char* this_addr, const char* that_addr,
|
|
|
|
std::string* mismatch) {
|
|
|
|
assert(struct_map);
|
|
|
|
bool matches = true;
|
|
|
|
std::string result;
|
|
|
|
if (EndsWith(opt_name, struct_name)) {
|
|
|
|
// This option represents the entire struct
|
|
|
|
for (const auto& iter : *struct_map) {
|
|
|
|
const auto& opt_info = iter.second;
|
|
|
|
|
|
|
|
matches = opt_info.AreEqual(config_options, iter.first,
|
|
|
|
this_addr + opt_info.offset_,
|
|
|
|
that_addr + opt_info.offset_, &result);
|
|
|
|
if (!matches) {
|
|
|
|
*mismatch = struct_name + "." + result;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (StartsWith(opt_name, struct_name + ".")) {
|
|
|
|
// This option represents a nested field in the struct (e.g, struct.field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info =
|
|
|
|
Find(opt_name.substr(struct_name.size() + 1), *struct_map, &elem_name);
|
|
|
|
assert(opt_info);
|
|
|
|
if (opt_info == nullptr) {
|
|
|
|
*mismatch = opt_name;
|
|
|
|
matches = false;
|
|
|
|
} else if (!opt_info->AreEqual(config_options, elem_name,
|
|
|
|
this_addr + opt_info->offset_,
|
|
|
|
that_addr + opt_info->offset_, &result)) {
|
|
|
|
matches = false;
|
|
|
|
*mismatch = struct_name + "." + result;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This option represents a field in the struct (e.g. field)
|
|
|
|
std::string elem_name;
|
|
|
|
const auto opt_info = Find(opt_name, *struct_map, &elem_name);
|
|
|
|
assert(opt_info);
|
|
|
|
if (opt_info == nullptr) {
|
|
|
|
*mismatch = struct_name + "." + opt_name;
|
|
|
|
matches = false;
|
|
|
|
} else if (!opt_info->AreEqual(config_options, elem_name,
|
|
|
|
this_addr + opt_info->offset_,
|
|
|
|
that_addr + opt_info->offset_, &result)) {
|
|
|
|
matches = false;
|
|
|
|
*mismatch = struct_name + "." + result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OptionTypeInfo::AreEqualByName(const ConfigOptions& config_options,
|
|
|
|
const std::string& opt_name,
|
|
|
|
const char* this_addr,
|
|
|
|
const char* that_addr) const {
|
2020-04-29 01:02:11 +00:00
|
|
|
if (IsByName()) {
|
|
|
|
std::string that_value;
|
2020-05-21 17:56:40 +00:00
|
|
|
if (Serialize(config_options, opt_name, that_addr, &that_value).ok()) {
|
|
|
|
return AreEqualByName(config_options, opt_name, this_addr, that_value);
|
2020-04-29 01:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:56:40 +00:00
|
|
|
bool OptionTypeInfo::AreEqualByName(const ConfigOptions& config_options,
|
|
|
|
const std::string& opt_name,
|
|
|
|
const char* opt_addr,
|
|
|
|
const std::string& that_value) const {
|
2020-04-29 01:02:11 +00:00
|
|
|
std::string this_value;
|
|
|
|
if (!IsByName()) {
|
|
|
|
return false;
|
2020-05-21 17:56:40 +00:00
|
|
|
} else if (!Serialize(config_options, opt_name, opt_addr, &this_value).ok()) {
|
2020-04-29 01:02:11 +00:00
|
|
|
return false;
|
|
|
|
} else if (IsEnabled(OptionVerificationType::kByNameAllowFromNull)) {
|
|
|
|
if (that_value == kNullptrString) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (IsEnabled(OptionVerificationType::kByNameAllowNull)) {
|
|
|
|
if (that_value == kNullptrString) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (this_value == that_value);
|
|
|
|
}
|
2020-05-21 17:56:40 +00:00
|
|
|
|
|
|
|
const OptionTypeInfo* OptionTypeInfo::Find(
|
|
|
|
const std::string& opt_name,
|
|
|
|
const std::unordered_map<std::string, OptionTypeInfo>& opt_map,
|
|
|
|
std::string* elem_name) {
|
|
|
|
const auto iter = opt_map.find(opt_name); // Look up the value in the map
|
|
|
|
if (iter != opt_map.end()) { // Found the option in the map
|
|
|
|
*elem_name = opt_name; // Return the name
|
|
|
|
return &(iter->second); // Return the contents of the iterator
|
|
|
|
} else {
|
|
|
|
auto idx = opt_name.find("."); // Look for a separator
|
|
|
|
if (idx > 0 && idx != std::string::npos) { // We found a separator
|
|
|
|
auto siter =
|
|
|
|
opt_map.find(opt_name.substr(0, idx)); // Look for the short name
|
|
|
|
if (siter != opt_map.end()) { // We found the short name
|
|
|
|
if (siter->second.IsStruct()) { // If the object is a struct
|
|
|
|
*elem_name = opt_name.substr(idx + 1); // Return the rest
|
|
|
|
return &(siter->second); // Return the contents of the iterator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
RocksDB Options file format and its serialization / deserialization.
Summary:
This patch defines the format of RocksDB options file, which
follows the INI file format, and implements functions for its
serialization and deserialization. An example RocksDB options
file can be found in examples/rocksdb_option_file_example.ini.
A typical RocksDB options file has three sections, which are
Version, DBOptions, and more than one CFOptions. The RocksDB
options file in general follows the basic INI file format
with the following extensions / modifications:
* Escaped characters
We escaped the following characters:
- \n -- line feed - new line
- \r -- carriage return
- \\ -- backslash \
- \: -- colon symbol :
- \# -- hash tag #
* Comments
We support # style comments. Comments can appear at the ending
part of a line.
* Statements
A statement is of the form option_name = value.
Each statement contains a '=', where extra white-spaces
are supported. However, we don't support multi-lined statement.
Furthermore, each line can only contain at most one statement.
* Section
Sections are of the form [SecitonTitle "SectionArgument"],
where section argument is optional.
* List
We use colon-separated string to represent a list.
For instance, n1:n2:n3:n4 is a list containing four values.
Below is an example of a RocksDB options file:
[Version]
rocksdb_version=4.0.0
options_file_version=1.0
[DBOptions]
max_open_files=12345
max_background_flushes=301
[CFOptions "default"]
[CFOptions "the second column family"]
[CFOptions "the third column family"]
Test Plan: Added many tests in options_test.cc
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: maykov, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D46059
2015-09-29 21:42:40 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|
2016-09-15 05:10:28 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|