Skip to content

Commit

Permalink
Reply to empiredan's suggestion and modify my code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruojieranyishen committed Jul 30, 2023
1 parent bf75036 commit 31886f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/base/pegasus_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "pegasus_const.h"

#include <fmt/core.h>
#include <rocksdb/options.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -144,11 +143,11 @@ const std::unordered_map<std::string, cf_opts_setter> cf_opts_setters = {
const std::unordered_map<std::string, cf_opts_getter> cf_opts_getters = {
{ROCKSDB_WRITE_BUFFER_SIZE,
[](const rocksdb::ColumnFamilyOptions &option, /*out*/ std::string &str) {
str = fmt::format("{}", option.write_buffer_size);
str = std::to_string(option.write_buffer_size);
}},
{ROCKSDB_NUM_LEVELS,
[](const rocksdb::ColumnFamilyOptions &option, /*out*/ std::string &str) {
str = fmt::format("{}", option.num_levels);
str = std::to_string(option.num_levels);
}},
};
} // namespace pegasus
25 changes: 9 additions & 16 deletions src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ void pegasus_server_impl::update_rocksdb_dynamic_options(

std::unordered_map<std::string, std::string> new_options;
for (const auto &option : ROCKSDB_DYNAMIC_OPTIONS) {
auto find = envs.find(option);
const auto &find = envs.find(option);
if (find == envs.end()) {
continue;
}
Expand All @@ -2662,12 +2662,12 @@ void pegasus_server_impl::set_rocksdb_options_before_creating(
}

for (const auto &option : pegasus::ROCKSDB_STATIC_OPTIONS) {
auto find = envs.find(option);
const auto &find = envs.find(option);
if (find == envs.end()) {
continue;
}

auto setter = cf_opts_setters.find(option);
const auto &setter = cf_opts_setters.find(option);
if (setter == cf_opts_setters.end()) {
LOG_WARNING("cannot find {} setter function, and set this option fail.", option);
continue;
Expand All @@ -2678,12 +2678,12 @@ void pegasus_server_impl::set_rocksdb_options_before_creating(
}

for (const auto &option : pegasus::ROCKSDB_DYNAMIC_OPTIONS) {
auto find = envs.find(option);
const auto &find = envs.find(option);
if (find == envs.end()) {
continue;
}

auto setter = cf_opts_setters.find(option);
const auto &setter = cf_opts_setters.find(option);
if (setter == cf_opts_setters.end()) {
LOG_WARNING("cannot find {} setter function, and set this option fail.", option);
continue;
Expand Down Expand Up @@ -2728,18 +2728,14 @@ void pegasus_server_impl::query_app_envs(/*out*/ std::map<std::string, std::stri
envs[ROCKSDB_ENV_USAGE_SCENARIO_KEY] = _usage_scenario;
// write_buffer_size involves random values (refer to pegasus_server_impl::set_usage_scenario),
// so it can only be taken from _data_cf_opts
envs[ROCKSDB_WRITE_BUFFER_SIZE] = fmt::format("{}", _data_cf_opts.write_buffer_size);
envs[ROCKSDB_WRITE_BUFFER_SIZE] = std::to_string(_data_cf_opts.write_buffer_size);

// Get Data ColumnFamilyOptions directly from _data_cf
rocksdb::ColumnFamilyDescriptor desc;
auto s = _data_cf->GetDescriptor(&desc);
CHECK_TRUE(s.ok());
CHECK_TRUE(_data_cf->GetDescriptor(&desc).ok());
for (const auto &option : pegasus::ROCKSDB_STATIC_OPTIONS) {
auto getter = cf_opts_getters.find(option);
if (getter == cf_opts_getters.end()) {
LOG_WARNING("cannot find {} getter function, and get this option fail.", option);
continue;
}
CHECK_TRUE(getter != cf_opts_getters.end());
std::string option_val;
getter->second(desc.options, option_val);
envs[option] = option_val;
Expand All @@ -2749,10 +2745,7 @@ void pegasus_server_impl::query_app_envs(/*out*/ std::map<std::string, std::stri
continue;
}
auto getter = cf_opts_getters.find(option);
if (getter == cf_opts_getters.end()) {
LOG_WARNING("cannot find {} getter function, and get this option fail.", option);
continue;
}
CHECK_TRUE(getter != cf_opts_getters.end());
std::string option_val;
getter->second(desc.options, option_val);
envs[option] = option_val;
Expand Down

0 comments on commit 31886f1

Please sign in to comment.