Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamically adjust the upper limit of the data that each layer configure option. #497

Merged
merged 30 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b3e1fb3
Update Rocksdb options, enable level_compaction_dynamic_level_bytes f…
WyattJia Feb 24, 2022
bd2e708
Merge pull request #1 from WyattJia/max_bytes_for_level_base
WyattJia Feb 24, 2022
eacb3ea
Format config.cc.
WyattJia Feb 25, 2022
bf8c93f
Lint config.cc, remove useless comma.
WyattJia Feb 25, 2022
8aa0025
Update conf, rewrite levels target size option comments.
WyattJia Feb 25, 2022
d156b9c
Update level_compaction_dynamic_level_bytes config load.
WyattJia Feb 25, 2022
d5aa2f5
Update kvrocks.conf
WyattJia Feb 25, 2022
d432188
Update kvrocks.conf
WyattJia Feb 25, 2022
335c033
Update kvrocks.conf
WyattJia Feb 25, 2022
612e690
Update levels target size option comments.
WyattJia Feb 25, 2022
de62f14
Update levels target size option comments.
WyattJia Feb 25, 2022
dceca92
Update level_compaction_dynamic_level_bytes config load.
WyattJia Feb 25, 2022
d78c3df
Fix level_compaction_dynamic_level_bytes conf value error.
WyattJia Feb 25, 2022
14a728c
Lint config.cc
WyattJia Feb 25, 2022
d4553b4
Update src/config.cc
git-hulk Feb 25, 2022
f1c8a95
Enable lz4 and zstd compression algorithms.
WyattJia Feb 25, 2022
c30aa27
Fix configura option unit error.
WyattJia Feb 25, 2022
c3f970e
Update src/config.cc
git-hulk Feb 25, 2022
77070db
Revert 267b45ee886, add compression algorithum.
WyattJia Feb 25, 2022
27df4cb
Fix configura option unit error.
WyattJia Feb 25, 2022
30646b7
Revert blob_file_size default unit error.
WyattJia Feb 25, 2022
31e8773
Update tests/config_test.cc
git-hulk Feb 25, 2022
278a3c1
Update src/config.cc
git-hulk Feb 25, 2022
c73f2cf
Update src/config.cc
git-hulk Feb 25, 2022
31eb562
Update .gitignore
WyattJia Feb 28, 2022
d2f7ad2
Update config.cc
WyattJia Feb 28, 2022
4fc9bbf
Update kvrocks.conf
WyattJia Feb 28, 2022
a35ad25
Update kvrocks.conf
WyattJia Feb 28, 2022
b695d71
Update max_bytes_for_level_base unit bytes to MiB.
WyattJia Mar 6, 2022
004c97e
Fix config.cc, max_bytes_for_level_base unit bytes to MiB.
WyattJia Mar 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,28 @@ rocksdb.enable_blob_garbage_collection yes
# Default: 25
rocksdb.blob_garbage_collection_age_cutoff 25


# The purpose of this option is to dynamically adjust the upper limit of
# the data that each layer can store according to the size of the different
# layers of the LSM. Enabling this option will bring some improvements in
# deletion efficiency and space amplification, but it will lose a certain
# amount of read performance.
# If you want know more detail about Levels' Target Size, you can read RocksDB wiki:
# https://github.com/facebook/rocksdb/wiki/Leveled-Compaction#levels-target-size
#
# Default False
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
rocksdb.level_compaction_dynamic_level_bytes false

# Default 256 M
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
rocksdb.max_bytes_for_level_base 256
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this config has bytes word, we should use byte unit, right? or we rename it to level_base_size? maybe rocksdb name is better?

This commit is not released in newest version, we have chances to change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also think bytes is better.


# This configuration value is a double type number in RocksDB,
# but kvrocks is not support double data type number yet,
# so we use int data number instead of double currently.
#
# Default 10
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
rocksdb.max_bytes_for_level_multiplier 10

################################ NAMESPACE #####################################
# namespace.test change.me

27 changes: 25 additions & 2 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const char *kDefaultNamespace = "__namespace";

const char *errNotEnableBlobDB = "Must set rocksdb.enable_blob_files to yes first.";

const char *errNotSetLevelCompactionDynamicLevelBytes = "Must set rocksdb.level_compaction_dynamic_level_bytes.";

configEnum compression_type_enum[] = {
{"no", rocksdb::CompressionType::kNoCompression},
{"snappy", rocksdb::CompressionType::kSnappyCompression},
Expand Down Expand Up @@ -145,7 +147,12 @@ Config::Config() {
{"rocksdb.blob_file_size", false, new IntField(&RocksDB.blob_file_size, 128, 0, INT_MAX)},
{"rocksdb.enable_blob_garbage_collection", false, new YesNoField(&RocksDB.enable_blob_garbage_collection, true)},
{"rocksdb.blob_garbage_collection_age_cutoff",
false, new IntField(&RocksDB.blob_garbage_collection_age_cutoff, 25, 0, 100)}
false, new IntField(&RocksDB.blob_garbage_collection_age_cutoff, 25, 0, 100)},
{"rocksdb.max_bytes_for_level_base", false, new IntField(&RocksDB.max_bytes_for_level_base, 256, 0, INT16_MAX)},
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
{"rocksdb.max_bytes_for_level_multiplier",
false, new IntField(&RocksDB.max_bytes_for_level_multiplier, 10, 1, 100)},
{"rocksdb.level_compaction_dynamic_level_bytes",
false, new YesNoField(&RocksDB.level_compaction_dynamic_level_bytes, false)},
};
for (const auto &wrapper : fields) {
auto field = wrapper.field;
Expand Down Expand Up @@ -404,6 +411,21 @@ void Config::initFieldCallback() {
double cutoff = val / 100;
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), std::to_string(cutoff));
}},
{"rocksdb.max_bytes_for_level_base", [this](Server* srv, const std::string &k, const std::string& v)->Status {
if (!srv) return Status::OK();
if (!RocksDB.level_compaction_dynamic_level_bytes) {
return Status(Status::NotOK, errNotSetLevelCompactionDynamicLevelBytes);
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), v);
}},
{"rocksdb.max_bytes_for_level_multiplier", [this](Server* srv, const std::string &k,
const std::string& v)->Status {
if (!srv) return Status::OK();
if (!RocksDB.level_compaction_dynamic_level_bytes) {
return Status(Status::NotOK, errNotSetLevelCompactionDynamicLevelBytes);
}
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k), v);
}},
{"rocksdb.max_open_files", set_db_option_cb},
{"rocksdb.stats_dump_period_sec", set_db_option_cb},
{"rocksdb.delayed_write_rate", set_db_option_cb},
Expand All @@ -414,7 +436,8 @@ void Config::initFieldCallback() {
{"rocksdb.max_write_buffer_number", set_cf_option_cb},
{"rocksdb.level0_slowdown_writes_trigger", set_cf_option_cb},
{"rocksdb.level0_stop_writes_trigger", set_cf_option_cb},
{"rocksdb.level0_file_num_compaction_trigger", set_cf_option_cb}
{"rocksdb.level0_file_num_compaction_trigger", set_cf_option_cb},
{"rocksdb.level_compaction_dynamic_level_bytes", set_cf_option_cb}
};
for (const auto& iter : callbacks) {
auto field_iter = fields_.find(iter.first);
Expand Down
3 changes: 3 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ struct Config{
int blob_file_size;
bool enable_blob_garbage_collection;
int blob_garbage_collection_age_cutoff;
int max_bytes_for_level_base;
int max_bytes_for_level_multiplier;
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
bool level_compaction_dynamic_level_bytes;
} RocksDB;

public:
Expand Down
3 changes: 3 additions & 0 deletions src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ void Storage::InitOptions(rocksdb::Options *options) {
options->level0_slowdown_writes_trigger = config_->RocksDB.level0_slowdown_writes_trigger;
options->level0_stop_writes_trigger = config_->RocksDB.level0_stop_writes_trigger;
options->level0_file_num_compaction_trigger = config_->RocksDB.level0_file_num_compaction_trigger;
options->max_bytes_for_level_base = config_->RocksDB.max_bytes_for_level_base;
options->max_bytes_for_level_multiplier = config_->RocksDB.max_bytes_for_level_multiplier;
options->level_compaction_dynamic_level_bytes = config_->RocksDB.level_compaction_dynamic_level_bytes;
}

Status Storage::SetColumnFamilyOption(const std::string &key, const std::string &value) {
Expand Down
3 changes: 3 additions & 0 deletions tests/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ TEST(Config, GetAndSet) {
{"rocksdb.blob_file_size", "128"},
{"rocksdb.enable_blob_garbage_collection", "yes"},
{"rocksdb.blob_garbage_collection_age_cutoff", "25"},
{"rocksdb.max_bytes_for_level_base", "128"},
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
{"rocksdb.max_bytes_for_level_multiplier", "10"},
{"rocksdb.level_compaction_dynamic_level_bytes", "false"},
};
std::vector<std::string> values;
for (const auto &iter : mutable_cases) {
Expand Down