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

Fixed dynamic resize target_file_size_base bug #368

Merged
merged 2 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Config::Config() {
{"rocksdb.max_open_files", false, new IntField(&RocksDB.max_open_files, 4096, -1, INT_MAX)},
{"rocksdb.write_buffer_size", false, new IntField(&RocksDB.write_buffer_size, 64, 0, 4096)},
{"rocksdb.max_write_buffer_number", false, new IntField(&RocksDB.max_write_buffer_number, 4, 0, 256)},
{"rocksdb.target_file_size_base", true, new IntField(&RocksDB.target_file_size_base, 128, 1, 1024)},
{"rocksdb.target_file_size_base", false, new IntField(&RocksDB.target_file_size_base, 128, 1, 1024)},
{"rocksdb.max_background_compactions", false, new IntField(&RocksDB.max_background_compactions, 2, 0, 32)},
{"rocksdb.max_background_flushes", true, new IntField(&RocksDB.max_background_flushes, 2, 0, 32)},
{"rocksdb.max_sub_compactions", false, new IntField(&RocksDB.max_sub_compactions, 1, 0, 16)},
Expand Down Expand Up @@ -295,6 +295,11 @@ void Config::initFieldCallback() {
srv->GetPerfLog()->SetMaxEntries(profiling_sample_record_max_len);
return Status::OK();
}},
{"rocksdb.target_file_size_base", [this](Server* srv, const std::string &k, const std::string& v)->Status {
if (!srv) return Status::OK();
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k),
std::to_string(RocksDB.target_file_size_base * MiB));
}},
{"rocksdb.write_buffer_size", [this](Server* srv, const std::string &k, const std::string& v)->Status {
if (!srv) return Status::OK();
return srv->storage_->SetColumnFamilyOption(trimRocksDBPrefix(k),
Expand Down
6 changes: 3 additions & 3 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,10 @@ Status Server::autoResizeBlockAndSST() {
return Status::OK();
}
if (target_file_size_base != config_->RocksDB.target_file_size_base) {
auto s = storage_->SetOption("target_file_size_base", std::to_string(target_file_size_base * MiB));
auto old_target_file_size_base = config_->RocksDB.target_file_size_base;
auto s = config_->Set(this, "rocksdb.target_file_size_base", std::to_string(target_file_size_base));
LOG(INFO) << "[server] Resize rocksdb.target_file_size_base from "
<< config_->RocksDB.target_file_size_base
<< old_target_file_size_base
<< " to " << target_file_size_base
<< ", average_kv_size: " << average_kv_size
<< ", total_size: " << total_size
Expand All @@ -1065,7 +1066,6 @@ Status Server::autoResizeBlockAndSST() {
if (!s.IsOK()) {
return s;
}
config_->RocksDB.target_file_size_base = target_file_size_base;
}
if (target_file_size_base != config_->RocksDB.write_buffer_size) {
auto old_write_buffer_size = config_->RocksDB.write_buffer_size;
Expand Down
2 changes: 1 addition & 1 deletion tests/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TEST(Config, GetAndSet) {
{"rocksdb.max_open_files" , "1234"},
{"rocksdb.write_buffer_size" , "1234"},
{"rocksdb.max_write_buffer_number" , "1"},
{"rocksdb.target_file_size_base", "100"},
{"rocksdb.max_background_compactions" , "2"},
{"rocksdb.max_sub_compactions" , "3"},
{"rocksdb.delayed_write_rate" , "1234"},
Expand Down Expand Up @@ -79,7 +80,6 @@ TEST(Config, GetAndSet) {
{"pidfile", "test.pid"},
{"supervised", "no"},
{"rocksdb.block_size", "1234"},
{"rocksdb.target_file_size_base", "100"},
{"rocksdb.max_background_flushes", "16"},
{"rocksdb.wal_ttl_seconds", "10000"},
{"rocksdb.wal_size_limit_mb", "16"},
Expand Down