2016-07-14 06:08:15 +02: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).
|
2016-07-14 06:08:15 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "rocksdb/utilities/option_change_migration.h"
|
2020-07-09 23:33:42 +02:00
|
|
|
|
2016-07-14 06:08:15 +02:00
|
|
|
#include <set>
|
2020-07-09 23:33:42 +02:00
|
|
|
|
2016-07-14 06:08:15 +02:00
|
|
|
#include "db/db_test_util.h"
|
|
|
|
#include "port/stack_trace.h"
|
2020-07-09 23:33:42 +02:00
|
|
|
#include "util/random.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2016-07-14 06:08:15 +02:00
|
|
|
|
2016-11-16 06:55:15 +01:00
|
|
|
class DBOptionChangeMigrationTests
|
2016-07-14 06:08:15 +02:00
|
|
|
: public DBTestBase,
|
|
|
|
public testing::WithParamInterface<
|
2016-10-24 22:16:54 +02:00
|
|
|
std::tuple<int, int, bool, int, int, bool>> {
|
2016-07-14 06:08:15 +02:00
|
|
|
public:
|
2016-11-16 06:55:15 +01:00
|
|
|
DBOptionChangeMigrationTests()
|
2021-07-23 17:37:27 +02:00
|
|
|
: DBTestBase("db_option_change_migration_test", /*env_do_fsync=*/true) {
|
2016-07-14 06:08:15 +02:00
|
|
|
level1_ = std::get<0>(GetParam());
|
2016-10-24 22:16:54 +02:00
|
|
|
compaction_style1_ = std::get<1>(GetParam());
|
2016-07-14 06:08:15 +02:00
|
|
|
is_dynamic1_ = std::get<2>(GetParam());
|
|
|
|
|
|
|
|
level2_ = std::get<3>(GetParam());
|
2016-10-24 22:16:54 +02:00
|
|
|
compaction_style2_ = std::get<4>(GetParam());
|
2016-07-14 06:08:15 +02:00
|
|
|
is_dynamic2_ = std::get<5>(GetParam());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Required if inheriting from testing::WithParamInterface<>
|
|
|
|
static void SetUpTestCase() {}
|
|
|
|
static void TearDownTestCase() {}
|
|
|
|
|
|
|
|
int level1_;
|
2016-10-24 22:16:54 +02:00
|
|
|
int compaction_style1_;
|
2016-07-14 06:08:15 +02:00
|
|
|
bool is_dynamic1_;
|
|
|
|
|
|
|
|
int level2_;
|
2016-10-24 22:16:54 +02:00
|
|
|
int compaction_style2_;
|
2016-07-14 06:08:15 +02:00
|
|
|
bool is_dynamic2_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2016-11-16 06:55:15 +01:00
|
|
|
TEST_P(DBOptionChangeMigrationTests, Migrate1) {
|
2016-07-14 06:08:15 +02:00
|
|
|
Options old_options = CurrentOptions();
|
2016-10-24 22:16:54 +02:00
|
|
|
old_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style1_);
|
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
2016-07-14 06:08:15 +02:00
|
|
|
old_options.level_compaction_dynamic_level_bytes = is_dynamic1_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
old_options.max_open_files = -1;
|
|
|
|
}
|
2016-07-14 06:08:15 +02:00
|
|
|
old_options.level0_file_num_compaction_trigger = 3;
|
|
|
|
old_options.write_buffer_size = 64 * 1024;
|
|
|
|
old_options.target_file_size_base = 128 * 1024;
|
|
|
|
// Make level target of L1, L2 to be 200KB and 600KB
|
|
|
|
old_options.num_levels = level1_;
|
|
|
|
old_options.max_bytes_for_level_multiplier = 3;
|
|
|
|
old_options.max_bytes_for_level_base = 200 * 1024;
|
|
|
|
|
|
|
|
Reopen(old_options);
|
|
|
|
|
|
|
|
Random rnd(301);
|
|
|
|
int key_idx = 0;
|
|
|
|
|
|
|
|
// Generate at least 2MB of data
|
|
|
|
for (int num = 0; num < 20; num++) {
|
|
|
|
GenerateNewFile(&rnd, &key_idx);
|
|
|
|
}
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-07-14 06:08:15 +02:00
|
|
|
|
|
|
|
// Will make sure exactly those keys are in the DB after migration.
|
|
|
|
std::set<std::string> keys;
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (; it->Valid(); it->Next()) {
|
|
|
|
keys.insert(it->key().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Close();
|
|
|
|
|
|
|
|
Options new_options = old_options;
|
2016-10-24 22:16:54 +02:00
|
|
|
new_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style2_);
|
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
2016-07-14 06:08:15 +02:00
|
|
|
new_options.level_compaction_dynamic_level_bytes = is_dynamic2_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
new_options.max_open_files = -1;
|
|
|
|
}
|
2016-07-14 06:08:15 +02:00
|
|
|
new_options.target_file_size_base = 256 * 1024;
|
|
|
|
new_options.num_levels = level2_;
|
|
|
|
new_options.max_bytes_for_level_base = 150 * 1024;
|
|
|
|
new_options.max_bytes_for_level_multiplier = 4;
|
|
|
|
ASSERT_OK(OptionChangeMigration(dbname_, old_options, new_options));
|
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
// Wait for compaction to finish and make sure it can reopen
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-07-14 06:08:15 +02:00
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (std::string key : keys) {
|
|
|
|
ASSERT_TRUE(it->Valid());
|
|
|
|
ASSERT_EQ(key, it->key().ToString());
|
|
|
|
it->Next();
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(!it->Valid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 06:55:15 +01:00
|
|
|
TEST_P(DBOptionChangeMigrationTests, Migrate2) {
|
2016-07-14 06:08:15 +02:00
|
|
|
Options old_options = CurrentOptions();
|
2016-10-24 22:16:54 +02:00
|
|
|
old_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style2_);
|
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
2016-07-14 06:08:15 +02:00
|
|
|
old_options.level_compaction_dynamic_level_bytes = is_dynamic2_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
old_options.max_open_files = -1;
|
|
|
|
}
|
2016-07-14 06:08:15 +02:00
|
|
|
old_options.level0_file_num_compaction_trigger = 3;
|
|
|
|
old_options.write_buffer_size = 64 * 1024;
|
|
|
|
old_options.target_file_size_base = 128 * 1024;
|
|
|
|
// Make level target of L1, L2 to be 200KB and 600KB
|
|
|
|
old_options.num_levels = level2_;
|
|
|
|
old_options.max_bytes_for_level_multiplier = 3;
|
|
|
|
old_options.max_bytes_for_level_base = 200 * 1024;
|
|
|
|
|
|
|
|
Reopen(old_options);
|
|
|
|
|
|
|
|
Random rnd(301);
|
|
|
|
int key_idx = 0;
|
|
|
|
|
|
|
|
// Generate at least 2MB of data
|
|
|
|
for (int num = 0; num < 20; num++) {
|
|
|
|
GenerateNewFile(&rnd, &key_idx);
|
|
|
|
}
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-07-14 06:08:15 +02:00
|
|
|
|
|
|
|
// Will make sure exactly those keys are in the DB after migration.
|
|
|
|
std::set<std::string> keys;
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (; it->Valid(); it->Next()) {
|
|
|
|
keys.insert(it->key().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
Options new_options = old_options;
|
2016-10-24 22:16:54 +02:00
|
|
|
new_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style1_);
|
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
2016-07-14 06:08:15 +02:00
|
|
|
new_options.level_compaction_dynamic_level_bytes = is_dynamic1_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
new_options.max_open_files = -1;
|
|
|
|
}
|
2016-07-14 06:08:15 +02:00
|
|
|
new_options.target_file_size_base = 256 * 1024;
|
|
|
|
new_options.num_levels = level1_;
|
|
|
|
new_options.max_bytes_for_level_base = 150 * 1024;
|
|
|
|
new_options.max_bytes_for_level_multiplier = 4;
|
|
|
|
ASSERT_OK(OptionChangeMigration(dbname_, old_options, new_options));
|
|
|
|
Reopen(new_options);
|
|
|
|
// Wait for compaction to finish and make sure it can reopen
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-07-14 06:08:15 +02:00
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (std::string key : keys) {
|
|
|
|
ASSERT_TRUE(it->Valid());
|
|
|
|
ASSERT_EQ(key, it->key().ToString());
|
|
|
|
it->Next();
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(!it->Valid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 06:55:15 +01:00
|
|
|
TEST_P(DBOptionChangeMigrationTests, Migrate3) {
|
|
|
|
Options old_options = CurrentOptions();
|
|
|
|
old_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style1_);
|
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
|
|
|
old_options.level_compaction_dynamic_level_bytes = is_dynamic1_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
old_options.max_open_files = -1;
|
|
|
|
}
|
2016-11-16 06:55:15 +01:00
|
|
|
old_options.level0_file_num_compaction_trigger = 3;
|
|
|
|
old_options.write_buffer_size = 64 * 1024;
|
|
|
|
old_options.target_file_size_base = 128 * 1024;
|
|
|
|
// Make level target of L1, L2 to be 200KB and 600KB
|
|
|
|
old_options.num_levels = level1_;
|
|
|
|
old_options.max_bytes_for_level_multiplier = 3;
|
|
|
|
old_options.max_bytes_for_level_base = 200 * 1024;
|
|
|
|
|
|
|
|
Reopen(old_options);
|
|
|
|
Random rnd(301);
|
|
|
|
for (int num = 0; num < 20; num++) {
|
|
|
|
for (int i = 0; i < 50; i++) {
|
2020-07-09 23:33:42 +02:00
|
|
|
ASSERT_OK(Put(Key(num * 100 + i), rnd.RandomString(900)));
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
Flush();
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
if (num == 9) {
|
|
|
|
// Issue a full compaction to generate some zero-out files
|
|
|
|
CompactRangeOptions cro;
|
|
|
|
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(cro, nullptr, nullptr));
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
|
|
|
|
// Will make sure exactly those keys are in the DB after migration.
|
|
|
|
std::set<std::string> keys;
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (; it->Valid(); it->Next()) {
|
|
|
|
keys.insert(it->key().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Close();
|
|
|
|
|
|
|
|
Options new_options = old_options;
|
|
|
|
new_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style2_);
|
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
|
|
|
new_options.level_compaction_dynamic_level_bytes = is_dynamic2_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
new_options.max_open_files = -1;
|
|
|
|
}
|
2016-11-16 06:55:15 +01:00
|
|
|
new_options.target_file_size_base = 256 * 1024;
|
|
|
|
new_options.num_levels = level2_;
|
|
|
|
new_options.max_bytes_for_level_base = 150 * 1024;
|
|
|
|
new_options.max_bytes_for_level_multiplier = 4;
|
|
|
|
ASSERT_OK(OptionChangeMigration(dbname_, old_options, new_options));
|
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
// Wait for compaction to finish and make sure it can reopen
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (std::string key : keys) {
|
|
|
|
ASSERT_TRUE(it->Valid());
|
|
|
|
ASSERT_EQ(key, it->key().ToString());
|
|
|
|
it->Next();
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(!it->Valid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DBOptionChangeMigrationTests, Migrate4) {
|
|
|
|
Options old_options = CurrentOptions();
|
|
|
|
old_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style2_);
|
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
|
|
|
old_options.level_compaction_dynamic_level_bytes = is_dynamic2_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (old_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
old_options.max_open_files = -1;
|
|
|
|
}
|
2016-11-16 06:55:15 +01:00
|
|
|
old_options.level0_file_num_compaction_trigger = 3;
|
|
|
|
old_options.write_buffer_size = 64 * 1024;
|
|
|
|
old_options.target_file_size_base = 128 * 1024;
|
|
|
|
// Make level target of L1, L2 to be 200KB and 600KB
|
|
|
|
old_options.num_levels = level2_;
|
|
|
|
old_options.max_bytes_for_level_multiplier = 3;
|
|
|
|
old_options.max_bytes_for_level_base = 200 * 1024;
|
|
|
|
|
|
|
|
Reopen(old_options);
|
|
|
|
Random rnd(301);
|
|
|
|
for (int num = 0; num < 20; num++) {
|
|
|
|
for (int i = 0; i < 50; i++) {
|
2020-07-09 23:33:42 +02:00
|
|
|
ASSERT_OK(Put(Key(num * 100 + i), rnd.RandomString(900)));
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
Flush();
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
if (num == 9) {
|
|
|
|
// Issue a full compaction to generate some zero-out files
|
|
|
|
CompactRangeOptions cro;
|
|
|
|
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(cro, nullptr, nullptr));
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
|
|
|
|
// Will make sure exactly those keys are in the DB after migration.
|
|
|
|
std::set<std::string> keys;
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (; it->Valid(); it->Next()) {
|
|
|
|
keys.insert(it->key().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
Options new_options = old_options;
|
|
|
|
new_options.compaction_style =
|
|
|
|
static_cast<CompactionStyle>(compaction_style1_);
|
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleLevel) {
|
|
|
|
new_options.level_compaction_dynamic_level_bytes = is_dynamic1_;
|
|
|
|
}
|
2021-04-14 21:03:56 +02:00
|
|
|
if (new_options.compaction_style == CompactionStyle::kCompactionStyleFIFO) {
|
|
|
|
new_options.max_open_files = -1;
|
|
|
|
}
|
2016-11-16 06:55:15 +01:00
|
|
|
new_options.target_file_size_base = 256 * 1024;
|
|
|
|
new_options.num_levels = level1_;
|
|
|
|
new_options.max_bytes_for_level_base = 150 * 1024;
|
|
|
|
new_options.max_bytes_for_level_multiplier = 4;
|
|
|
|
ASSERT_OK(OptionChangeMigration(dbname_, old_options, new_options));
|
|
|
|
Reopen(new_options);
|
|
|
|
// Wait for compaction to finish and make sure it can reopen
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (std::string key : keys) {
|
|
|
|
ASSERT_TRUE(it->Valid());
|
|
|
|
ASSERT_EQ(key, it->key().ToString());
|
|
|
|
it->Next();
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(!it->Valid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 00:53:09 +02:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2016-11-16 06:55:15 +01:00
|
|
|
DBOptionChangeMigrationTests, DBOptionChangeMigrationTests,
|
2016-10-24 22:16:54 +02:00
|
|
|
::testing::Values(std::make_tuple(3, 0, false, 4, 0, false),
|
|
|
|
std::make_tuple(3, 0, true, 4, 0, true),
|
|
|
|
std::make_tuple(3, 0, true, 4, 0, false),
|
|
|
|
std::make_tuple(3, 0, false, 4, 0, true),
|
|
|
|
std::make_tuple(3, 1, false, 4, 1, false),
|
|
|
|
std::make_tuple(1, 1, false, 4, 1, false),
|
|
|
|
std::make_tuple(3, 0, false, 4, 1, false),
|
|
|
|
std::make_tuple(3, 0, false, 1, 1, false),
|
|
|
|
std::make_tuple(3, 0, true, 4, 1, false),
|
|
|
|
std::make_tuple(3, 0, true, 1, 1, false),
|
|
|
|
std::make_tuple(1, 1, false, 4, 0, false),
|
|
|
|
std::make_tuple(4, 0, false, 1, 2, false),
|
|
|
|
std::make_tuple(3, 0, true, 2, 2, false),
|
|
|
|
std::make_tuple(3, 1, false, 3, 2, false),
|
|
|
|
std::make_tuple(1, 1, false, 4, 2, false)));
|
2016-07-14 06:08:15 +02:00
|
|
|
|
2016-11-16 06:55:15 +01:00
|
|
|
class DBOptionChangeMigrationTest : public DBTestBase {
|
|
|
|
public:
|
|
|
|
DBOptionChangeMigrationTest()
|
2021-07-23 17:37:27 +02:00
|
|
|
: DBTestBase("db_option_change_migration_test2", /*env_do_fsync=*/true) {}
|
2016-11-16 06:55:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DBOptionChangeMigrationTest, CompactedSrcToUniversal) {
|
|
|
|
Options old_options = CurrentOptions();
|
|
|
|
old_options.compaction_style = CompactionStyle::kCompactionStyleLevel;
|
|
|
|
old_options.max_compaction_bytes = 200 * 1024;
|
|
|
|
old_options.level_compaction_dynamic_level_bytes = false;
|
|
|
|
old_options.level0_file_num_compaction_trigger = 3;
|
|
|
|
old_options.write_buffer_size = 64 * 1024;
|
|
|
|
old_options.target_file_size_base = 128 * 1024;
|
|
|
|
// Make level target of L1, L2 to be 200KB and 600KB
|
|
|
|
old_options.num_levels = 4;
|
|
|
|
old_options.max_bytes_for_level_multiplier = 3;
|
|
|
|
old_options.max_bytes_for_level_base = 200 * 1024;
|
|
|
|
|
|
|
|
Reopen(old_options);
|
|
|
|
Random rnd(301);
|
|
|
|
for (int num = 0; num < 20; num++) {
|
|
|
|
for (int i = 0; i < 50; i++) {
|
2020-07-09 23:33:42 +02:00
|
|
|
ASSERT_OK(Put(Key(num * 100 + i), rnd.RandomString(900)));
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Flush();
|
|
|
|
CompactRangeOptions cro;
|
|
|
|
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(cro, nullptr, nullptr));
|
2016-11-16 06:55:15 +01:00
|
|
|
|
|
|
|
// Will make sure exactly those keys are in the DB after migration.
|
|
|
|
std::set<std::string> keys;
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (; it->Valid(); it->Next()) {
|
|
|
|
keys.insert(it->key().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
Options new_options = old_options;
|
|
|
|
new_options.compaction_style = CompactionStyle::kCompactionStyleUniversal;
|
|
|
|
new_options.target_file_size_base = 256 * 1024;
|
|
|
|
new_options.num_levels = 1;
|
|
|
|
new_options.max_bytes_for_level_base = 150 * 1024;
|
|
|
|
new_options.max_bytes_for_level_multiplier = 4;
|
|
|
|
ASSERT_OK(OptionChangeMigration(dbname_, old_options, new_options));
|
|
|
|
Reopen(new_options);
|
|
|
|
// Wait for compaction to finish and make sure it can reopen
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-11-16 06:55:15 +01:00
|
|
|
Reopen(new_options);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ReadOptions()));
|
|
|
|
it->SeekToFirst();
|
|
|
|
for (std::string key : keys) {
|
|
|
|
ASSERT_TRUE(it->Valid());
|
|
|
|
ASSERT_EQ(key, it->key().ToString());
|
|
|
|
it->Next();
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(!it->Valid());
|
2020-12-23 08:44:44 +01:00
|
|
|
ASSERT_OK(it->status());
|
2016-11-16 06:55:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 06:08:15 +02:00
|
|
|
#endif // ROCKSDB_LITE
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2016-07-14 06:08:15 +02:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2016-07-14 06:08:15 +02:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|