2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-10-31 16:48:19 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "db/version_edit.h"
|
|
|
|
#include "db/version_set.h"
|
2019-06-01 02:19:43 +02:00
|
|
|
#include "logging/logging.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_util/testutil.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/string_util.h"
|
2014-10-31 16:48:19 +01:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
class VersionBuilderTest : public testing::Test {
|
2014-10-31 16:48:19 +01:00
|
|
|
public:
|
2014-11-11 23:28:18 +01:00
|
|
|
const Comparator* ucmp_;
|
|
|
|
InternalKeyComparator icmp_;
|
|
|
|
Options options_;
|
|
|
|
ImmutableCFOptions ioptions_;
|
|
|
|
MutableCFOptions mutable_cf_options_;
|
|
|
|
VersionStorageInfo vstorage_;
|
|
|
|
uint32_t file_num_;
|
|
|
|
CompactionOptionsFIFO fifo_options_;
|
|
|
|
std::vector<uint64_t> size_being_compacted_;
|
2014-10-31 16:48:19 +01:00
|
|
|
|
|
|
|
VersionBuilderTest()
|
2014-11-11 23:28:18 +01:00
|
|
|
: ucmp_(BytewiseComparator()),
|
|
|
|
icmp_(ucmp_),
|
|
|
|
ioptions_(options_),
|
2016-09-14 06:11:59 +02:00
|
|
|
mutable_cf_options_(options_),
|
2014-11-11 23:28:18 +01:00
|
|
|
vstorage_(&icmp_, ucmp_, options_.num_levels, kCompactionStyleLevel,
|
2016-10-08 02:21:45 +02:00
|
|
|
nullptr, false),
|
2014-11-11 23:28:18 +01:00
|
|
|
file_num_(1) {
|
|
|
|
mutable_cf_options_.RefreshDerivedOptions(ioptions_);
|
|
|
|
size_being_compacted_.resize(options_.num_levels);
|
2014-10-31 16:48:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 22:36:04 +01:00
|
|
|
~VersionBuilderTest() override {
|
2014-11-11 23:28:18 +01:00
|
|
|
for (int i = 0; i < vstorage_.num_levels(); i++) {
|
|
|
|
for (auto* f : vstorage_.LevelFiles(i)) {
|
2014-10-31 16:48:19 +01:00
|
|
|
if (--f->refs == 0) {
|
|
|
|
delete f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalKey GetInternalKey(const char* ukey,
|
|
|
|
SequenceNumber smallest_seq = 100) {
|
|
|
|
return InternalKey(ukey, smallest_seq, kTypeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(int level, uint32_t file_number, const char* smallest,
|
|
|
|
const char* largest, uint64_t file_size = 0, uint32_t path_id = 0,
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
SequenceNumber smallest_seq = 100, SequenceNumber largest_seq = 100,
|
2014-11-11 23:28:18 +01:00
|
|
|
uint64_t num_entries = 0, uint64_t num_deletions = 0,
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
bool sampled = false, SequenceNumber smallest_seqno = 0,
|
|
|
|
SequenceNumber largest_seqno = 0) {
|
2014-11-11 23:28:18 +01:00
|
|
|
assert(level < vstorage_.num_levels());
|
2019-10-15 00:19:31 +02:00
|
|
|
FileMetaData* f = new FileMetaData(
|
|
|
|
file_number, path_id, file_size, GetInternalKey(smallest, smallest_seq),
|
|
|
|
GetInternalKey(largest, largest_seq), smallest_seqno, largest_seqno,
|
2019-11-23 01:01:21 +01:00
|
|
|
/* marked_for_compact */ false, kInvalidBlobFileNumber,
|
|
|
|
kUnknownOldestAncesterTime);
|
2014-10-31 16:48:19 +01:00
|
|
|
f->compensated_file_size = file_size;
|
2014-11-11 23:28:18 +01:00
|
|
|
f->num_entries = num_entries;
|
|
|
|
f->num_deletions = num_deletions;
|
2014-11-13 22:41:43 +01:00
|
|
|
vstorage_.AddFile(level, f);
|
2014-11-11 23:28:18 +01:00
|
|
|
if (sampled) {
|
|
|
|
f->init_stats_from_file = true;
|
|
|
|
vstorage_.UpdateAccumulatedStats(f);
|
|
|
|
}
|
2014-10-31 16:48:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateVersionStorageInfo() {
|
2016-09-14 06:11:59 +02:00
|
|
|
vstorage_.UpdateFilesByCompactionPri(ioptions_.compaction_pri);
|
2014-11-11 23:28:18 +01:00
|
|
|
vstorage_.UpdateNumNonEmptyLevels();
|
|
|
|
vstorage_.GenerateFileIndexer();
|
|
|
|
vstorage_.GenerateLevelFilesBrief();
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
vstorage_.CalculateBaseBytes(ioptions_, mutable_cf_options_);
|
Allowing L0 -> L1 trivial move on sorted data
Summary:
This diff updates the logic of how we do trivial move, now trivial move can run on any number of files in input level as long as they are not overlapping
The conditions for trivial move have been updated
Introduced conditions:
- Trivial move cannot happen if we have a compaction filter (except if the compaction is not manual)
- Input level files cannot be overlapping
Removed conditions:
- Trivial move only run when the compaction is not manual
- Input level should can contain only 1 file
More context on what tests failed because of Trivial move
```
DBTest.CompactionsGenerateMultipleFiles
This test is expecting compaction on a file in L0 to generate multiple files in L1, this test will fail with trivial move because we end up with one file in L1
```
```
DBTest.NoSpaceCompactRange
This test expect compaction to fail when we force environment to report running out of space, of course this is not valid in trivial move situation
because trivial move does not need any extra space, and did not check for that
```
```
DBTest.DropWrites
Similar to DBTest.NoSpaceCompactRange
```
```
DBTest.DeleteObsoleteFilesPendingOutputs
This test expect that a file in L2 is deleted after it's moved to L3, this is not valid with trivial move because although the file was moved it is now used by L3
```
```
CuckooTableDBTest.CompactionIntoMultipleFiles
Same as DBTest.CompactionsGenerateMultipleFiles
```
This diff is based on a work by @sdong https://reviews.facebook.net/D34149
Test Plan: make -j64 check
Reviewers: rven, sdong, igor
Reviewed By: igor
Subscribers: yhchiang, ott, march, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D34797
2015-06-05 01:51:25 +02:00
|
|
|
vstorage_.GenerateLevel0NonOverlapping();
|
2014-11-11 23:28:18 +01:00
|
|
|
vstorage_.SetFinalized();
|
2014-10-31 16:48:19 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
void UnrefFilesInVersion(VersionStorageInfo* new_vstorage) {
|
|
|
|
for (int i = 0; i < new_vstorage->num_levels(); i++) {
|
|
|
|
for (auto* f : new_vstorage->LevelFiles(i)) {
|
|
|
|
if (--f->refs == 0) {
|
|
|
|
delete f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, ApplyAndSaveTo) {
|
2014-10-31 16:48:19 +01:00
|
|
|
Add(0, 1U, "150", "200", 100U);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
|
2014-10-31 16:48:19 +01:00
|
|
|
Add(1, 66U, "150", "200", 100U);
|
|
|
|
Add(1, 88U, "201", "300", 100U);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
|
2014-10-31 16:48:19 +01:00
|
|
|
Add(2, 6U, "150", "179", 100U);
|
|
|
|
Add(2, 7U, "180", "220", 100U);
|
|
|
|
Add(2, 8U, "221", "300", 100U);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
|
2014-10-31 16:48:19 +01:00
|
|
|
Add(3, 26U, "150", "170", 100U);
|
|
|
|
Add(3, 27U, "171", "179", 100U);
|
|
|
|
Add(3, 28U, "191", "220", 100U);
|
|
|
|
Add(3, 29U, "221", "300", 100U);
|
|
|
|
UpdateVersionStorageInfo();
|
|
|
|
|
|
|
|
VersionEdit version_edit;
|
|
|
|
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("350"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2014-10-31 16:48:19 +01:00
|
|
|
version_edit.DeleteFile(3, 27U);
|
|
|
|
|
|
|
|
EnvOptions env_options;
|
|
|
|
|
2014-11-11 23:28:18 +01:00
|
|
|
VersionBuilder version_builder(env_options, nullptr, &vstorage_);
|
2014-10-31 16:48:19 +01:00
|
|
|
|
2014-11-11 23:28:18 +01:00
|
|
|
VersionStorageInfo new_vstorage(&icmp_, ucmp_, options_.num_levels,
|
2016-10-08 02:21:45 +02:00
|
|
|
kCompactionStyleLevel, nullptr, false);
|
2014-10-31 16:48:19 +01:00
|
|
|
version_builder.Apply(&version_edit);
|
|
|
|
version_builder.SaveTo(&new_vstorage);
|
|
|
|
|
|
|
|
ASSERT_EQ(400U, new_vstorage.NumLevelBytes(2));
|
|
|
|
ASSERT_EQ(300U, new_vstorage.NumLevelBytes(3));
|
|
|
|
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
UnrefFilesInVersion(&new_vstorage);
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, ApplyAndSaveToDynamic) {
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
ioptions_.level_compaction_dynamic_level_bytes = true;
|
|
|
|
|
|
|
|
Add(0, 1U, "150", "200", 100U, 0, 200U, 200U, 0, 0, false, 200U, 200U);
|
|
|
|
Add(0, 88U, "201", "300", 100U, 0, 100U, 100U, 0, 0, false, 100U, 100U);
|
|
|
|
|
|
|
|
Add(4, 6U, "150", "179", 100U);
|
|
|
|
Add(4, 7U, "180", "220", 100U);
|
|
|
|
Add(4, 8U, "221", "300", 100U);
|
|
|
|
|
|
|
|
Add(5, 26U, "150", "170", 100U);
|
|
|
|
Add(5, 27U, "171", "179", 100U);
|
|
|
|
UpdateVersionStorageInfo();
|
|
|
|
|
|
|
|
VersionEdit version_edit;
|
|
|
|
version_edit.AddFile(3, 666, 0, 100U, GetInternalKey("301"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("350"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
version_edit.DeleteFile(0, 1U);
|
|
|
|
version_edit.DeleteFile(0, 88U);
|
|
|
|
|
|
|
|
EnvOptions env_options;
|
|
|
|
|
|
|
|
VersionBuilder version_builder(env_options, nullptr, &vstorage_);
|
|
|
|
|
|
|
|
VersionStorageInfo new_vstorage(&icmp_, ucmp_, options_.num_levels,
|
2016-10-08 02:21:45 +02:00
|
|
|
kCompactionStyleLevel, nullptr, false);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
version_builder.Apply(&version_edit);
|
|
|
|
version_builder.SaveTo(&new_vstorage);
|
|
|
|
|
|
|
|
ASSERT_EQ(0U, new_vstorage.NumLevelBytes(0));
|
|
|
|
ASSERT_EQ(100U, new_vstorage.NumLevelBytes(3));
|
|
|
|
ASSERT_EQ(300U, new_vstorage.NumLevelBytes(4));
|
|
|
|
ASSERT_EQ(200U, new_vstorage.NumLevelBytes(5));
|
|
|
|
|
|
|
|
UnrefFilesInVersion(&new_vstorage);
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, ApplyAndSaveToDynamic2) {
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
ioptions_.level_compaction_dynamic_level_bytes = true;
|
|
|
|
|
|
|
|
Add(0, 1U, "150", "200", 100U, 0, 200U, 200U, 0, 0, false, 200U, 200U);
|
|
|
|
Add(0, 88U, "201", "300", 100U, 0, 100U, 100U, 0, 0, false, 100U, 100U);
|
|
|
|
|
|
|
|
Add(4, 6U, "150", "179", 100U);
|
|
|
|
Add(4, 7U, "180", "220", 100U);
|
|
|
|
Add(4, 8U, "221", "300", 100U);
|
|
|
|
|
|
|
|
Add(5, 26U, "150", "170", 100U);
|
|
|
|
Add(5, 27U, "171", "179", 100U);
|
|
|
|
UpdateVersionStorageInfo();
|
|
|
|
|
|
|
|
VersionEdit version_edit;
|
|
|
|
version_edit.AddFile(4, 666, 0, 100U, GetInternalKey("301"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("350"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
version_edit.DeleteFile(0, 1U);
|
|
|
|
version_edit.DeleteFile(0, 88U);
|
|
|
|
version_edit.DeleteFile(4, 6U);
|
|
|
|
version_edit.DeleteFile(4, 7U);
|
|
|
|
version_edit.DeleteFile(4, 8U);
|
|
|
|
|
|
|
|
EnvOptions env_options;
|
|
|
|
|
|
|
|
VersionBuilder version_builder(env_options, nullptr, &vstorage_);
|
|
|
|
|
|
|
|
VersionStorageInfo new_vstorage(&icmp_, ucmp_, options_.num_levels,
|
2016-10-08 02:21:45 +02:00
|
|
|
kCompactionStyleLevel, nullptr, false);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
version_builder.Apply(&version_edit);
|
|
|
|
version_builder.SaveTo(&new_vstorage);
|
|
|
|
|
|
|
|
ASSERT_EQ(0U, new_vstorage.NumLevelBytes(0));
|
|
|
|
ASSERT_EQ(100U, new_vstorage.NumLevelBytes(4));
|
|
|
|
ASSERT_EQ(200U, new_vstorage.NumLevelBytes(5));
|
|
|
|
|
|
|
|
UnrefFilesInVersion(&new_vstorage);
|
2015-01-07 19:29:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, ApplyMultipleAndSaveTo) {
|
2015-01-07 19:29:21 +01:00
|
|
|
UpdateVersionStorageInfo();
|
|
|
|
|
|
|
|
VersionEdit version_edit;
|
|
|
|
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("350"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("450"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("650"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("550"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("750"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
|
|
|
|
EnvOptions env_options;
|
|
|
|
|
|
|
|
VersionBuilder version_builder(env_options, nullptr, &vstorage_);
|
|
|
|
|
|
|
|
VersionStorageInfo new_vstorage(&icmp_, ucmp_, options_.num_levels,
|
2016-10-08 02:21:45 +02:00
|
|
|
kCompactionStyleLevel, nullptr, false);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_builder.Apply(&version_edit);
|
|
|
|
version_builder.SaveTo(&new_vstorage);
|
|
|
|
|
|
|
|
ASSERT_EQ(500U, new_vstorage.NumLevelBytes(2));
|
|
|
|
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
UnrefFilesInVersion(&new_vstorage);
|
2015-01-07 19:29:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, ApplyDeleteAndSaveTo) {
|
2015-01-07 19:29:21 +01:00
|
|
|
UpdateVersionStorageInfo();
|
|
|
|
|
|
|
|
EnvOptions env_options;
|
|
|
|
VersionBuilder version_builder(env_options, nullptr, &vstorage_);
|
|
|
|
VersionStorageInfo new_vstorage(&icmp_, ucmp_, options_.num_levels,
|
2016-10-08 02:21:45 +02:00
|
|
|
kCompactionStyleLevel, nullptr, false);
|
2015-01-07 19:29:21 +01:00
|
|
|
|
|
|
|
VersionEdit version_edit;
|
|
|
|
version_edit.AddFile(2, 666, 0, 100U, GetInternalKey("301"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("350"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 676, 0, 100U, GetInternalKey("401"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("450"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 636, 0, 100U, GetInternalKey("601"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("650"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 616, 0, 100U, GetInternalKey("501"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("550"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit.AddFile(2, 606, 0, 100U, GetInternalKey("701"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("750"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_builder.Apply(&version_edit);
|
|
|
|
|
|
|
|
VersionEdit version_edit2;
|
|
|
|
version_edit.AddFile(2, 808, 0, 100U, GetInternalKey("901"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("950"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_edit2.DeleteFile(2, 616);
|
|
|
|
version_edit2.DeleteFile(2, 636);
|
|
|
|
version_edit.AddFile(2, 806, 0, 100U, GetInternalKey("801"),
|
2019-10-15 00:19:31 +02:00
|
|
|
GetInternalKey("850"), 200, 200, false,
|
2019-11-23 01:01:21 +01:00
|
|
|
kInvalidBlobFileNumber, kUnknownOldestAncesterTime);
|
2015-01-07 19:29:21 +01:00
|
|
|
version_builder.Apply(&version_edit2);
|
|
|
|
|
|
|
|
version_builder.SaveTo(&new_vstorage);
|
|
|
|
|
|
|
|
ASSERT_EQ(300U, new_vstorage.NumLevelBytes(2));
|
|
|
|
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 20:44:17 +01:00
|
|
|
UnrefFilesInVersion(&new_vstorage);
|
2014-10-31 16:48:19 +01:00
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(VersionBuilderTest, EstimatedActiveKeys) {
|
2014-11-12 00:22:06 +01:00
|
|
|
const uint32_t kTotalSamples = 20;
|
|
|
|
const uint32_t kNumLevels = 5;
|
|
|
|
const uint32_t kFilesPerLevel = 8;
|
|
|
|
const uint32_t kNumFiles = kNumLevels * kFilesPerLevel;
|
|
|
|
const uint32_t kEntriesPerFile = 1000;
|
|
|
|
const uint32_t kDeletionsPerFile = 100;
|
|
|
|
for (uint32_t i = 0; i < kNumFiles; ++i) {
|
|
|
|
Add(static_cast<int>(i / kFilesPerLevel), i + 1,
|
2014-11-25 05:44:49 +01:00
|
|
|
ToString((i + 100) * 1000).c_str(),
|
|
|
|
ToString((i + 100) * 1000 + 999).c_str(),
|
2014-11-11 23:28:18 +01:00
|
|
|
100U, 0, 100, 100,
|
|
|
|
kEntriesPerFile, kDeletionsPerFile,
|
|
|
|
(i < kTotalSamples));
|
|
|
|
}
|
|
|
|
// minus 2X for the number of deletion entries because:
|
|
|
|
// 1x for deletion entry does not count as a data entry.
|
|
|
|
// 1x for each deletion entry will actually remove one data entry.
|
|
|
|
ASSERT_EQ(vstorage_.GetEstimatedActiveKeys(),
|
|
|
|
(kEntriesPerFile - 2 * kDeletionsPerFile) * kNumFiles);
|
|
|
|
}
|
|
|
|
|
2014-10-31 16:48:19 +01:00
|
|
|
} // namespace rocksdb
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|