2016-02-09 15:12:00 -08:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 16:03:42 -07: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).
|
2014-09-17 12:49:13 -07:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-02-07 10:35:15 -08:00
|
|
|
#include <map>
|
2014-11-18 22:21:02 +01:00
|
|
|
#include <stdexcept>
|
2016-09-20 13:02:41 -07:00
|
|
|
#include <string>
|
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 06:52:43 -08:00
|
|
|
#include <vector>
|
|
|
|
|
2015-08-26 16:13:56 -07:00
|
|
|
#include "rocksdb/options.h"
|
2014-11-04 16:23:05 -08:00
|
|
|
#include "rocksdb/status.h"
|
2015-10-11 12:17:42 -07:00
|
|
|
#include "rocksdb/table.h"
|
2014-09-17 12:49:13 -07:00
|
|
|
|
2020-02-20 12:07:53 -08:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2020-09-14 16:59:00 -07:00
|
|
|
struct ColumnFamilyOptions;
|
2020-04-21 17:35:28 -07:00
|
|
|
struct ConfigOptions;
|
2020-09-14 16:59:00 -07:00
|
|
|
struct DBOptions;
|
2021-04-22 20:42:50 -07:00
|
|
|
struct ImmutableCFOptions;
|
2020-09-14 16:59:00 -07:00
|
|
|
struct ImmutableDBOptions;
|
|
|
|
struct MutableDBOptions;
|
|
|
|
struct MutableCFOptions;
|
|
|
|
struct Options;
|
2014-09-17 12:49:13 -07:00
|
|
|
|
2020-04-24 15:30:12 -07:00
|
|
|
std::vector<CompressionType> GetSupportedCompressions();
|
|
|
|
|
2020-11-02 19:20:15 -08:00
|
|
|
std::vector<CompressionType> GetSupportedDictCompressions();
|
|
|
|
|
2020-09-14 16:59:00 -07:00
|
|
|
// Checks that the combination of DBOptions and ColumnFamilyOptions are valid
|
|
|
|
Status ValidateOptions(const DBOptions& db_opts,
|
|
|
|
const ColumnFamilyOptions& cf_opts);
|
|
|
|
|
2016-09-23 16:34:04 -07:00
|
|
|
DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
|
|
|
|
const MutableDBOptions& mutable_db_options);
|
|
|
|
|
2016-09-14 22:10:28 -07:00
|
|
|
ColumnFamilyOptions BuildColumnFamilyOptions(
|
|
|
|
const ColumnFamilyOptions& ioptions,
|
|
|
|
const MutableCFOptions& mutable_cf_options);
|
2021-05-05 13:59:21 -07:00
|
|
|
|
|
|
|
void UpdateColumnFamilyOptions(const ImmutableCFOptions& ioptions,
|
|
|
|
ColumnFamilyOptions* cf_opts);
|
|
|
|
void UpdateColumnFamilyOptions(const MutableCFOptions& moptions,
|
|
|
|
ColumnFamilyOptions* cf_opts);
|
2016-09-14 22:10:28 -07:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2020-09-14 16:59:00 -07:00
|
|
|
std::unique_ptr<Configurable> DBOptionsAsConfigurable(
|
|
|
|
const MutableDBOptions& opts);
|
|
|
|
std::unique_ptr<Configurable> DBOptionsAsConfigurable(const DBOptions& opts);
|
|
|
|
std::unique_ptr<Configurable> CFOptionsAsConfigurable(
|
|
|
|
const MutableCFOptions& opts);
|
|
|
|
std::unique_ptr<Configurable> CFOptionsAsConfigurable(
|
|
|
|
const ColumnFamilyOptions& opts,
|
|
|
|
const std::unordered_map<std::string, std::string>* opt_map = nullptr);
|
|
|
|
|
2016-10-14 12:25:39 -07:00
|
|
|
|
2018-06-26 15:56:26 -07:00
|
|
|
bool ParseSliceTransform(
|
|
|
|
const std::string& value,
|
|
|
|
std::shared_ptr<const SliceTransform>* slice_transform);
|
|
|
|
|
2017-07-28 16:23:50 -07:00
|
|
|
extern Status StringToMap(
|
|
|
|
const std::string& opts_str,
|
|
|
|
std::unordered_map<std::string, std::string>* opts_map);
|
2016-09-14 22:10:28 -07:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2017-11-17 17:02:13 -08:00
|
|
|
struct OptionsHelper {
|
2020-09-14 16:59:00 -07:00
|
|
|
static const std::string kCFOptionsName /*= "ColumnFamilyOptions"*/;
|
|
|
|
static const std::string kDBOptionsName /*= "DBOptions" */;
|
2017-11-17 17:02:13 -08:00
|
|
|
static std::map<CompactionStyle, std::string> compaction_style_to_string;
|
|
|
|
static std::map<CompactionPri, std::string> compaction_pri_to_string;
|
|
|
|
static std::map<CompactionStopStyle, std::string>
|
|
|
|
compaction_stop_style_to_string;
|
|
|
|
static std::unordered_map<std::string, ChecksumType> checksum_type_string_map;
|
2018-01-23 14:36:54 -08:00
|
|
|
static std::unordered_map<std::string, CompressionType>
|
|
|
|
compression_type_string_map;
|
2017-11-17 17:02:13 -08:00
|
|
|
#ifndef ROCKSDB_LITE
|
2017-12-11 13:12:12 -08:00
|
|
|
static std::unordered_map<std::string, CompactionStopStyle>
|
|
|
|
compaction_stop_style_string_map;
|
2017-11-17 17:02:13 -08:00
|
|
|
static std::unordered_map<std::string, EncodingType> encoding_type_string_map;
|
|
|
|
static std::unordered_map<std::string, CompactionStyle>
|
|
|
|
compaction_style_string_map;
|
|
|
|
static std::unordered_map<std::string, CompactionPri>
|
|
|
|
compaction_pri_string_map;
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
};
|
|
|
|
|
|
|
|
// Some aliasing
|
|
|
|
static auto& compaction_style_to_string =
|
|
|
|
OptionsHelper::compaction_style_to_string;
|
|
|
|
static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string;
|
|
|
|
static auto& compaction_stop_style_to_string =
|
|
|
|
OptionsHelper::compaction_stop_style_to_string;
|
|
|
|
static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map;
|
|
|
|
#ifndef ROCKSDB_LITE
|
2017-12-11 13:12:12 -08:00
|
|
|
static auto& compaction_stop_style_string_map =
|
|
|
|
OptionsHelper::compaction_stop_style_string_map;
|
2017-11-17 17:02:13 -08:00
|
|
|
static auto& compression_type_string_map =
|
|
|
|
OptionsHelper::compression_type_string_map;
|
|
|
|
static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map;
|
|
|
|
static auto& compaction_style_string_map =
|
|
|
|
OptionsHelper::compaction_style_string_map;
|
|
|
|
static auto& compaction_pri_string_map =
|
|
|
|
OptionsHelper::compaction_pri_string_map;
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2020-02-20 12:07:53 -08:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|