2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02: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 15:52:43 +01:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2020-04-22 02:35:28 +02:00
|
|
|
#include "rocksdb/utilities/options_util.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 15:52:43 +01:00
|
|
|
|
|
|
|
#include <cctype>
|
2020-04-22 02:35:28 +02:00
|
|
|
#include <cinttypes>
|
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 15:52:43 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2020-10-15 07:27:12 +02:00
|
|
|
#include "env/mock_env.h"
|
|
|
|
#include "file/filename.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "options/options_parser.h"
|
2020-04-22 02:35:28 +02:00
|
|
|
#include "rocksdb/convenience.h"
|
2015-11-13 01:52:51 +01:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/table.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_util/testutil.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/random.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 15:52:43 +01:00
|
|
|
|
|
|
|
#ifndef GFLAGS
|
|
|
|
bool FLAGS_enable_print = false;
|
|
|
|
#else
|
2017-12-01 19:40:45 +01: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 15:52:43 +01:00
|
|
|
DEFINE_bool(enable_print, false, "Print options generated to console.");
|
|
|
|
#endif // GFLAGS
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
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 15:52:43 +01:00
|
|
|
class OptionsUtilTest : public testing::Test {
|
|
|
|
public:
|
2015-11-13 01:52:51 +01:00
|
|
|
OptionsUtilTest() : rnd_(0xFB) {
|
2020-10-15 07:27:12 +02:00
|
|
|
env_.reset(NewMemEnv(Env::Default()));
|
2018-07-14 02:18:39 +02:00
|
|
|
dbname_ = test::PerThreadDBPath("options_util_test");
|
2015-11-13 01:52:51 +01: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 15:52:43 +01:00
|
|
|
|
|
|
|
protected:
|
2020-10-15 07:27:12 +02:00
|
|
|
std::unique_ptr<Env> env_;
|
2015-11-13 01:52:51 +01: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 15:52:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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 01:52:51 +01: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 15:52:43 +01:00
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
cf_names.push_back(i == 0 ? kDefaultColumnFamilyName
|
2015-11-13 01:52:51 +01: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 15:52:43 +01:00
|
|
|
cf_opts.emplace_back();
|
2019-06-04 04:47:02 +02:00
|
|
|
test::RandomInitCFOptions(&cf_opts.back(), 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 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string kFileName = "OPTIONS-123456";
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(PersistRocksDBOptions(db_opt, cf_names, cf_opts, kFileName,
|
|
|
|
env_->GetFileSystem().get()));
|
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 15:52:43 +01:00
|
|
|
|
|
|
|
DBOptions loaded_db_opt;
|
|
|
|
std::vector<ColumnFamilyDescriptor> loaded_cf_descs;
|
|
|
|
ASSERT_OK(LoadOptionsFromFile(kFileName, env_.get(), &loaded_db_opt,
|
|
|
|
&loaded_cf_descs));
|
2020-04-22 02:35:28 +02:00
|
|
|
ConfigOptions exact;
|
|
|
|
exact.sanity_level = ConfigOptions::kSanityLevelExactMatch;
|
|
|
|
ASSERT_OK(
|
|
|
|
RocksDBOptionsParser::VerifyDBOptions(exact, db_opt, loaded_db_opt));
|
2015-11-13 01:52:51 +01:00
|
|
|
test::RandomInitDBOptions(&db_opt, &rnd_);
|
2020-04-22 02:35:28 +02:00
|
|
|
ASSERT_NOK(
|
|
|
|
RocksDBOptionsParser::VerifyDBOptions(exact, db_opt, loaded_db_opt));
|
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 15:52:43 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < kCFCount; ++i) {
|
|
|
|
ASSERT_EQ(cf_names[i], loaded_cf_descs[i].name);
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(
|
2020-04-22 02:35:28 +02:00
|
|
|
exact, cf_opts[i], loaded_cf_descs[i].options));
|
2020-09-15 01:59:00 +02:00
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyTableFactory(
|
|
|
|
exact, cf_opts[i].table_factory.get(),
|
|
|
|
loaded_cf_descs[i].options.table_factory.get()));
|
2019-06-04 04:47:02 +02:00
|
|
|
test::RandomInitCFOptions(&cf_opts[i], 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 15:52:43 +01:00
|
|
|
ASSERT_NOK(RocksDBOptionsParser::VerifyCFOptions(
|
2020-04-22 02:35:28 +02:00
|
|
|
exact, cf_opts[i], loaded_cf_descs[i].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 15:52:43 +01:00
|
|
|
}
|
2015-11-12 23:12:27 +01:00
|
|
|
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, Options(db_opt, cf_opts[0])));
|
2015-11-12 23:12:27 +01: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 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 00:16:40 +01:00
|
|
|
TEST_F(OptionsUtilTest, SaveAndLoadWithCacheCheck) {
|
|
|
|
// creating db
|
|
|
|
DBOptions db_opt;
|
|
|
|
db_opt.create_if_missing = true;
|
|
|
|
// initialize BlockBasedTableOptions
|
|
|
|
std::shared_ptr<Cache> cache = NewLRUCache(1 * 1024);
|
|
|
|
BlockBasedTableOptions bbt_opts;
|
|
|
|
bbt_opts.block_size = 32 * 1024;
|
|
|
|
// saving cf options
|
|
|
|
std::vector<ColumnFamilyOptions> cf_opts;
|
|
|
|
ColumnFamilyOptions default_column_family_opt = ColumnFamilyOptions();
|
|
|
|
default_column_family_opt.table_factory.reset(
|
|
|
|
NewBlockBasedTableFactory(bbt_opts));
|
|
|
|
cf_opts.push_back(default_column_family_opt);
|
|
|
|
|
|
|
|
ColumnFamilyOptions cf_opt_sample = ColumnFamilyOptions();
|
|
|
|
cf_opt_sample.table_factory.reset(NewBlockBasedTableFactory(bbt_opts));
|
|
|
|
cf_opts.push_back(cf_opt_sample);
|
|
|
|
|
|
|
|
ColumnFamilyOptions cf_opt_plain_table_opt = ColumnFamilyOptions();
|
|
|
|
cf_opt_plain_table_opt.table_factory.reset(NewPlainTableFactory());
|
|
|
|
cf_opts.push_back(cf_opt_plain_table_opt);
|
|
|
|
|
|
|
|
std::vector<std::string> cf_names;
|
|
|
|
cf_names.push_back(kDefaultColumnFamilyName);
|
|
|
|
cf_names.push_back("cf_sample");
|
|
|
|
cf_names.push_back("cf_plain_table_sample");
|
|
|
|
// Saving DB in file
|
|
|
|
const std::string kFileName = "OPTIONS-LOAD_CACHE_123456";
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(PersistRocksDBOptions(db_opt, cf_names, cf_opts, kFileName,
|
|
|
|
env_->GetFileSystem().get()));
|
2019-03-22 00:16:40 +01:00
|
|
|
DBOptions loaded_db_opt;
|
|
|
|
std::vector<ColumnFamilyDescriptor> loaded_cf_descs;
|
2020-04-22 02:35:28 +02:00
|
|
|
|
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
config_options.input_strings_escaped = true;
|
|
|
|
config_options.env = env_.get();
|
|
|
|
ASSERT_OK(LoadOptionsFromFile(config_options, kFileName, &loaded_db_opt,
|
|
|
|
&loaded_cf_descs, &cache));
|
|
|
|
for (size_t i = 0; i < loaded_cf_descs.size(); i++) {
|
2020-09-15 01:59:00 +02:00
|
|
|
auto* loaded_bbt_opt =
|
|
|
|
loaded_cf_descs[i]
|
|
|
|
.options.table_factory->GetOptions<BlockBasedTableOptions>();
|
|
|
|
// Expect the same cache will be loaded
|
|
|
|
if (loaded_bbt_opt != nullptr) {
|
|
|
|
ASSERT_EQ(loaded_bbt_opt->block_cache.get(), cache.get());
|
2020-04-22 02:35:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the old interface
|
2019-03-22 00:16:40 +01:00
|
|
|
ASSERT_OK(LoadOptionsFromFile(kFileName, env_.get(), &loaded_db_opt,
|
|
|
|
&loaded_cf_descs, false, &cache));
|
|
|
|
for (size_t i = 0; i < loaded_cf_descs.size(); i++) {
|
2020-09-15 01:59:00 +02:00
|
|
|
auto* loaded_bbt_opt =
|
|
|
|
loaded_cf_descs[i]
|
|
|
|
.options.table_factory->GetOptions<BlockBasedTableOptions>();
|
|
|
|
// Expect the same cache will be loaded
|
|
|
|
if (loaded_bbt_opt != nullptr) {
|
|
|
|
ASSERT_EQ(loaded_bbt_opt->block_cache.get(), cache.get());
|
2019-03-22 00:16:40 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, Options(loaded_db_opt, cf_opts[0])));
|
2019-03-22 00:16:40 +01:00
|
|
|
}
|
|
|
|
|
2015-11-13 01:52:51 +01:00
|
|
|
namespace {
|
|
|
|
class DummyTableFactory : public TableFactory {
|
|
|
|
public:
|
|
|
|
DummyTableFactory() {}
|
2019-02-14 22:52:47 +01:00
|
|
|
~DummyTableFactory() override {}
|
2015-11-13 01:52:51 +01:00
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
const char* Name() const override { return "DummyTableFactory"; }
|
2015-11-13 01:52:51 +01:00
|
|
|
|
2020-06-29 23:51:57 +02:00
|
|
|
using TableFactory::NewTableReader;
|
2019-02-14 22:52:47 +01:00
|
|
|
Status NewTableReader(
|
2020-06-29 23:51:57 +02:00
|
|
|
const ReadOptions& /*ro*/,
|
2018-03-05 22:08:17 +01:00
|
|
|
const TableReaderOptions& /*table_reader_options*/,
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<RandomAccessFileReader>&& /*file*/,
|
|
|
|
uint64_t /*file_size*/, std::unique_ptr<TableReader>* /*table_reader*/,
|
2018-03-05 22:08:17 +01:00
|
|
|
bool /*prefetch_index_and_filter_in_cache*/) const override {
|
2015-11-13 01:52:51 +01:00
|
|
|
return Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
TableBuilder* NewTableBuilder(
|
2018-03-05 22:08:17 +01:00
|
|
|
const TableBuilderOptions& /*table_builder_options*/,
|
|
|
|
WritableFileWriter* /*file*/) const override {
|
2015-11-13 01:52:51 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-09-15 01:59:00 +02:00
|
|
|
Status ValidateOptions(
|
2018-03-05 22:08:17 +01:00
|
|
|
const DBOptions& /*db_opts*/,
|
|
|
|
const ColumnFamilyOptions& /*cf_opts*/) const override {
|
2015-11-13 01:52:51 +01:00
|
|
|
return Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
2020-09-15 01:59:00 +02:00
|
|
|
std::string GetPrintableOptions() const override { return ""; }
|
2015-11-13 01:52:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DummyMergeOperator : public MergeOperator {
|
|
|
|
public:
|
|
|
|
DummyMergeOperator() {}
|
2019-02-14 22:52:47 +01:00
|
|
|
~DummyMergeOperator() override {}
|
2015-11-13 01:52:51 +01:00
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
bool FullMergeV2(const MergeOperationInput& /*merge_in*/,
|
|
|
|
MergeOperationOutput* /*merge_out*/) const override {
|
2015-11-13 01:52:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
bool PartialMergeMulti(const Slice& /*key*/,
|
|
|
|
const std::deque<Slice>& /*operand_list*/,
|
|
|
|
std::string* /*new_value*/,
|
|
|
|
Logger* /*logger*/) const override {
|
2015-11-13 01:52:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
const char* Name() const override { return "DummyMergeOperator"; }
|
2015-11-13 01:52:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DummySliceTransform : public SliceTransform {
|
|
|
|
public:
|
|
|
|
DummySliceTransform() {}
|
2019-02-14 22:52:47 +01:00
|
|
|
~DummySliceTransform() override {}
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
// Return the name of this transformation.
|
2019-02-14 22:52:47 +01:00
|
|
|
const char* Name() const override { return "DummySliceTransform"; }
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
// transform a src in domain to a dst in the range
|
2019-02-14 22:52:47 +01:00
|
|
|
Slice Transform(const Slice& src) const override { return src; }
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
// determine whether this is a valid src upon the function applies
|
2019-02-14 22:52:47 +01:00
|
|
|
bool InDomain(const Slice& /*src*/) const override { return false; }
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
// determine whether dst=Transform(src) for some src
|
2019-02-14 22:52:47 +01:00
|
|
|
bool InRange(const Slice& /*dst*/) const override { return false; }
|
2015-11-13 01:52:51 +01: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 23:42:24 +01:00
|
|
|
// Assign non-null values to prefix_extractors except the first cf.
|
2015-11-13 01:52:51 +01:00
|
|
|
cf_descs.back().options.prefix_extractor.reset(
|
2016-02-19 23:42:24 +01:00
|
|
|
i != 0 ? test::RandomSliceTransform(&rnd_) : nullptr);
|
2015-11-13 01:52:51 +01:00
|
|
|
cf_descs.back().options.merge_operator.reset(
|
|
|
|
test::RandomMergeOperator(&rnd_));
|
|
|
|
}
|
|
|
|
|
|
|
|
db_opt.create_missing_column_families = true;
|
|
|
|
db_opt.create_if_missing = true;
|
|
|
|
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, Options(db_opt, cf_descs[0].options)));
|
2015-11-13 01:52:51 +01:00
|
|
|
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;
|
|
|
|
|
2020-04-22 02:35:28 +02:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
config_options.input_strings_escaped = true;
|
|
|
|
config_options.sanity_level = ConfigOptions::kSanityLevelLooselyCompatible;
|
2015-11-13 01:52:51 +01:00
|
|
|
// perform sanity check
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
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(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[0].options.merge_operator.reset(new DummyMergeOperator());
|
|
|
|
ASSERT_NOK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[0].options.merge_operator = merge_op;
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// prefix extractor
|
|
|
|
{
|
|
|
|
std::shared_ptr<const SliceTransform> prefix_extractor =
|
|
|
|
cf_descs[1].options.prefix_extractor;
|
|
|
|
|
2016-02-19 23:42:24 +01:00
|
|
|
// It's okay to set prefix_extractor to nullptr.
|
2015-11-13 01:52:51 +01:00
|
|
|
ASSERT_NE(prefix_extractor, nullptr);
|
|
|
|
cf_descs[1].options.prefix_extractor.reset();
|
2016-02-19 23:42:24 +01:00
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[1].options.prefix_extractor.reset(new DummySliceTransform());
|
2017-06-23 01:16:19 +02:00
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[1].options.prefix_extractor = prefix_extractor;
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 23:42:24 +01: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(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2016-02-19 23:42:24 +01:00
|
|
|
|
|
|
|
// It's okay to change prefix_extractor from nullptr to non-nullptr
|
|
|
|
cf_descs[0].options.prefix_extractor.reset(new DummySliceTransform());
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2016-02-19 23:42:24 +01:00
|
|
|
|
|
|
|
cf_descs[0].options.prefix_extractor = prefix_extractor;
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2016-02-19 23:42:24 +01:00
|
|
|
}
|
|
|
|
|
2015-11-13 01:52:51 +01:00
|
|
|
// comparator
|
|
|
|
{
|
|
|
|
test::SimpleSuffixReverseComparator comparator;
|
|
|
|
|
|
|
|
auto* prev_comparator = cf_descs[2].options.comparator;
|
|
|
|
cf_descs[2].options.comparator = &comparator;
|
|
|
|
ASSERT_NOK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[2].options.comparator = prev_comparator;
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
|
|
|
|
cf_descs[3].options.table_factory = table_factory;
|
|
|
|
ASSERT_OK(
|
2020-04-22 02:35:28 +02:00
|
|
|
CheckOptionsCompatibility(config_options, dbname_, db_opt, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
}
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, Options(db_opt, cf_descs[0].options)));
|
2020-10-15 07:27:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, LatestOptionsNotFound) {
|
|
|
|
std::unique_ptr<Env> env(NewMemEnv(Env::Default()));
|
|
|
|
Status s;
|
|
|
|
Options options;
|
|
|
|
ConfigOptions config_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
|
|
|
|
options.env = env.get();
|
|
|
|
options.create_if_missing = true;
|
|
|
|
config_opts.env = options.env;
|
|
|
|
config_opts.ignore_unknown_options = false;
|
|
|
|
|
|
|
|
std::vector<std::string> children;
|
|
|
|
|
|
|
|
std::string options_file_name;
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
2020-10-15 07:27:12 +02:00
|
|
|
// First, test where the db directory does not exist
|
|
|
|
ASSERT_NOK(options.env->GetChildren(dbname_, &children));
|
|
|
|
|
|
|
|
s = GetLatestOptionsFileName(dbname_, options.env, &options_file_name);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
s = LoadLatestOptions(dbname_, options.env, &options, &cf_descs);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &options, &cf_descs);
|
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
s = GetLatestOptionsFileName(dbname_, options.env, &options_file_name);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
// Second, test where the db directory exists but is empty
|
|
|
|
ASSERT_OK(options.env->CreateDir(dbname_));
|
|
|
|
|
|
|
|
s = GetLatestOptionsFileName(dbname_, options.env, &options_file_name);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
s = LoadLatestOptions(dbname_, options.env, &options, &cf_descs);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
// Finally, test where a file exists but is not an "Options" file
|
|
|
|
std::unique_ptr<WritableFile> file;
|
|
|
|
ASSERT_OK(
|
|
|
|
options.env->NewWritableFile(dbname_ + "/temp.txt", &file, EnvOptions()));
|
|
|
|
ASSERT_OK(file->Close());
|
|
|
|
s = GetLatestOptionsFileName(dbname_, options.env, &options_file_name);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &options, &cf_descs);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsNotFound());
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_TRUE(s.IsPathNotFound());
|
|
|
|
ASSERT_OK(options.env->DeleteFile(dbname_ + "/temp.txt"));
|
|
|
|
ASSERT_OK(options.env->DeleteDir(dbname_));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, LoadLatestOptions) {
|
|
|
|
Options options;
|
|
|
|
options.OptimizeForSmallDb();
|
|
|
|
ColumnFamilyDescriptor cf_desc;
|
|
|
|
ConfigOptions config_opts;
|
|
|
|
DBOptions db_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
DB* db;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
2020-10-15 07:27:12 +02:00
|
|
|
|
|
|
|
cf_descs.emplace_back();
|
|
|
|
cf_descs.back().name = kDefaultColumnFamilyName;
|
|
|
|
cf_descs.back().options.table_factory.reset(NewBlockBasedTableFactory());
|
|
|
|
cf_descs.emplace_back();
|
|
|
|
cf_descs.back().name = "Plain";
|
|
|
|
cf_descs.back().options.table_factory.reset(NewPlainTableFactory());
|
|
|
|
db_opts.create_missing_column_families = true;
|
|
|
|
db_opts.create_if_missing = true;
|
|
|
|
|
|
|
|
// open and persist the options
|
|
|
|
ASSERT_OK(DB::Open(db_opts, dbname_, cf_descs, &handles, &db));
|
|
|
|
|
|
|
|
std::string options_file_name;
|
|
|
|
std::string new_options_file;
|
|
|
|
|
|
|
|
ASSERT_OK(GetLatestOptionsFileName(dbname_, options.env, &options_file_name));
|
|
|
|
ASSERT_OK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(cf_descs.size(), 2U);
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(config_opts,
|
|
|
|
db->GetDBOptions(), db_opts));
|
|
|
|
ASSERT_OK(handles[0]->GetDescriptor(&cf_desc));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(config_opts, cf_desc.options,
|
|
|
|
cf_descs[0].options));
|
|
|
|
ASSERT_OK(handles[1]->GetDescriptor(&cf_desc));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(config_opts, cf_desc.options,
|
|
|
|
cf_descs[1].options));
|
|
|
|
|
|
|
|
// Now change some of the DBOptions
|
|
|
|
ASSERT_OK(db->SetDBOptions(
|
|
|
|
{{"delayed_write_rate", "1234"}, {"bytes_per_sync", "32768"}}));
|
|
|
|
ASSERT_OK(GetLatestOptionsFileName(dbname_, options.env, &new_options_file));
|
|
|
|
ASSERT_NE(options_file_name, new_options_file);
|
|
|
|
ASSERT_OK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(config_opts,
|
|
|
|
db->GetDBOptions(), db_opts));
|
|
|
|
options_file_name = new_options_file;
|
|
|
|
|
|
|
|
// Now change some of the ColumnFamilyOptions
|
|
|
|
ASSERT_OK(db->SetOptions(handles[1], {{"write_buffer_size", "32768"}}));
|
|
|
|
ASSERT_OK(GetLatestOptionsFileName(dbname_, options.env, &new_options_file));
|
|
|
|
ASSERT_NE(options_file_name, new_options_file);
|
|
|
|
ASSERT_OK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(config_opts,
|
|
|
|
db->GetDBOptions(), db_opts));
|
|
|
|
ASSERT_OK(handles[0]->GetDescriptor(&cf_desc));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(config_opts, cf_desc.options,
|
|
|
|
cf_descs[0].options));
|
|
|
|
ASSERT_OK(handles[1]->GetDescriptor(&cf_desc));
|
|
|
|
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(config_opts, cf_desc.options,
|
|
|
|
cf_descs[1].options));
|
|
|
|
|
|
|
|
// close the db
|
|
|
|
for (auto* handle : handles) {
|
|
|
|
delete handle;
|
|
|
|
}
|
|
|
|
delete db;
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(DestroyDB(dbname_, options, cf_descs));
|
2015-11-13 01:52:51 +01:00
|
|
|
}
|
|
|
|
|
2020-10-15 07:27:12 +02:00
|
|
|
static void WriteOptionsFile(Env* env, const std::string& path,
|
|
|
|
const std::string& options_file, int major,
|
|
|
|
int minor, const std::string& db_opts,
|
2020-10-30 02:43:03 +01:00
|
|
|
const std::string& cf_opts,
|
|
|
|
const std::string& bbt_opts = "") {
|
2020-10-15 07:27:12 +02:00
|
|
|
std::string options_file_header =
|
|
|
|
"\n"
|
|
|
|
"[Version]\n"
|
|
|
|
" rocksdb_version=" +
|
2022-05-06 22:03:58 +02:00
|
|
|
std::to_string(major) + "." + std::to_string(minor) +
|
2020-10-15 07:27:12 +02:00
|
|
|
".0\n"
|
|
|
|
" options_file_version=1\n";
|
|
|
|
|
|
|
|
std::unique_ptr<WritableFile> wf;
|
|
|
|
ASSERT_OK(env->NewWritableFile(path + "/" + options_file, &wf, EnvOptions()));
|
|
|
|
ASSERT_OK(
|
|
|
|
wf->Append(options_file_header + "[ DBOptions ]\n" + db_opts + "\n"));
|
|
|
|
ASSERT_OK(wf->Append(
|
|
|
|
"[CFOptions \"default\"] # column family must be specified\n" +
|
|
|
|
cf_opts + "\n"));
|
2020-10-30 02:43:03 +01:00
|
|
|
ASSERT_OK(wf->Append("[TableOptions/BlockBasedTable \"default\"]\n" +
|
|
|
|
bbt_opts + "\n"));
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(wf->Close());
|
|
|
|
|
|
|
|
std::string latest_options_file;
|
|
|
|
ASSERT_OK(GetLatestOptionsFileName(path, env, &latest_options_file));
|
|
|
|
ASSERT_EQ(latest_options_file, options_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, BadLatestOptions) {
|
|
|
|
Status s;
|
|
|
|
ConfigOptions config_opts;
|
|
|
|
DBOptions db_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
Options options;
|
|
|
|
options.env = env_.get();
|
|
|
|
config_opts.env = env_.get();
|
|
|
|
config_opts.ignore_unknown_options = false;
|
|
|
|
config_opts.delimiter = "\n";
|
|
|
|
|
|
|
|
ConfigOptions ignore_opts = config_opts;
|
|
|
|
ignore_opts.ignore_unknown_options = true;
|
|
|
|
|
|
|
|
std::string options_file_name;
|
|
|
|
|
|
|
|
// Test where the db directory exists but is empty
|
|
|
|
ASSERT_OK(options.env->CreateDir(dbname_));
|
|
|
|
ASSERT_NOK(
|
|
|
|
GetLatestOptionsFileName(dbname_, options.env, &options_file_name));
|
|
|
|
ASSERT_NOK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
|
|
|
|
// Write an options file for a previous major release with an unknown DB
|
|
|
|
// Option
|
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0001", ROCKSDB_MAJOR - 1,
|
|
|
|
ROCKSDB_MINOR, "unknown_db_opt=true", "");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-29 21:45:17 +01:00
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-15 07:27:12 +02:00
|
|
|
// Write an options file for a previous minor release with an unknown CF
|
|
|
|
// Option
|
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0002", ROCKSDB_MAJOR,
|
|
|
|
ROCKSDB_MINOR - 1, "", "unknown_cf_opt=true");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-29 21:45:17 +01:00
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-30 02:43:03 +01:00
|
|
|
// Write an options file for a previous minor release with an unknown BBT
|
|
|
|
// Option
|
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0003", ROCKSDB_MAJOR,
|
|
|
|
ROCKSDB_MINOR - 1, "", "", "unknown_bbt_opt=true");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-15 07:27:12 +02:00
|
|
|
|
|
|
|
// Write an options file for the current release with an unknown DB Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0004", ROCKSDB_MAJOR,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR, "unknown_db_opt=true", "");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-29 21:45:17 +01:00
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-15 07:27:12 +02:00
|
|
|
|
|
|
|
// Write an options file for the current release with an unknown CF Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0005", ROCKSDB_MAJOR,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR, "", "unknown_cf_opt=true");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
2020-10-20 20:51:51 +02:00
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-29 21:45:17 +01:00
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-15 07:27:12 +02:00
|
|
|
|
|
|
|
// Write an options file for the current release with an invalid DB Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0006", ROCKSDB_MAJOR,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR, "create_if_missing=hello", "");
|
|
|
|
s = LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-29 21:45:17 +01:00
|
|
|
// Even though ignore_unknown_options=true, we still return an error...
|
|
|
|
s = LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs);
|
|
|
|
ASSERT_NOK(s);
|
|
|
|
ASSERT_TRUE(s.IsInvalidArgument());
|
2020-10-15 07:27:12 +02:00
|
|
|
|
|
|
|
// Write an options file for the next release with an invalid DB Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0007", ROCKSDB_MAJOR,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR + 1, "create_if_missing=hello", "");
|
2020-10-29 21:45:17 +01:00
|
|
|
ASSERT_NOK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
|
|
|
|
// Write an options file for the next release with an unknown DB Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0008", ROCKSDB_MAJOR,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR + 1, "unknown_db_opt=true", "");
|
2020-10-29 21:45:17 +01:00
|
|
|
ASSERT_NOK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
// Ignore the errors for future releases when ignore_unknown_options=true
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
|
|
|
|
// Write an options file for the next major release with an unknown CF Option
|
2020-10-30 02:43:03 +01:00
|
|
|
WriteOptionsFile(options.env, dbname_, "OPTIONS-0009", ROCKSDB_MAJOR + 1,
|
2020-10-15 07:27:12 +02:00
|
|
|
ROCKSDB_MINOR, "", "unknown_cf_opt=true");
|
2020-10-29 21:45:17 +01:00
|
|
|
ASSERT_NOK(LoadLatestOptions(config_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
// Ignore the errors for future releases when ignore_unknown_options=true
|
2020-10-15 07:27:12 +02:00
|
|
|
ASSERT_OK(LoadLatestOptions(ignore_opts, dbname_, &db_opts, &cf_descs));
|
|
|
|
}
|
2021-07-30 21:15:04 +02:00
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, RenameDatabaseDirectory) {
|
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
DBOptions db_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
|
|
|
|
options.create_if_missing = true;
|
|
|
|
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
ASSERT_OK(db->Put(WriteOptions(), "foo", "value0"));
|
|
|
|
delete db;
|
|
|
|
|
|
|
|
auto new_dbname = dbname_ + "_2";
|
|
|
|
|
|
|
|
ASSERT_OK(options.env->RenameFile(dbname_, new_dbname));
|
|
|
|
ASSERT_OK(LoadLatestOptions(new_dbname, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(cf_descs.size(), 1U);
|
|
|
|
|
|
|
|
db_opts.create_if_missing = false;
|
|
|
|
ASSERT_OK(DB::Open(db_opts, new_dbname, cf_descs, &handles, &db));
|
|
|
|
std::string value;
|
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "foo", &value));
|
|
|
|
ASSERT_EQ("value0", value);
|
|
|
|
// close the db
|
|
|
|
for (auto* handle : handles) {
|
|
|
|
delete handle;
|
|
|
|
}
|
|
|
|
delete db;
|
|
|
|
Options new_options(db_opts, cf_descs[0].options);
|
|
|
|
ASSERT_OK(DestroyDB(new_dbname, new_options, cf_descs));
|
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, WalDirSettings) {
|
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
DBOptions db_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
|
|
|
|
options.create_if_missing = true;
|
|
|
|
|
|
|
|
// Open a DB with no wal dir set. The wal_dir should stay empty
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, "");
|
|
|
|
|
|
|
|
// Open a DB with wal_dir == dbname. The wal_dir should be set to empty
|
|
|
|
options.wal_dir = dbname_;
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, "");
|
|
|
|
|
|
|
|
// Open a DB with no wal_dir but a db_path==dbname_. The wal_dir should be
|
|
|
|
// empty
|
|
|
|
options.wal_dir = "";
|
|
|
|
options.db_paths.emplace_back(dbname_, std::numeric_limits<uint64_t>::max());
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, "");
|
|
|
|
|
|
|
|
// Open a DB with no wal_dir==dbname_ and db_path==dbname_. The wal_dir
|
|
|
|
// should be empty
|
|
|
|
options.wal_dir = dbname_ + "/";
|
|
|
|
options.db_paths.emplace_back(dbname_, std::numeric_limits<uint64_t>::max());
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, "");
|
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
|
|
|
|
|
|
|
// Open a DB with no wal_dir but db_path != db_name. The wal_dir == dbname_
|
|
|
|
options.wal_dir = "";
|
|
|
|
options.db_paths.clear();
|
|
|
|
options.db_paths.emplace_back(dbname_ + "_0",
|
|
|
|
std::numeric_limits<uint64_t>::max());
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, dbname_);
|
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
|
|
|
|
|
|
|
// Open a DB with wal_dir != db_name. The wal_dir remains unchanged
|
|
|
|
options.wal_dir = dbname_ + "/wal";
|
|
|
|
options.db_paths.clear();
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, dbname_ + "/wal");
|
|
|
|
ASSERT_OK(DestroyDB(dbname_, options));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptionsUtilTest, WalDirInOptins) {
|
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
DBOptions db_opts;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
|
|
|
|
// Store an options file with wal_dir=dbname_ and make sure it still loads
|
|
|
|
// when the input wal_dir is empty
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.wal_dir = "";
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
options.wal_dir = dbname_;
|
|
|
|
std::string options_file;
|
|
|
|
ASSERT_OK(GetLatestOptionsFileName(dbname_, options.env, &options_file));
|
|
|
|
ASSERT_OK(PersistRocksDBOptions(options, {"default"}, {options},
|
|
|
|
dbname_ + "/" + options_file,
|
|
|
|
options.env->GetFileSystem().get()));
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, dbname_);
|
|
|
|
options.wal_dir = "";
|
|
|
|
ASSERT_OK(DB::Open(options, dbname_, &db));
|
|
|
|
delete db;
|
|
|
|
ASSERT_OK(LoadLatestOptions(dbname_, options.env, &db_opts, &cf_descs));
|
|
|
|
ASSERT_EQ(db_opts.wal_dir, "");
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
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 15:52:43 +01:00
|
|
|
|
|
|
|
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 02:19:57 +02: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 15:52:43 +01:00
|
|
|
printf("Skipped in RocksDBLite as utilities are not supported.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|