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).
|
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
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include <cctype>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "options/options_parser.h"
|
2015-11-13 00:52:51 +00:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/table.h"
|
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
|
|
|
#include "rocksdb/utilities/options_util.h"
|
|
|
|
#include "util/random.h"
|
|
|
|
#include "util/testharness.h"
|
|
|
|
#include "util/testutil.h"
|
|
|
|
|
|
|
|
#ifndef GFLAGS
|
|
|
|
bool FLAGS_enable_print = false;
|
|
|
|
#else
|
2017-12-01 18:40:45 +00:00
|
|
|
#include "util/gflags_compat.h"
|
|
|
|
using GFLAGS_NAMESPACE::ParseCommandLineFlags;
|
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
|
|
|
DEFINE_bool(enable_print, false, "Print options generated to console.");
|
|
|
|
#endif // GFLAGS
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
class OptionsUtilTest : public testing::Test {
|
|
|
|
public:
|
2015-11-13 00:52:51 +00:00
|
|
|
OptionsUtilTest() : rnd_(0xFB) {
|
|
|
|
env_.reset(new test::StringEnv(Env::Default()));
|
2018-07-14 00:18:39 +00:00
|
|
|
dbname_ = test::PerThreadDBPath("options_util_test");
|
2015-11-13 00:52:51 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
protected:
|
|
|
|
std::unique_ptr<test::StringEnv> env_;
|
2015-11-13 00:52:51 +00:00
|
|
|
std::string dbname_;
|
|
|
|
Random rnd_;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
bool IsBlockBasedTableFactory(TableFactory* tf) {
|
|
|
|
return tf->Name() == BlockBasedTableFactory().Name();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, SaveAndLoad) {
|
|
|
|
const size_t kCFCount = 5;
|
|
|
|
|
|
|
|
DBOptions db_opt;
|
|
|
|
std::vector<std::string> cf_names;
|
|
|
|
std::vector<ColumnFamilyOptions> cf_opts;
|
2015-11-13 00:52:51 +00:00
|
|
|
test::RandomInitDBOptions(&db_opt, &rnd_);
|
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
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
cf_names.push_back(i == 0 ? kDefaultColumnFamilyName
|
2015-11-13 00:52:51 +00:00
|
|
|
: test::RandomName(&rnd_, 10));
|
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
|
|
|
cf_opts.emplace_back();
|
2015-11-13 00:52:51 +00:00
|
|
|
test::RandomInitCFOptions(&cf_opts.back(), &rnd_);
|
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::string kFileName = "OPTIONS-123456";
|
|
|
|
PersistRocksDBOptions(db_opt, cf_names, cf_opts, kFileName, env_.get());
|
|
|
|
|
|
|
|
DBOptions loaded_db_opt;
|
|
|
|
std::vector<ColumnFamilyDescriptor> loaded_cf_descs;
|
|
|
|
ASSERT_OK(LoadOptionsFromFile(kFileName, env_.get(), &loaded_db_opt,
|
|
|
|
&loaded_cf_descs));
|
|
|
|
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(db_opt, loaded_db_opt));
|
2015-11-13 00:52:51 +00:00
|
|
|
test::RandomInitDBOptions(&db_opt, &rnd_);
|
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
|
|
|
ASSERT_NOK(RocksDBOptionsParser::VerifyDBOptions(db_opt, loaded_db_opt));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
ASSERT_EQ(cf_names[i], loaded_cf_descs[i].name);
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(
|
|
|
|
cf_opts[i], loaded_cf_descs[i].options));
|
|
|
|
if (IsBlockBasedTableFactory(cf_opts[i].table_factory.get())) {
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyTableFactory(
|
|
|
|
cf_opts[i].table_factory.get(),
|
|
|
|
loaded_cf_descs[i].options.table_factory.get()));
|
|
|
|
}
|
2015-11-13 00:52:51 +00:00
|
|
|
test::RandomInitCFOptions(&cf_opts[i], &rnd_);
|
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
|
|
|
ASSERT_NOK(RocksDBOptionsParser::VerifyCFOptions(
|
|
|
|
cf_opts[i], loaded_cf_descs[i].options));
|
|
|
|
}
|
2015-11-12 22:12:27 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
if (cf_opts[i].compaction_filter) {
|
|
|
|
delete cf_opts[i].compaction_filter;
|
|
|
|
}
|
|
|
|
}
|
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-11-13 00:52:51 +00:00
|
|
|
namespace {
|
|
|
|
class DummyTableFactory : public TableFactory {
|
|
|
|
public:
|
|
|
|
DummyTableFactory() {}
|
2019-02-14 21:52:47 +00:00
|
|
|
~DummyTableFactory() override {}
|
2015-11-13 00:52:51 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
const char* Name() const override { return "DummyTableFactory"; }
|
2015-11-13 00:52:51 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status NewTableReader(
|
2018-03-05 21:08:17 +00:00
|
|
|
const TableReaderOptions& /*table_reader_options*/,
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<RandomAccessFileReader>&& /*file*/,
|
|
|
|
uint64_t /*file_size*/, std::unique_ptr<TableReader>* /*table_reader*/,
|
2018-03-05 21:08:17 +00:00
|
|
|
bool /*prefetch_index_and_filter_in_cache*/) const override {
|
2015-11-13 00:52:51 +00:00
|
|
|
return Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
TableBuilder* NewTableBuilder(
|
2018-03-05 21:08:17 +00:00
|
|
|
const TableBuilderOptions& /*table_builder_options*/,
|
|
|
|
uint32_t /*column_family_id*/,
|
|
|
|
WritableFileWriter* /*file*/) const override {
|
2015-11-13 00:52:51 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
Status SanitizeOptions(
|
2018-03-05 21:08:17 +00:00
|
|
|
const DBOptions& /*db_opts*/,
|
|
|
|
const ColumnFamilyOptions& /*cf_opts*/) const override {
|
2015-11-13 00:52:51 +00:00
|
|
|
return Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
std::string GetPrintableTableOptions() const override { return ""; }
|
2017-07-28 23:23:50 +00:00
|
|
|
|
2018-03-05 21:08:17 +00:00
|
|
|
Status GetOptionString(std::string* /*opt_string*/,
|
|
|
|
const std::string& /*delimiter*/) const override {
|
2017-07-28 23:23:50 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
2015-11-13 00:52:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DummyMergeOperator : public MergeOperator {
|
|
|
|
public:
|
|
|
|
DummyMergeOperator() {}
|
2019-02-14 21:52:47 +00:00
|
|
|
~DummyMergeOperator() override {}
|
2015-11-13 00:52:51 +00:00
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool FullMergeV2(const MergeOperationInput& /*merge_in*/,
|
|
|
|
MergeOperationOutput* /*merge_out*/) const override {
|
2015-11-13 00:52:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
bool PartialMergeMulti(const Slice& /*key*/,
|
|
|
|
const std::deque<Slice>& /*operand_list*/,
|
|
|
|
std::string* /*new_value*/,
|
|
|
|
Logger* /*logger*/) const override {
|
2015-11-13 00:52:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:47 +00:00
|
|
|
const char* Name() const override { return "DummyMergeOperator"; }
|
2015-11-13 00:52:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DummySliceTransform : public SliceTransform {
|
|
|
|
public:
|
|
|
|
DummySliceTransform() {}
|
2019-02-14 21:52:47 +00:00
|
|
|
~DummySliceTransform() override {}
|
2015-11-13 00:52:51 +00:00
|
|
|
|
|
|
|
// Return the name of this transformation.
|
2019-02-14 21:52:47 +00:00
|
|
|
const char* Name() const override { return "DummySliceTransform"; }
|
2015-11-13 00:52:51 +00:00
|
|
|
|
|
|
|
// transform a src in domain to a dst in the range
|
2019-02-14 21:52:47 +00:00
|
|
|
Slice Transform(const Slice& src) const override { return src; }
|
2015-11-13 00:52:51 +00:00
|
|
|
|
|
|
|
// determine whether this is a valid src upon the function applies
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InDomain(const Slice& /*src*/) const override { return false; }
|
2015-11-13 00:52:51 +00:00
|
|
|
|
|
|
|
// determine whether dst=Transform(src) for some src
|
2019-02-14 21:52:47 +00:00
|
|
|
bool InRange(const Slice& /*dst*/) const override { return false; }
|
2015-11-13 00:52:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, SanityCheck) {
|
|
|
|
DBOptions db_opt;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
const size_t kCFCount = 5;
|
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
cf_descs.emplace_back();
|
|
|
|
cf_descs.back().name =
|
|
|
|
(i == 0) ? kDefaultColumnFamilyName : test::RandomName(&rnd_, 10);
|
|
|
|
|
|
|
|
cf_descs.back().options.table_factory.reset(NewBlockBasedTableFactory());
|
2016-02-19 22:42:24 +00:00
|
|
|
// Assign non-null values to prefix_extractors except the first cf.
|
2015-11-13 00:52:51 +00:00
|
|
|
cf_descs.back().options.prefix_extractor.reset(
|
2016-02-19 22:42:24 +00:00
|
|
|
i != 0 ? test::RandomSliceTransform(&rnd_) : nullptr);
|
2015-11-13 00:52:51 +00:00
|
|
|
cf_descs.back().options.merge_operator.reset(
|
|
|
|
test::RandomMergeOperator(&rnd_));
|
|
|
|
}
|
|
|
|
|
|
|
|
db_opt.create_missing_column_families = true;
|
|
|
|
db_opt.create_if_missing = true;
|
|
|
|
|
|
|
|
DestroyDB(dbname_, Options(db_opt, cf_descs[0].options));
|
|
|
|
DB* db;
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
// open and persist the options
|
|
|
|
ASSERT_OK(DB::Open(db_opt, dbname_, cf_descs, &handles, &db));
|
|
|
|
|
|
|
|
// close the db
|
|
|
|
for (auto* handle : handles) {
|
|
|
|
delete handle;
|
|
|
|
}
|
|
|
|
delete db;
|
|
|
|
|
|
|
|
// perform sanity check
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
ASSERT_GE(kCFCount, 5);
|
|
|
|
// merge operator
|
|
|
|
{
|
|
|
|
std::shared_ptr<MergeOperator> merge_op =
|
|
|
|
cf_descs[0].options.merge_operator;
|
|
|
|
|
|
|
|
ASSERT_NE(merge_op.get(), nullptr);
|
|
|
|
cf_descs[0].options.merge_operator.reset();
|
|
|
|
ASSERT_NOK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[0].options.merge_operator.reset(new DummyMergeOperator());
|
|
|
|
ASSERT_NOK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[0].options.merge_operator = merge_op;
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
}
|
|
|
|
|
|
|
|
// prefix extractor
|
|
|
|
{
|
|
|
|
std::shared_ptr<const SliceTransform> prefix_extractor =
|
|
|
|
cf_descs[1].options.prefix_extractor;
|
|
|
|
|
2016-02-19 22:42:24 +00:00
|
|
|
// It's okay to set prefix_extractor to nullptr.
|
2015-11-13 00:52:51 +00:00
|
|
|
ASSERT_NE(prefix_extractor, nullptr);
|
|
|
|
cf_descs[1].options.prefix_extractor.reset();
|
2016-02-19 22:42:24 +00:00
|
|
|
ASSERT_OK(
|
2015-11-13 00:52:51 +00:00
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[1].options.prefix_extractor.reset(new DummySliceTransform());
|
2017-06-22 23:16:19 +00:00
|
|
|
ASSERT_OK(
|
2015-11-13 00:52:51 +00:00
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[1].options.prefix_extractor = prefix_extractor;
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
}
|
|
|
|
|
2016-02-19 22:42:24 +00:00
|
|
|
// prefix extractor nullptr case
|
|
|
|
{
|
|
|
|
std::shared_ptr<const SliceTransform> prefix_extractor =
|
|
|
|
cf_descs[0].options.prefix_extractor;
|
|
|
|
|
|
|
|
// It's okay to set prefix_extractor to nullptr.
|
|
|
|
ASSERT_EQ(prefix_extractor, nullptr);
|
|
|
|
cf_descs[0].options.prefix_extractor.reset();
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
// It's okay to change prefix_extractor from nullptr to non-nullptr
|
|
|
|
cf_descs[0].options.prefix_extractor.reset(new DummySliceTransform());
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[0].options.prefix_extractor = prefix_extractor;
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
}
|
|
|
|
|
2015-11-13 00:52:51 +00:00
|
|
|
// comparator
|
|
|
|
{
|
|
|
|
test::SimpleSuffixReverseComparator comparator;
|
|
|
|
|
|
|
|
auto* prev_comparator = cf_descs[2].options.comparator;
|
|
|
|
cf_descs[2].options.comparator = &comparator;
|
|
|
|
ASSERT_NOK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[2].options.comparator = prev_comparator;
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
}
|
|
|
|
|
|
|
|
// table factory
|
|
|
|
{
|
|
|
|
std::shared_ptr<TableFactory> table_factory =
|
|
|
|
cf_descs[3].options.table_factory;
|
|
|
|
|
|
|
|
ASSERT_NE(table_factory, nullptr);
|
|
|
|
cf_descs[3].options.table_factory.reset(new DummyTableFactory());
|
|
|
|
ASSERT_NOK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
|
|
|
|
cf_descs[3].options.table_factory = table_factory;
|
|
|
|
ASSERT_OK(
|
|
|
|
CheckOptionsCompatibility(dbname_, Env::Default(), db_opt, cf_descs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
#ifdef GFLAGS
|
|
|
|
ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
#endif // GFLAGS
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#include <cstdio>
|
|
|
|
|
2018-04-16 00:19:57 +00:00
|
|
|
int main(int /*argc*/, char** /*argv*/) {
|
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
|
|
|
printf("Skipped in RocksDBLite as utilities are not supported.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|