2016-07-13 00:30:38 +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-13 00:30:38 +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.
|
2016-08-03 06:55:26 +02:00
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
2016-09-15 07:10:28 +02:00
|
|
|
#include <unordered_map>
|
2016-08-03 06:55:26 +02:00
|
|
|
|
2016-09-15 07:10:28 +02:00
|
|
|
#include "db/column_family.h"
|
2019-05-31 20:52:59 +02:00
|
|
|
#include "db/db_impl/db_impl.h"
|
2019-06-01 00:21:36 +02:00
|
|
|
#include "db/db_test_util.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "options/options_helper.h"
|
2016-07-13 00:30:38 +02:00
|
|
|
#include "port/stack_trace.h"
|
2017-05-04 05:46:17 +02:00
|
|
|
#include "rocksdb/cache.h"
|
2016-09-15 07:10:28 +02:00
|
|
|
#include "rocksdb/convenience.h"
|
2017-05-24 18:52:08 +02:00
|
|
|
#include "rocksdb/rate_limiter.h"
|
2019-02-21 00:46:59 +01:00
|
|
|
#include "rocksdb/stats_history.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/sync_point.h"
|
|
|
|
#include "test_util/testutil.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/random.h"
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2016-07-13 00:30:38 +02:00
|
|
|
|
|
|
|
class DBOptionsTest : public DBTestBase {
|
|
|
|
public:
|
2021-07-23 17:37:27 +02:00
|
|
|
DBOptionsTest() : DBTestBase("db_options_test", /*env_do_fsync=*/true) {}
|
2016-09-15 07:10:28 +02:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2016-10-14 21:25:39 +02:00
|
|
|
std::unordered_map<std::string, std::string> GetMutableDBOptionsMap(
|
|
|
|
const DBOptions& options) {
|
|
|
|
std::string options_str;
|
2020-09-15 01:59:00 +02:00
|
|
|
std::unordered_map<std::string, std::string> mutable_map;
|
2021-05-11 15:45:49 +02:00
|
|
|
ConfigOptions config_options(options);
|
2020-04-22 02:35:28 +02:00
|
|
|
config_options.delimiter = "; ";
|
2020-09-15 01:59:00 +02:00
|
|
|
|
2020-09-17 00:45:30 +02:00
|
|
|
EXPECT_OK(GetStringFromMutableDBOptions(
|
|
|
|
config_options, MutableDBOptions(options), &options_str));
|
|
|
|
EXPECT_OK(StringToMap(options_str, &mutable_map));
|
|
|
|
|
2016-10-14 21:25:39 +02:00
|
|
|
return mutable_map;
|
|
|
|
}
|
|
|
|
|
2016-09-15 07:10:28 +02:00
|
|
|
std::unordered_map<std::string, std::string> GetMutableCFOptionsMap(
|
|
|
|
const ColumnFamilyOptions& options) {
|
|
|
|
std::string options_str;
|
2020-04-22 02:35:28 +02:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.delimiter = "; ";
|
|
|
|
|
2016-09-15 07:10:28 +02:00
|
|
|
std::unordered_map<std::string, std::string> mutable_map;
|
2020-09-17 00:45:30 +02:00
|
|
|
EXPECT_OK(GetStringFromMutableCFOptions(
|
|
|
|
config_options, MutableCFOptions(options), &options_str));
|
|
|
|
EXPECT_OK(StringToMap(options_str, &mutable_map));
|
2016-09-15 07:10:28 +02:00
|
|
|
return mutable_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> GetRandomizedMutableCFOptionsMap(
|
|
|
|
Random* rnd) {
|
2019-06-04 04:47:02 +02:00
|
|
|
Options options = CurrentOptions();
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-09-24 01:34:04 +02:00
|
|
|
ImmutableDBOptions db_options(options);
|
2019-06-04 04:47:02 +02:00
|
|
|
test::RandomInitCFOptions(&options, options, rnd);
|
2016-10-21 20:31:42 +02:00
|
|
|
auto sanitized_options = SanitizeOptions(db_options, options);
|
2016-09-15 23:57:32 +02:00
|
|
|
auto opt_map = GetMutableCFOptionsMap(sanitized_options);
|
|
|
|
delete options.compaction_filter;
|
|
|
|
return opt_map;
|
2016-09-15 07:10:28 +02:00
|
|
|
}
|
2016-10-14 21:25:39 +02:00
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> GetRandomizedMutableDBOptionsMap(
|
|
|
|
Random* rnd) {
|
|
|
|
DBOptions db_options;
|
|
|
|
test::RandomInitDBOptions(&db_options, rnd);
|
|
|
|
auto sanitized_options = SanitizeOptions(dbname_, db_options);
|
|
|
|
return GetMutableDBOptionsMap(sanitized_options);
|
|
|
|
}
|
2016-09-15 07:10:28 +02:00
|
|
|
#endif // ROCKSDB_LITE
|
2016-07-13 00:30:38 +02:00
|
|
|
};
|
|
|
|
|
2020-10-10 01:40:25 +02:00
|
|
|
TEST_F(DBOptionsTest, ImmutableTrackAndVerifyWalsInManifest) {
|
|
|
|
Options options;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = env_;
|
2020-10-10 01:40:25 +02:00
|
|
|
options.track_and_verify_wals_in_manifest = true;
|
|
|
|
|
|
|
|
ImmutableDBOptions db_options(options);
|
|
|
|
ASSERT_TRUE(db_options.track_and_verify_wals_in_manifest);
|
|
|
|
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_TRUE(dbfull()->GetDBOptions().track_and_verify_wals_in_manifest);
|
|
|
|
|
|
|
|
Status s =
|
|
|
|
dbfull()->SetDBOptions({{"track_and_verify_wals_in_manifest", "false"}});
|
|
|
|
ASSERT_FALSE(s.ok());
|
|
|
|
}
|
|
|
|
|
2016-07-25 20:48:17 +02:00
|
|
|
// RocksDB lite don't support dynamic options.
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2021-07-21 22:44:39 +02:00
|
|
|
TEST_F(DBOptionsTest, AvoidUpdatingOptions) {
|
|
|
|
Options options;
|
|
|
|
options.env = env_;
|
|
|
|
options.max_background_jobs = 4;
|
|
|
|
options.delayed_write_rate = 1024;
|
|
|
|
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
SyncPoint::GetInstance()->ClearAllCallBacks();
|
|
|
|
bool is_changed_stats = false;
|
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"DBImpl::WriteOptionsFile:PersistOptions", [&](void* /*arg*/) {
|
|
|
|
ASSERT_FALSE(is_changed_stats); // should only save options file once
|
|
|
|
is_changed_stats = true;
|
|
|
|
});
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
|
|
|
|
|
|
|
// helper function to check the status and reset after each check
|
|
|
|
auto is_changed = [&] {
|
|
|
|
bool ret = is_changed_stats;
|
|
|
|
is_changed_stats = false;
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
// without changing the value, but it's sanitized to a different value
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"bytes_per_sync", "0"}}));
|
|
|
|
ASSERT_TRUE(is_changed());
|
|
|
|
|
|
|
|
// without changing the value
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_background_jobs", "4"}}));
|
|
|
|
ASSERT_FALSE(is_changed());
|
|
|
|
|
|
|
|
// changing the value
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"bytes_per_sync", "123"}}));
|
|
|
|
ASSERT_TRUE(is_changed());
|
|
|
|
|
|
|
|
// update again
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"bytes_per_sync", "123"}}));
|
|
|
|
ASSERT_FALSE(is_changed());
|
|
|
|
|
|
|
|
// without changing a default value
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"strict_bytes_per_sync", "false"}}));
|
|
|
|
ASSERT_FALSE(is_changed());
|
|
|
|
|
|
|
|
// now change
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"strict_bytes_per_sync", "true"}}));
|
|
|
|
ASSERT_TRUE(is_changed());
|
|
|
|
|
|
|
|
// multiple values without change
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions(
|
|
|
|
{{"max_total_wal_size", "0"}, {"stats_dump_period_sec", "600"}}));
|
|
|
|
ASSERT_FALSE(is_changed());
|
|
|
|
|
|
|
|
// multiple values with change
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions(
|
|
|
|
{{"max_open_files", "100"}, {"stats_dump_period_sec", "600"}}));
|
|
|
|
ASSERT_TRUE(is_changed());
|
|
|
|
}
|
|
|
|
|
2016-10-14 21:25:39 +02:00
|
|
|
TEST_F(DBOptionsTest, GetLatestDBOptions) {
|
|
|
|
// GetOptions should be able to get latest option changed by SetOptions.
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-10-14 21:25:39 +02:00
|
|
|
Random rnd(228);
|
|
|
|
Reopen(options);
|
|
|
|
auto new_options = GetRandomizedMutableDBOptionsMap(&rnd);
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions(new_options));
|
|
|
|
ASSERT_EQ(new_options, GetMutableDBOptionsMap(dbfull()->GetDBOptions()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBOptionsTest, GetLatestCFOptions) {
|
2016-09-15 07:10:28 +02:00
|
|
|
// GetOptions should be able to get latest option changed by SetOptions.
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-09-15 07:10:28 +02:00
|
|
|
Random rnd(228);
|
|
|
|
Reopen(options);
|
|
|
|
CreateColumnFamilies({"foo"}, options);
|
|
|
|
ReopenWithColumnFamilies({"default", "foo"}, options);
|
|
|
|
auto options_default = GetRandomizedMutableCFOptionsMap(&rnd);
|
|
|
|
auto options_foo = GetRandomizedMutableCFOptionsMap(&rnd);
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(handles_[0], options_default));
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(handles_[1], options_foo));
|
|
|
|
ASSERT_EQ(options_default,
|
|
|
|
GetMutableCFOptionsMap(dbfull()->GetOptions(handles_[0])));
|
|
|
|
ASSERT_EQ(options_foo,
|
|
|
|
GetMutableCFOptionsMap(dbfull()->GetOptions(handles_[1])));
|
|
|
|
}
|
|
|
|
|
2021-02-19 19:25:39 +01:00
|
|
|
TEST_F(DBOptionsTest, SetMutableTableOptions) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.env = env_;
|
|
|
|
options.blob_file_size = 16384;
|
|
|
|
BlockBasedTableOptions bbto;
|
|
|
|
bbto.no_block_cache = true;
|
|
|
|
bbto.block_size = 8192;
|
|
|
|
bbto.block_restart_interval = 7;
|
|
|
|
|
|
|
|
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
ColumnFamilyHandle* cfh = dbfull()->DefaultColumnFamily();
|
|
|
|
Options c_opts = dbfull()->GetOptions(cfh);
|
|
|
|
const auto* c_bbto =
|
|
|
|
c_opts.table_factory->GetOptions<BlockBasedTableOptions>();
|
|
|
|
ASSERT_NE(c_bbto, nullptr);
|
|
|
|
ASSERT_EQ(c_opts.blob_file_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->no_block_cache, true);
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 8192);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 7);
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory.block_size", "16384"},
|
|
|
|
{"table_factory.block_restart_interval", "11"}}));
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 11);
|
|
|
|
|
|
|
|
// Now set an option that is not mutable - options should not change
|
|
|
|
ASSERT_NOK(
|
|
|
|
dbfull()->SetOptions(cfh, {{"table_factory.no_block_cache", "false"}}));
|
|
|
|
ASSERT_EQ(c_bbto->no_block_cache, true);
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 11);
|
|
|
|
|
|
|
|
// Set some that are mutable and some that are not - options should not change
|
|
|
|
ASSERT_NOK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory.no_block_cache", "false"},
|
|
|
|
{"table_factory.block_size", "8192"},
|
|
|
|
{"table_factory.block_restart_interval", "7"}}));
|
|
|
|
ASSERT_EQ(c_bbto->no_block_cache, true);
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 11);
|
|
|
|
|
|
|
|
// Set some that are mutable and some that do not exist - options should not
|
|
|
|
// change
|
|
|
|
ASSERT_NOK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory.block_size", "8192"},
|
|
|
|
{"table_factory.does_not_exist", "true"},
|
|
|
|
{"table_factory.block_restart_interval", "7"}}));
|
|
|
|
ASSERT_EQ(c_bbto->no_block_cache, true);
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 11);
|
|
|
|
|
|
|
|
// Trying to change the table factory fails
|
|
|
|
ASSERT_NOK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory", TableFactory::kPlainTableName()}}));
|
|
|
|
|
|
|
|
// Set some on the table and some on the Column Family
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory.block_size", "16384"},
|
|
|
|
{"blob_file_size", "32768"},
|
|
|
|
{"table_factory.block_restart_interval", "13"}}));
|
|
|
|
c_opts = dbfull()->GetOptions(cfh);
|
|
|
|
ASSERT_EQ(c_opts.blob_file_size, 32768);
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 13);
|
|
|
|
// Set some on the table and a bad one on the ColumnFamily - options should
|
|
|
|
// not change
|
|
|
|
ASSERT_NOK(dbfull()->SetOptions(
|
|
|
|
cfh, {{"table_factory.block_size", "1024"},
|
|
|
|
{"no_such_option", "32768"},
|
|
|
|
{"table_factory.block_restart_interval", "7"}}));
|
|
|
|
ASSERT_EQ(c_bbto->block_size, 16384);
|
|
|
|
ASSERT_EQ(c_bbto->block_restart_interval, 13);
|
|
|
|
}
|
|
|
|
|
2021-12-09 21:35:18 +01:00
|
|
|
TEST_F(DBOptionsTest, SetWithCustomMemTableFactory) {
|
|
|
|
class DummySkipListFactory : public SkipListFactory {
|
|
|
|
public:
|
|
|
|
static const char* kClassName() { return "DummySkipListFactory"; }
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
explicit DummySkipListFactory() : SkipListFactory(2) {}
|
|
|
|
};
|
|
|
|
{
|
|
|
|
// Verify the DummySkipList cannot be created
|
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.ignore_unsupported_options = false;
|
|
|
|
std::unique_ptr<MemTableRepFactory> factory;
|
|
|
|
ASSERT_NOK(MemTableRepFactory::CreateFromString(
|
|
|
|
config_options, DummySkipListFactory::kClassName(), &factory));
|
|
|
|
}
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
// Try with fail_if_options_file_error=false/true to update the options
|
|
|
|
for (bool on_error : {false, true}) {
|
|
|
|
options.fail_if_options_file_error = on_error;
|
|
|
|
options.env = env_;
|
|
|
|
options.disable_auto_compactions = false;
|
|
|
|
|
|
|
|
options.memtable_factory.reset(new DummySkipListFactory());
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
ColumnFamilyHandle* cfh = dbfull()->DefaultColumnFamily();
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetOptions(cfh, {{"disable_auto_compactions", "true"}}));
|
|
|
|
ColumnFamilyDescriptor cfd;
|
|
|
|
ASSERT_OK(cfh->GetDescriptor(&cfd));
|
|
|
|
ASSERT_STREQ(cfd.options.memtable_factory->Name(),
|
|
|
|
DummySkipListFactory::kClassName());
|
|
|
|
ColumnFamilyHandle* test = nullptr;
|
|
|
|
ASSERT_OK(dbfull()->CreateColumnFamily(options, "test", &test));
|
|
|
|
ASSERT_OK(test->GetDescriptor(&cfd));
|
|
|
|
ASSERT_STREQ(cfd.options.memtable_factory->Name(),
|
|
|
|
DummySkipListFactory::kClassName());
|
|
|
|
|
|
|
|
ASSERT_OK(dbfull()->DropColumnFamily(test));
|
|
|
|
delete test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 02:37:08 +02:00
|
|
|
TEST_F(DBOptionsTest, SetBytesPerSync) {
|
2017-10-03 22:36:53 +02:00
|
|
|
const size_t kValueSize = 1024 * 1024; // 1MB
|
2017-09-28 02:37:08 +02:00
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.bytes_per_sync = 1024 * 1024;
|
|
|
|
options.use_direct_reads = false;
|
|
|
|
options.write_buffer_size = 400 * kValueSize;
|
|
|
|
options.disable_auto_compactions = true;
|
2017-10-03 22:36:53 +02:00
|
|
|
options.compression = kNoCompression;
|
2017-09-28 02:37:08 +02:00
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
|
|
|
int counter = 0;
|
|
|
|
int low_bytes_per_sync = 0;
|
|
|
|
int i = 0;
|
|
|
|
const std::string kValue(kValueSize, 'v');
|
|
|
|
ASSERT_EQ(options.bytes_per_sync, dbfull()->GetDBOptions().bytes_per_sync);
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"WritableFileWriter::RangeSync:0", [&](void* /*arg*/) { counter++; });
|
2017-09-28 02:37:08 +02:00
|
|
|
|
|
|
|
WriteOptions write_opts;
|
2017-10-03 22:36:53 +02:00
|
|
|
// should sync approximately 40MB/1MB ~= 40 times.
|
|
|
|
for (i = 0; i < 40; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue, write_opts));
|
2017-09-28 02:37:08 +02:00
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
2017-09-28 02:37:08 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
2017-09-28 02:37:08 +02:00
|
|
|
low_bytes_per_sync = counter;
|
2017-10-03 22:36:53 +02:00
|
|
|
ASSERT_GT(low_bytes_per_sync, 35);
|
|
|
|
ASSERT_LT(low_bytes_per_sync, 45);
|
|
|
|
|
2017-09-28 02:37:08 +02:00
|
|
|
counter = 0;
|
|
|
|
// 8388608 = 8 * 1024 * 1024
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"bytes_per_sync", "8388608"}}));
|
|
|
|
ASSERT_EQ(8388608, dbfull()->GetDBOptions().bytes_per_sync);
|
2017-10-03 22:36:53 +02:00
|
|
|
// should sync approximately 40MB*2/8MB ~= 10 times.
|
|
|
|
// data will be 40*2MB because of previous Puts too.
|
|
|
|
for (i = 0; i < 40; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue, write_opts));
|
2017-09-28 02:37:08 +02:00
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
2017-09-28 02:37:08 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-03 22:36:53 +02:00
|
|
|
ASSERT_GT(counter, 5);
|
|
|
|
ASSERT_LT(counter, 15);
|
|
|
|
|
|
|
|
// Redundant assert. But leaving it here just to get the point across that
|
|
|
|
// low_bytes_per_sync > counter.
|
2017-09-28 02:37:08 +02:00
|
|
|
ASSERT_GT(low_bytes_per_sync, counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBOptionsTest, SetWalBytesPerSync) {
|
|
|
|
const size_t kValueSize = 1024 * 1024 * 3;
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.wal_bytes_per_sync = 512;
|
|
|
|
options.write_buffer_size = 100 * kValueSize;
|
|
|
|
options.disable_auto_compactions = true;
|
2017-10-03 22:36:53 +02:00
|
|
|
options.compression = kNoCompression;
|
2017-09-28 02:37:08 +02:00
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(512, dbfull()->GetDBOptions().wal_bytes_per_sync);
|
2021-01-11 19:15:59 +01:00
|
|
|
std::atomic_int counter{0};
|
2017-09-28 02:37:08 +02:00
|
|
|
int low_bytes_per_sync = 0;
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
2021-01-11 19:15:59 +01:00
|
|
|
"WritableFileWriter::RangeSync:0",
|
|
|
|
[&](void* /*arg*/) { counter.fetch_add(1); });
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
2017-09-28 02:37:08 +02:00
|
|
|
const std::string kValue(kValueSize, 'v');
|
|
|
|
int i = 0;
|
|
|
|
for (; i < 10; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2017-09-28 02:37:08 +02:00
|
|
|
}
|
|
|
|
// Do not flush. If we flush here, SwitchWAL will reuse old WAL file since its
|
|
|
|
// empty and will not get the new wal_bytes_per_sync value.
|
|
|
|
low_bytes_per_sync = counter;
|
|
|
|
//5242880 = 1024 * 1024 * 5
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"wal_bytes_per_sync", "5242880"}}));
|
|
|
|
ASSERT_EQ(5242880, dbfull()->GetDBOptions().wal_bytes_per_sync);
|
|
|
|
counter = 0;
|
|
|
|
i = 0;
|
|
|
|
for (; i < 10; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2017-09-28 02:37:08 +02:00
|
|
|
}
|
|
|
|
ASSERT_GT(counter, 0);
|
|
|
|
ASSERT_GT(low_bytes_per_sync, 0);
|
|
|
|
ASSERT_GT(low_bytes_per_sync, counter);
|
|
|
|
}
|
|
|
|
|
2017-10-31 21:49:25 +01:00
|
|
|
TEST_F(DBOptionsTest, WritableFileMaxBufferSize) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.writable_file_max_buffer_size = 1024 * 1024;
|
|
|
|
options.level0_file_num_compaction_trigger = 3;
|
|
|
|
options.max_manifest_file_size = 1;
|
|
|
|
options.env = env_;
|
|
|
|
int buffer_size = 1024 * 1024;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(buffer_size,
|
|
|
|
dbfull()->GetDBOptions().writable_file_max_buffer_size);
|
|
|
|
|
|
|
|
std::atomic<int> match_cnt(0);
|
|
|
|
std::atomic<int> unmatch_cnt(0);
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
2017-10-31 21:49:25 +01:00
|
|
|
"WritableFileWriter::WritableFileWriter:0", [&](void* arg) {
|
|
|
|
int value = static_cast<int>(reinterpret_cast<uintptr_t>(arg));
|
|
|
|
if (value == buffer_size) {
|
|
|
|
match_cnt++;
|
|
|
|
} else {
|
|
|
|
unmatch_cnt++;
|
|
|
|
}
|
|
|
|
});
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
2017-10-31 21:49:25 +01:00
|
|
|
int i = 0;
|
|
|
|
for (; i < 3; i++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put("foo", std::to_string(i)));
|
|
|
|
ASSERT_OK(Put("bar", std::to_string(i)));
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2017-10-31 21:49:25 +01:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2017-10-31 21:49:25 +01:00
|
|
|
ASSERT_EQ(unmatch_cnt, 0);
|
|
|
|
ASSERT_GE(match_cnt, 11);
|
|
|
|
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetDBOptions({{"writable_file_max_buffer_size", "524288"}}));
|
2018-05-22 01:37:47 +02:00
|
|
|
buffer_size = 512 * 1024;
|
|
|
|
match_cnt = 0;
|
|
|
|
unmatch_cnt = 0; // SetDBOptions() will create a WriteableFileWriter
|
|
|
|
|
2017-10-31 21:49:25 +01:00
|
|
|
ASSERT_EQ(buffer_size,
|
|
|
|
dbfull()->GetDBOptions().writable_file_max_buffer_size);
|
|
|
|
i = 0;
|
|
|
|
for (; i < 3; i++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put("foo", std::to_string(i)));
|
|
|
|
ASSERT_OK(Put("bar", std::to_string(i)));
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2017-10-31 21:49:25 +01:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2017-10-31 21:49:25 +01:00
|
|
|
ASSERT_EQ(unmatch_cnt, 0);
|
|
|
|
ASSERT_GE(match_cnt, 11);
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:17:15 +02:00
|
|
|
TEST_F(DBOptionsTest, SetOptionsAndReopen) {
|
|
|
|
Random rnd(1044);
|
|
|
|
auto rand_opts = GetRandomizedMutableCFOptionsMap(&rnd);
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(rand_opts));
|
|
|
|
// Verify if DB can be reopen after setting options.
|
|
|
|
Options options;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-09-27 20:17:15 +02:00
|
|
|
ASSERT_OK(TryReopen(options));
|
|
|
|
}
|
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
TEST_F(DBOptionsTest, EnableAutoCompactionAndTriggerStall) {
|
|
|
|
const std::string kValue(1024, 'v');
|
|
|
|
for (int method_type = 0; method_type < 2; method_type++) {
|
|
|
|
for (int option_type = 0; option_type < 4; option_type++) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.disable_auto_compactions = true;
|
2016-08-06 01:45:57 +02:00
|
|
|
options.write_buffer_size = 1024 * 1024 * 10;
|
2016-08-03 06:55:26 +02:00
|
|
|
options.compression = CompressionType::kNoCompression;
|
|
|
|
options.level0_file_num_compaction_trigger = 1;
|
|
|
|
options.level0_stop_writes_trigger = std::numeric_limits<int>::max();
|
|
|
|
options.level0_slowdown_writes_trigger = std::numeric_limits<int>::max();
|
|
|
|
options.hard_pending_compaction_bytes_limit =
|
|
|
|
std::numeric_limits<uint64_t>::max();
|
|
|
|
options.soft_pending_compaction_bytes_limit =
|
|
|
|
std::numeric_limits<uint64_t>::max();
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
DestroyAndReopen(options);
|
2016-08-06 01:45:57 +02:00
|
|
|
int i = 0;
|
|
|
|
for (; i < 1024; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2016-08-03 06:55:26 +02:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2016-08-06 01:45:57 +02:00
|
|
|
for (; i < 1024 * 2; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2016-08-06 01:45:57 +02:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
|
2016-08-03 06:55:26 +02:00
|
|
|
ASSERT_EQ(2, NumTableFilesAtLevel(0));
|
|
|
|
uint64_t l0_size = SizeAtLevel(0);
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
switch (option_type) {
|
|
|
|
case 0:
|
|
|
|
// test with level0_stop_writes_trigger
|
|
|
|
options.level0_stop_writes_trigger = 2;
|
|
|
|
options.level0_slowdown_writes_trigger = 2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
options.level0_slowdown_writes_trigger = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
options.hard_pending_compaction_bytes_limit = l0_size;
|
|
|
|
options.soft_pending_compaction_bytes_limit = l0_size;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
options.soft_pending_compaction_bytes_limit = l0_size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Reopen(options);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-08-03 06:55:26 +02:00
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().NeedsDelay());
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->LoadDependency(
|
|
|
|
{{"DBOptionsTest::EnableAutoCompactionAndTriggerStall:1",
|
|
|
|
"BackgroundCallCompaction:0"},
|
|
|
|
{"DBImpl::BackgroundCompaction():BeforePickCompaction",
|
|
|
|
"DBOptionsTest::EnableAutoCompactionAndTriggerStall:2"},
|
|
|
|
{"DBOptionsTest::EnableAutoCompactionAndTriggerStall:3",
|
|
|
|
"DBImpl::BackgroundCompaction():AfterPickCompaction"}});
|
|
|
|
// Block background compaction.
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
switch (method_type) {
|
|
|
|
case 0:
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetOptions({{"disable_auto_compactions", "false"}}));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ASSERT_OK(dbfull()->EnableAutoCompaction(
|
|
|
|
{dbfull()->DefaultColumnFamily()}));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TEST_SYNC_POINT("DBOptionsTest::EnableAutoCompactionAndTriggerStall:1");
|
|
|
|
// Wait for stall condition recalculate.
|
|
|
|
TEST_SYNC_POINT("DBOptionsTest::EnableAutoCompactionAndTriggerStall:2");
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
switch (option_type) {
|
|
|
|
case 0:
|
|
|
|
ASSERT_TRUE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
ASSERT_TRUE(dbfull()->TEST_write_controler().NeedsDelay());
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ASSERT_TRUE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
ASSERT_TRUE(dbfull()->TEST_write_controler().NeedsDelay());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TEST_SYNC_POINT("DBOptionsTest::EnableAutoCompactionAndTriggerStall:3");
|
2016-07-13 00:30:38 +02:00
|
|
|
|
2016-08-03 06:55:26 +02:00
|
|
|
// Background compaction executed.
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-08-03 06:55:26 +02:00
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped());
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().NeedsDelay());
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 00:30:38 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:17:15 +02:00
|
|
|
TEST_F(DBOptionsTest, SetOptionsMayTriggerCompaction) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.level0_file_num_compaction_trigger = 1000;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-09-27 20:17:15 +02:00
|
|
|
Reopen(options);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
// Need to insert two keys to avoid trivial move.
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put("foo", std::to_string(i)));
|
|
|
|
ASSERT_OK(Put("bar", std::to_string(i)));
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2016-09-27 20:17:15 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ("3", FilesPerLevel());
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetOptions({{"level0_file_num_compaction_trigger", "3"}}));
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2016-09-27 20:17:15 +02:00
|
|
|
ASSERT_EQ("0,1", FilesPerLevel());
|
|
|
|
}
|
|
|
|
|
2016-10-14 21:25:39 +02:00
|
|
|
TEST_F(DBOptionsTest, SetBackgroundCompactionThreads) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.max_background_compactions = 1; // default value
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-10-14 21:25:39 +02:00
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed());
|
2017-05-24 20:25:38 +02:00
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_background_compactions", "3"}}));
|
|
|
|
ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed());
|
2016-10-14 21:25:39 +02:00
|
|
|
auto stop_token = dbfull()->TEST_write_controler().GetStopToken();
|
|
|
|
ASSERT_EQ(3, dbfull()->TEST_BGCompactionsAllowed());
|
|
|
|
}
|
|
|
|
|
2020-04-21 01:17:25 +02:00
|
|
|
TEST_F(DBOptionsTest, SetBackgroundFlushThreads) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.max_background_flushes = 1;
|
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(1, dbfull()->TEST_BGFlushesAllowed());
|
|
|
|
ASSERT_EQ(1, env_->GetBackgroundThreads(Env::Priority::HIGH));
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_background_flushes", "3"}}));
|
|
|
|
ASSERT_EQ(3, env_->GetBackgroundThreads(Env::Priority::HIGH));
|
|
|
|
ASSERT_EQ(3, dbfull()->TEST_BGFlushesAllowed());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-24 20:25:38 +02:00
|
|
|
TEST_F(DBOptionsTest, SetBackgroundJobs) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.max_background_jobs = 8;
|
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
options.max_background_jobs = 12;
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions(
|
|
|
|
{{"max_background_jobs",
|
|
|
|
std::to_string(options.max_background_jobs)}}));
|
|
|
|
}
|
|
|
|
|
2020-01-16 23:33:28 +01:00
|
|
|
const int expected_max_flushes = options.max_background_jobs / 4;
|
|
|
|
|
|
|
|
ASSERT_EQ(expected_max_flushes, dbfull()->TEST_BGFlushesAllowed());
|
2017-05-24 20:25:38 +02:00
|
|
|
ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed());
|
|
|
|
|
|
|
|
auto stop_token = dbfull()->TEST_write_controler().GetStopToken();
|
|
|
|
|
2020-01-16 23:33:28 +01:00
|
|
|
const int expected_max_compactions = 3 * expected_max_flushes;
|
|
|
|
|
|
|
|
ASSERT_EQ(expected_max_flushes, dbfull()->TEST_BGFlushesAllowed());
|
|
|
|
ASSERT_EQ(expected_max_compactions, dbfull()->TEST_BGCompactionsAllowed());
|
|
|
|
|
|
|
|
ASSERT_EQ(expected_max_flushes,
|
|
|
|
env_->GetBackgroundThreads(Env::Priority::HIGH));
|
|
|
|
ASSERT_EQ(expected_max_compactions,
|
|
|
|
env_->GetBackgroundThreads(Env::Priority::LOW));
|
2017-05-24 20:25:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 23:22:13 +01:00
|
|
|
TEST_F(DBOptionsTest, AvoidFlushDuringShutdown) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.disable_auto_compactions = true;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-11-02 23:22:13 +01:00
|
|
|
WriteOptions write_without_wal;
|
|
|
|
write_without_wal.disableWAL = true;
|
|
|
|
|
|
|
|
ASSERT_FALSE(options.avoid_flush_during_shutdown);
|
|
|
|
DestroyAndReopen(options);
|
|
|
|
ASSERT_OK(Put("foo", "v1", write_without_wal));
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ("v1", Get("foo"));
|
|
|
|
ASSERT_EQ("1", FilesPerLevel());
|
|
|
|
|
|
|
|
DestroyAndReopen(options);
|
|
|
|
ASSERT_OK(Put("foo", "v2", write_without_wal));
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"avoid_flush_during_shutdown", "true"}}));
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ("NOT_FOUND", Get("foo"));
|
|
|
|
ASSERT_EQ("", FilesPerLevel());
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:43:33 +01:00
|
|
|
TEST_F(DBOptionsTest, SetDelayedWriteRateOption) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.delayed_write_rate = 2 * 1024U * 1024U;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-11-13 00:43:33 +01:00
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(2 * 1024U * 1024U, dbfull()->TEST_write_controler().max_delayed_write_rate());
|
|
|
|
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"delayed_write_rate", "20000"}}));
|
|
|
|
ASSERT_EQ(20000, dbfull()->TEST_write_controler().max_delayed_write_rate());
|
|
|
|
}
|
|
|
|
|
2016-11-15 07:45:16 +01:00
|
|
|
TEST_F(DBOptionsTest, MaxTotalWalSizeChange) {
|
|
|
|
Random rnd(1044);
|
|
|
|
const auto value_size = size_t(1024);
|
2020-07-09 23:33:42 +02:00
|
|
|
std::string value = rnd.RandomString(value_size);
|
2016-11-15 07:45:16 +01:00
|
|
|
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
2017-03-13 17:41:30 +01:00
|
|
|
options.env = env_;
|
2016-11-15 07:45:16 +01:00
|
|
|
CreateColumnFamilies({"1", "2", "3"}, options);
|
|
|
|
ReopenWithColumnFamilies({"default", "1", "2", "3"}, options);
|
|
|
|
|
|
|
|
WriteOptions write_options;
|
|
|
|
|
|
|
|
const int key_count = 100;
|
|
|
|
for (int i = 0; i < key_count; ++i) {
|
|
|
|
for (size_t cf = 0; cf < handles_.size(); ++cf) {
|
|
|
|
ASSERT_OK(Put(static_cast<int>(cf), Key(i), value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_total_wal_size", "10"}}));
|
|
|
|
|
|
|
|
for (size_t cf = 0; cf < handles_.size(); ++cf) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[cf]));
|
2016-11-15 07:45:16 +01:00
|
|
|
ASSERT_EQ("1", FilesPerLevel(static_cast<int>(cf)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 06:50:56 +01:00
|
|
|
TEST_F(DBOptionsTest, SetStatsDumpPeriodSec) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.stats_dump_period_sec = 5;
|
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
2019-09-09 20:22:28 +02:00
|
|
|
ASSERT_EQ(5u, dbfull()->GetDBOptions().stats_dump_period_sec);
|
2017-03-21 06:50:56 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++) {
|
2019-09-09 20:22:28 +02:00
|
|
|
unsigned int num = rand() % 5000 + 1;
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(dbfull()->SetDBOptions(
|
|
|
|
{{"stats_dump_period_sec", std::to_string(num)}}));
|
2017-03-21 06:50:56 +01:00
|
|
|
ASSERT_EQ(num, dbfull()->GetDBOptions().stats_dump_period_sec);
|
|
|
|
}
|
2019-02-21 00:46:59 +01:00
|
|
|
Close();
|
2017-03-21 06:50:56 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 00:46:59 +01:00
|
|
|
TEST_F(DBOptionsTest, SetOptionsStatsPersistPeriodSec) {
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.stats_persist_period_sec = 5;
|
|
|
|
options.env = env_;
|
|
|
|
Reopen(options);
|
2019-09-09 20:22:28 +02:00
|
|
|
ASSERT_EQ(5u, dbfull()->GetDBOptions().stats_persist_period_sec);
|
2019-02-21 00:46:59 +01:00
|
|
|
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"stats_persist_period_sec", "12345"}}));
|
2019-09-09 20:22:28 +02:00
|
|
|
ASSERT_EQ(12345u, dbfull()->GetDBOptions().stats_persist_period_sec);
|
2019-02-21 00:46:59 +01:00
|
|
|
ASSERT_NOK(dbfull()->SetDBOptions({{"stats_persist_period_sec", "abcde"}}));
|
2019-09-09 20:22:28 +02:00
|
|
|
ASSERT_EQ(12345u, dbfull()->GetDBOptions().stats_persist_period_sec);
|
2019-02-21 00:46:59 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 23:09:35 +01:00
|
|
|
static void assert_candidate_files_empty(DBImpl* dbfull, const bool empty) {
|
|
|
|
dbfull->TEST_LockMutex();
|
|
|
|
JobContext job_context(0);
|
|
|
|
dbfull->FindObsoleteFiles(&job_context, false);
|
|
|
|
ASSERT_EQ(empty, job_context.full_scan_candidate_files.empty());
|
|
|
|
dbfull->TEST_UnlockMutex();
|
2018-01-18 02:37:10 +01:00
|
|
|
if (job_context.HaveSomethingToDelete()) {
|
|
|
|
// fulfill the contract of FindObsoleteFiles by calling PurgeObsoleteFiles
|
|
|
|
// afterwards; otherwise the test may hang on shutdown
|
|
|
|
dbfull->PurgeObsoleteFiles(job_context);
|
|
|
|
}
|
|
|
|
job_context.Clean();
|
2016-12-05 23:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBOptionsTest, DeleteObsoleteFilesPeriodChange) {
|
|
|
|
Options options;
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
options.env = env_;
|
|
|
|
SetTimeElapseOnlySleepOnReopen(&options);
|
2016-12-05 23:09:35 +01:00
|
|
|
options.create_if_missing = true;
|
|
|
|
ASSERT_OK(TryReopen(options));
|
|
|
|
|
|
|
|
// Verify that candidate files set is empty when no full scan requested.
|
|
|
|
assert_candidate_files_empty(dbfull(), true);
|
|
|
|
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetDBOptions({{"delete_obsolete_files_period_micros", "0"}}));
|
|
|
|
|
|
|
|
// After delete_obsolete_files_period_micros updated to 0, the next call
|
|
|
|
// to FindObsoleteFiles should make a full scan
|
|
|
|
assert_candidate_files_empty(dbfull(), false);
|
|
|
|
|
|
|
|
ASSERT_OK(
|
|
|
|
dbfull()->SetDBOptions({{"delete_obsolete_files_period_micros", "20"}}));
|
|
|
|
|
|
|
|
assert_candidate_files_empty(dbfull(), true);
|
|
|
|
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
env_->MockSleepForMicroseconds(20);
|
2016-12-05 23:09:35 +01:00
|
|
|
assert_candidate_files_empty(dbfull(), true);
|
|
|
|
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
env_->MockSleepForMicroseconds(1);
|
2016-12-05 23:09:35 +01:00
|
|
|
assert_candidate_files_empty(dbfull(), false);
|
|
|
|
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2017-05-04 05:46:17 +02:00
|
|
|
TEST_F(DBOptionsTest, MaxOpenFilesChange) {
|
|
|
|
SpecialEnv env(env_);
|
|
|
|
Options options;
|
2017-06-27 01:52:06 +02:00
|
|
|
options.env = CurrentOptions().env;
|
2017-05-04 05:46:17 +02:00
|
|
|
options.max_open_files = -1;
|
|
|
|
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
Cache* tc = dbfull()->TEST_table_cache();
|
|
|
|
|
|
|
|
ASSERT_EQ(-1, dbfull()->GetDBOptions().max_open_files);
|
|
|
|
ASSERT_LT(2000, tc->GetCapacity());
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_open_files", "1024"}}));
|
|
|
|
ASSERT_EQ(1024, dbfull()->GetDBOptions().max_open_files);
|
|
|
|
// examine the table cache (actual size should be 1014)
|
|
|
|
ASSERT_GT(1500, tc->GetCapacity());
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2017-05-24 18:52:08 +02:00
|
|
|
TEST_F(DBOptionsTest, SanitizeDelayedWriteRate) {
|
|
|
|
Options options;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2017-05-24 18:52:08 +02:00
|
|
|
options.delayed_write_rate = 0;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(16 * 1024 * 1024, dbfull()->GetDBOptions().delayed_write_rate);
|
|
|
|
|
|
|
|
options.rate_limiter.reset(NewGenericRateLimiter(31 * 1024 * 1024));
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(31 * 1024 * 1024, dbfull()->GetDBOptions().delayed_write_rate);
|
|
|
|
}
|
|
|
|
|
2019-11-23 07:12:09 +01:00
|
|
|
TEST_F(DBOptionsTest, SanitizeUniversalTTLCompaction) {
|
|
|
|
Options options;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2019-11-23 07:12:09 +01:00
|
|
|
options.compaction_style = kCompactionStyleUniversal;
|
|
|
|
|
|
|
|
options.ttl = 0;
|
|
|
|
options.periodic_compaction_seconds = 0;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(0, dbfull()->GetOptions().ttl);
|
|
|
|
ASSERT_EQ(0, dbfull()->GetOptions().periodic_compaction_seconds);
|
|
|
|
|
|
|
|
options.ttl = 0;
|
|
|
|
options.periodic_compaction_seconds = 100;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(0, dbfull()->GetOptions().ttl);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().periodic_compaction_seconds);
|
|
|
|
|
|
|
|
options.ttl = 100;
|
|
|
|
options.periodic_compaction_seconds = 0;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().ttl);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().periodic_compaction_seconds);
|
|
|
|
|
|
|
|
options.ttl = 100;
|
|
|
|
options.periodic_compaction_seconds = 500;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().ttl);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().periodic_compaction_seconds);
|
|
|
|
}
|
|
|
|
|
2019-11-26 02:11:26 +01:00
|
|
|
TEST_F(DBOptionsTest, SanitizeTtlDefault) {
|
|
|
|
Options options;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2019-11-26 02:11:26 +01:00
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(30 * 24 * 60 * 60, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.compaction_style = kCompactionStyleLevel;
|
|
|
|
options.ttl = 0;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(0, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.ttl = 100;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().ttl);
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:59:13 +01:00
|
|
|
TEST_F(DBOptionsTest, SanitizeFIFOPeriodicCompaction) {
|
|
|
|
Options options;
|
|
|
|
options.compaction_style = kCompactionStyleFIFO;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2019-10-31 18:59:13 +01:00
|
|
|
options.ttl = 0;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(30 * 24 * 60 * 60, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.ttl = 100;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(100, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.ttl = 100 * 24 * 60 * 60;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(100 * 24 * 60 * 60, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.ttl = 200;
|
|
|
|
options.periodic_compaction_seconds = 300;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(200, dbfull()->GetOptions().ttl);
|
|
|
|
|
|
|
|
options.ttl = 500;
|
|
|
|
options.periodic_compaction_seconds = 300;
|
|
|
|
Reopen(options);
|
|
|
|
ASSERT_EQ(300, dbfull()->GetOptions().ttl);
|
|
|
|
}
|
|
|
|
|
2017-10-20 00:19:20 +02:00
|
|
|
TEST_F(DBOptionsTest, SetFIFOCompactionOptions) {
|
|
|
|
Options options;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2017-10-20 00:19:20 +02:00
|
|
|
options.compaction_style = kCompactionStyleFIFO;
|
|
|
|
options.write_buffer_size = 10 << 10; // 10KB
|
|
|
|
options.arena_block_size = 4096;
|
|
|
|
options.compression = kNoCompression;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.compaction_options_fifo.allow_compaction = false;
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
env_->SetMockSleep();
|
2017-10-20 00:19:20 +02:00
|
|
|
options.env = env_;
|
|
|
|
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
// NOTE: Presumed unnecessary and removed: resetting mock time in env
|
|
|
|
|
2019-02-15 18:48:44 +01:00
|
|
|
// Test dynamically changing ttl.
|
|
|
|
options.ttl = 1 * 60 * 60; // 1 hour
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_OK(TryReopen(options));
|
|
|
|
|
|
|
|
Random rnd(301);
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
// Generate and flush a file about 10KB.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(Flush());
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
env_->MockSleepForSeconds(61);
|
2017-10-20 00:19:20 +02:00
|
|
|
|
|
|
|
// No files should be compacted as ttl is set to 1 hour.
|
2019-02-15 18:48:44 +01:00
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 3600);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// Set ttl to 1 minute. So all files should get deleted.
|
2019-02-15 18:48:44 +01:00
|
|
|
ASSERT_OK(dbfull()->SetOptions({{"ttl", "60"}}));
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 60);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 0);
|
|
|
|
|
Fix+clean up handling of mock sleeps (#7101)
Summary:
We have a number of tests hanging on MacOS and windows due to
mishandling of code for mock sleeps. In addition, the code was in
terrible shape because the same variable (addon_time_) would sometimes
refer to microseconds and sometimes to seconds. One test even assumed it
was nanoseconds but was written to pass anyway.
This has been cleaned up so that DB tests generally use a SpecialEnv
function to mock sleep, for either some number of microseconds or seconds
depending on the function called. But to call one of these, the test must first
call SetMockSleep (precondition enforced with assertion), which also turns
sleeps in RocksDB into mock sleeps. To also removes accounting for actual
clock time, call SetTimeElapseOnlySleepOnReopen, which implies
SetMockSleep (on DB re-open). This latter setting only works by applying
on DB re-open, otherwise havoc can ensue if Env goes back in time with
DB open.
More specifics:
Removed some unused test classes, and updated comments on the general
problem.
Fixed DBSSTTest.GetTotalSstFilesSize using a sync point callback instead
of mock time. For this we have the only modification to production code,
inserting a sync point callback in flush_job.cc, which is not a change to
production behavior.
Removed unnecessary resetting of mock times to 0 in many tests. RocksDB
deals in relative time. Any behaviors relying on absolute date/time are likely
a bug. (The above test DBSSTTest.GetTotalSstFilesSize was the only one
clearly injecting a specific absolute time for actual testing convenience.) Just
in case I misunderstood some test, I put this note in each replacement:
// NOTE: Presumed unnecessary and removed: resetting mock time in env
Strengthened some tests like MergeTestTime, MergeCompactionTimeTest, and
FilterCompactionTimeTest in db_test.cc
stats_history_test and blob_db_test are each their own beast, rather deeply
dependent on MockTimeEnv. Each gets its own variant of a work-around for
TimedWait in a mock time environment. (Reduces redundancy and
inconsistency in stats_history_test.)
Intended follow-up:
Remove TimedWait from the public API of InstrumentedCondVar, and only
make that accessible through Env by passing in an InstrumentedCondVar and
a deadline. Then the Env implementations mocking time can fix this problem
without using sync points. (Test infrastructure using sync points interferes
with individual tests' control over sync points.)
With that change, we can simplify/consolidate the scattered work-arounds.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7101
Test Plan: make check on Linux and MacOS
Reviewed By: zhichao-cao
Differential Revision: D23032815
Pulled By: pdillinger
fbshipit-source-id: 7f33967ada8b83011fb54e8279365c008bd6610b
2020-08-11 21:39:49 +02:00
|
|
|
// NOTE: Presumed unnecessary and removed: resetting mock time in env
|
|
|
|
|
2017-10-20 00:19:20 +02:00
|
|
|
// Test dynamically changing compaction_options_fifo.max_table_files_size
|
|
|
|
options.compaction_options_fifo.max_table_files_size = 500 << 10; // 00KB
|
2019-02-15 18:48:44 +01:00
|
|
|
options.ttl = 0;
|
2017-10-20 00:19:20 +02:00
|
|
|
DestroyAndReopen(options);
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
// Generate and flush a file about 10KB.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// No files should be compacted as max_table_files_size is set to 500 KB.
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size,
|
|
|
|
500 << 10);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// Set max_table_files_size to 12 KB. So only 1 file should remain now.
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
{{"compaction_options_fifo", "{max_table_files_size=12288;}"}}));
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size,
|
|
|
|
12 << 10);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 1);
|
|
|
|
|
|
|
|
// Test dynamically changing compaction_options_fifo.allow_compaction
|
|
|
|
options.compaction_options_fifo.max_table_files_size = 500 << 10; // 500KB
|
2019-02-15 18:48:44 +01:00
|
|
|
options.ttl = 0;
|
2017-10-20 00:19:20 +02:00
|
|
|
options.compaction_options_fifo.allow_compaction = false;
|
|
|
|
options.level0_file_num_compaction_trigger = 6;
|
|
|
|
DestroyAndReopen(options);
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
// Generate and flush a file about 10KB.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2017-10-20 00:19:20 +02:00
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// No files should be compacted as max_table_files_size is set to 500 KB and
|
|
|
|
// allow_compaction is false
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction,
|
|
|
|
false);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// Set allow_compaction to true. So number of files should be between 1 and 5.
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
{{"compaction_options_fifo", "{allow_compaction=true;}"}}));
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction,
|
|
|
|
true);
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
2017-10-20 00:19:20 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_GE(NumTableFilesAtLevel(0), 1);
|
|
|
|
ASSERT_LE(NumTableFilesAtLevel(0), 5);
|
|
|
|
}
|
|
|
|
|
2017-11-17 02:46:43 +01:00
|
|
|
TEST_F(DBOptionsTest, CompactionReadaheadSizeChange) {
|
|
|
|
SpecialEnv env(env_);
|
|
|
|
Options options;
|
|
|
|
options.env = &env;
|
|
|
|
|
|
|
|
options.compaction_readahead_size = 0;
|
|
|
|
options.level0_file_num_compaction_trigger = 2;
|
|
|
|
const std::string kValue(1024, 'v');
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, dbfull()->GetDBOptions().compaction_readahead_size);
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"compaction_readahead_size", "256"}}));
|
|
|
|
ASSERT_EQ(256, dbfull()->GetDBOptions().compaction_readahead_size);
|
|
|
|
for (int i = 0; i < 1024; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2017-11-17 02:46:43 +01:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2017-11-17 02:46:43 +01:00
|
|
|
for (int i = 0; i < 1024 * 2; i++) {
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Put(Key(i), kValue));
|
2017-11-17 02:46:43 +01:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2017-11-17 02:46:43 +01:00
|
|
|
ASSERT_EQ(256, env_->compaction_readahead_size_);
|
|
|
|
Close();
|
|
|
|
}
|
2019-05-30 19:43:34 +02:00
|
|
|
|
|
|
|
TEST_F(DBOptionsTest, FIFOTtlBackwardCompatible) {
|
|
|
|
Options options;
|
|
|
|
options.compaction_style = kCompactionStyleFIFO;
|
|
|
|
options.write_buffer_size = 10 << 10; // 10KB
|
|
|
|
options.create_if_missing = true;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2019-05-30 19:43:34 +02:00
|
|
|
|
|
|
|
ASSERT_OK(TryReopen(options));
|
|
|
|
|
|
|
|
Random rnd(301);
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
// Generate and flush a file about 10KB.
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2022-05-06 22:03:58 +02:00
|
|
|
ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
|
2019-05-30 19:43:34 +02:00
|
|
|
}
|
2020-09-17 00:45:30 +02:00
|
|
|
ASSERT_OK(Flush());
|
2019-05-30 19:43:34 +02:00
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10);
|
|
|
|
|
|
|
|
// In release 6.0, ttl was promoted from a secondary level option under
|
|
|
|
// compaction_options_fifo to a top level option under ColumnFamilyOptions.
|
|
|
|
// We still need to handle old SetOptions calls but should ignore
|
|
|
|
// ttl under compaction_options_fifo.
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
{{"compaction_options_fifo",
|
|
|
|
"{allow_compaction=true;max_table_files_size=1024;ttl=731;}"},
|
|
|
|
{"ttl", "60"}}));
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction,
|
|
|
|
true);
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size,
|
|
|
|
1024);
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 60);
|
|
|
|
|
|
|
|
// Put ttl as the first option inside compaction_options_fifo. That works as
|
|
|
|
// it doesn't overwrite any other option.
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
{{"compaction_options_fifo",
|
|
|
|
"{ttl=985;allow_compaction=true;max_table_files_size=1024;}"},
|
|
|
|
{"ttl", "191"}}));
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction,
|
|
|
|
true);
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size,
|
|
|
|
1024);
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 191);
|
|
|
|
}
|
|
|
|
|
2020-03-31 21:08:41 +02:00
|
|
|
TEST_F(DBOptionsTest, ChangeCompression) {
|
|
|
|
if (!Snappy_Supported() || !LZ4_Supported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Options options;
|
|
|
|
options.write_buffer_size = 10 << 10; // 10KB
|
|
|
|
options.level0_file_num_compaction_trigger = 2;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.compression = CompressionType::kLZ4Compression;
|
|
|
|
options.bottommost_compression = CompressionType::kNoCompression;
|
|
|
|
options.bottommost_compression_opts.level = 2;
|
2020-04-02 01:37:54 +02:00
|
|
|
options.bottommost_compression_opts.parallel_threads = 1;
|
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a MemoryFileSystem class (#7566)
Summary:
This PR does a few things:
1. The MockFileSystem class was split out from the MockEnv. This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one). The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.
2. Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set. To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).
3. Updated the test framework to have a ROCKSDB_GTEST_SKIP macro. This can be used to flag tests that are skipped. Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).
I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV, both, and neither under both MacOS and RedHat. A few tests were disabled/skipped for the MEM/ENCRYPTED cases. The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem. (I will also push a change to disable those tests soon). There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.
Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.
Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale. I do not know how to do that, so if someone could write that job, it would be appreciated :)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7566
Reviewed By: zhichao-cao
Differential Revision: D24408980
Pulled By: jay-zhuang
fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
2020-10-27 18:31:34 +01:00
|
|
|
options.env = CurrentOptions().env;
|
2020-03-31 21:08:41 +02:00
|
|
|
|
|
|
|
ASSERT_OK(TryReopen(options));
|
|
|
|
|
|
|
|
CompressionType compression_used = CompressionType::kLZ4Compression;
|
|
|
|
CompressionOptions compression_opt_used;
|
|
|
|
bool compacted = false;
|
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"LevelCompactionPicker::PickCompaction:Return", [&](void* arg) {
|
|
|
|
Compaction* c = reinterpret_cast<Compaction*>(arg);
|
|
|
|
compression_used = c->output_compression();
|
|
|
|
compression_opt_used = c->output_compression_opts();
|
|
|
|
compacted = true;
|
|
|
|
});
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
|
|
|
|
|
|
|
ASSERT_OK(Put("foo", "foofoofoo"));
|
|
|
|
ASSERT_OK(Put("bar", "foofoofoo"));
|
|
|
|
ASSERT_OK(Flush());
|
|
|
|
ASSERT_OK(Put("foo", "foofoofoo"));
|
|
|
|
ASSERT_OK(Put("bar", "foofoofoo"));
|
|
|
|
ASSERT_OK(Flush());
|
2020-09-25 06:47:43 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2020-03-31 21:08:41 +02:00
|
|
|
ASSERT_TRUE(compacted);
|
|
|
|
ASSERT_EQ(CompressionType::kNoCompression, compression_used);
|
|
|
|
ASSERT_EQ(options.compression_opts.level, compression_opt_used.level);
|
2020-04-02 01:37:54 +02:00
|
|
|
ASSERT_EQ(options.compression_opts.parallel_threads,
|
|
|
|
compression_opt_used.parallel_threads);
|
2020-03-31 21:08:41 +02:00
|
|
|
|
|
|
|
compression_used = CompressionType::kLZ4Compression;
|
|
|
|
compacted = false;
|
|
|
|
ASSERT_OK(dbfull()->SetOptions(
|
|
|
|
{{"bottommost_compression", "kSnappyCompression"},
|
2020-05-01 01:59:16 +02:00
|
|
|
{"bottommost_compression_opts", "0:6:0:0:4:true"}}));
|
2020-03-31 21:08:41 +02:00
|
|
|
ASSERT_OK(Put("foo", "foofoofoo"));
|
|
|
|
ASSERT_OK(Put("bar", "foofoofoo"));
|
|
|
|
ASSERT_OK(Flush());
|
|
|
|
ASSERT_OK(Put("foo", "foofoofoo"));
|
|
|
|
ASSERT_OK(Put("bar", "foofoofoo"));
|
|
|
|
ASSERT_OK(Flush());
|
2020-09-25 06:47:43 +02:00
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
2020-03-31 21:08:41 +02:00
|
|
|
ASSERT_TRUE(compacted);
|
|
|
|
ASSERT_EQ(CompressionType::kSnappyCompression, compression_used);
|
|
|
|
ASSERT_EQ(6, compression_opt_used.level);
|
2020-05-01 01:59:16 +02:00
|
|
|
// Right now parallel_level is not yet allowed to be changed.
|
2020-03-31 21:08:41 +02:00
|
|
|
|
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
}
|
|
|
|
|
2020-04-03 01:39:18 +02:00
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
2020-11-12 05:30:58 +01:00
|
|
|
TEST_F(DBOptionsTest, BottommostCompressionOptsWithFallbackType) {
|
|
|
|
// Verify the bottommost compression options still take effect even when the
|
|
|
|
// bottommost compression type is left at its default value. Verify for both
|
|
|
|
// automatic and manual compaction.
|
|
|
|
if (!Snappy_Supported() || !LZ4_Supported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr int kUpperCompressionLevel = 1;
|
|
|
|
constexpr int kBottommostCompressionLevel = 2;
|
|
|
|
constexpr int kNumL0Files = 2;
|
|
|
|
|
|
|
|
Options options = CurrentOptions();
|
|
|
|
options.level0_file_num_compaction_trigger = kNumL0Files;
|
|
|
|
options.compression = CompressionType::kLZ4Compression;
|
|
|
|
options.compression_opts.level = kUpperCompressionLevel;
|
|
|
|
options.bottommost_compression_opts.level = kBottommostCompressionLevel;
|
|
|
|
options.bottommost_compression_opts.enabled = true;
|
|
|
|
Reopen(options);
|
|
|
|
|
|
|
|
CompressionType compression_used = CompressionType::kDisableCompressionOption;
|
|
|
|
CompressionOptions compression_opt_used;
|
|
|
|
bool compacted = false;
|
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"CompactionPicker::RegisterCompaction:Registered", [&](void* arg) {
|
|
|
|
Compaction* c = static_cast<Compaction*>(arg);
|
|
|
|
compression_used = c->output_compression();
|
|
|
|
compression_opt_used = c->output_compression_opts();
|
|
|
|
compacted = true;
|
|
|
|
});
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
|
|
|
|
|
|
|
// First, verify for automatic compaction.
|
|
|
|
for (int i = 0; i < kNumL0Files; ++i) {
|
|
|
|
ASSERT_OK(Put("foo", "foofoofoo"));
|
|
|
|
ASSERT_OK(Put("bar", "foofoofoo"));
|
|
|
|
ASSERT_OK(Flush());
|
|
|
|
}
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
|
|
|
|
|
|
|
ASSERT_TRUE(compacted);
|
|
|
|
ASSERT_EQ(CompressionType::kLZ4Compression, compression_used);
|
|
|
|
ASSERT_EQ(kBottommostCompressionLevel, compression_opt_used.level);
|
|
|
|
|
|
|
|
// Second, verify for manual compaction.
|
|
|
|
compacted = false;
|
|
|
|
compression_used = CompressionType::kDisableCompressionOption;
|
|
|
|
compression_opt_used = CompressionOptions();
|
|
|
|
CompactRangeOptions cro;
|
|
|
|
cro.bottommost_level_compaction = BottommostLevelCompaction::kForceOptimized;
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(cro, nullptr, nullptr));
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
|
|
|
|
|
|
|
|
ASSERT_TRUE(compacted);
|
|
|
|
ASSERT_EQ(CompressionType::kLZ4Compression, compression_used);
|
|
|
|
ASSERT_EQ(kBottommostCompressionLevel, compression_opt_used.level);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2016-07-13 00:30:38 +02:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2016-07-13 00:30:38 +02:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|