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 22 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ version.h
Makefile.dep
make_config.mk
.vscode
kvrocks2redis
kvrocks2redis

src/compactdb/
src/testsdb/
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 26 additions & 2 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ rocksdb.cache_index_and_filter_blocks yes
# than 2 to improve performance.
# Accept value: "no", "snappy"
# default snappy
rocksdb.compression snappy
rocksdb.compression no

# If non-zero, we perform bigger reads when doing compaction. If you're
# running RocksDB on spinning disks, you should set this to at least 2MB.
Expand Down Expand Up @@ -597,6 +597,30 @@ rocksdb.enable_blob_garbage_collection yes
# Default: 25
rocksdb.blob_garbage_collection_age_cutoff 25


# The purpose of following three options are 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: no
rocksdb.level_compaction_dynamic_level_bytes no

# The total file size of level-1 sst.
#
# Default: 256 M
rocksdb.max_bytes_for_level_base 268435456
WyattJia marked this conversation as resolved.
Show resolved Hide resolved

# Multiplication factor for the total file size of L(n+1) layers.
# This option 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
rocksdb.max_bytes_for_level_multiplier 10

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

35 changes: 34 additions & 1 deletion src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ 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 yes first.";

configEnum compression_type_enum[] = {
{"no", rocksdb::CompressionType::kNoCompression},
{"snappy", rocksdb::CompressionType::kSnappyCompression},
{nullptr, 0}
};

configEnum supervised_mode_enum[] = {
{"no", SUPERVISED_NONE},
{"auto", SUPERVISED_AUTODETECT},
Expand Down Expand Up @@ -145,7 +149,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, 268435456, 0, INT16_MAX)},
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 +413,30 @@ 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.level_compaction_dynamic_level_bytes", [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);
}
Comment on lines +436 to +438
Copy link
Member

Choose a reason for hiding this comment

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

this judgement is necessary? a mistake?

std::string enable_blob_garbage_collection = v == "yes" ? "true" : "false";
WyattJia marked this conversation as resolved.
Show resolved Hide resolved
return srv->storage_->SetDBOption(trimRocksDBPrefix(k), enable_blob_garbage_collection);
}},
{"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 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", "268435456"},
{"rocksdb.max_bytes_for_level_multiplier", "10"},
{"rocksdb.level_compaction_dynamic_level_bytes", "yes"},
};
std::vector<std::string> values;
for (const auto &iter : mutable_cases) {
Expand Down