Skip to content

Commit

Permalink
refactor code into reset_rocksdb_option
Browse files Browse the repository at this point in the history
  • Loading branch information
ninsmiracle committed Oct 19, 2023
1 parent b9e55a1 commit b07110a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,19 +1666,7 @@ dsn::error_code pegasus_server_impl::start(int argc, char **argv)
// We don't use `loaded_data_cf_opts` directly because pointer-typed options will
// only be initialized with default values when calling 'LoadLatestOptions', see
// 'rocksdb/utilities/options_util.h'.
reset_rocksdb_options(loaded_data_cf_opts, &_table_data_cf_opts);

// here loaded_db_opt should be read success
if (envs.size() == 0) {
// for reopen db during load balance learning
_db_opts.allow_ingest_behind = loaded_db_opt.allow_ingest_behind;
LOG_INFO_PREFIX("reopen replica,last_allow_ingest_behind = {}",
loaded_db_opt.allow_ingest_behind);
} else {
_db_opts.allow_ingest_behind = parse_allow_ingest_behind(envs);
LOG_INFO_PREFIX("normal open replica,new_allow_ingest_behind = {}",
_db_opts.allow_ingest_behind);
}
reset_rocksdb_options(loaded_data_cf_opts, &_table_data_cf_opts,loaded_db_opt,&_db_opts,envs);
}
} else {
// When create new DB, we have to create a new column family to store meta data (meta column
Expand Down Expand Up @@ -3143,7 +3131,7 @@ bool pegasus_server_impl::set_usage_scenario(const std::string &usage_scenario)
}

void pegasus_server_impl::reset_rocksdb_options(const rocksdb::ColumnFamilyOptions &base_opts,
rocksdb::ColumnFamilyOptions *target_opts)
rocksdb::ColumnFamilyOptions *target_opts,const rocksdb::DBOptions &base_db_opt,rocksdb::DBOptions *target_db_opt,const std::map<std::string, std::string> &envs)
{
LOG_INFO_PREFIX("Reset rocksdb envs options");
// Reset rocksdb option includes two aspects:
Expand All @@ -3157,6 +3145,8 @@ void pegasus_server_impl::reset_rocksdb_options(const rocksdb::ColumnFamilyOptio
// aspect 2:
target_opts->num_levels = base_opts.num_levels;
target_opts->write_buffer_size = base_opts.write_buffer_size;

reset_allow_ingest_behind_option(base_db_opt,target_db_opt,envs);
}

void pegasus_server_impl::reset_usage_scenario_options(
Expand All @@ -3177,6 +3167,16 @@ void pegasus_server_impl::reset_usage_scenario_options(
target_opts->max_write_buffer_number = base_opts.max_write_buffer_number;
}

void pegasus_server_impl::reset_allow_ingest_behind_option(const rocksdb::DBOptions &base_db_opt,rocksdb::DBOptions *target_db_opt,const std::map<std::string, std::string> &envs)
{
if (envs.empty()) {
// for reopen db during load balance learning
target_db_opt->allow_ingest_behind = base_db_opt.allow_ingest_behind;
} else {
target_db_opt->allow_ingest_behind = parse_allow_ingest_behind(envs);
}
}

void pegasus_server_impl::recalculate_data_cf_options(
const rocksdb::ColumnFamilyOptions &cur_data_cf_opts)
{
Expand Down
4 changes: 3 additions & 1 deletion src/server/pegasus_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,10 @@ class pegasus_server_impl : public pegasus_read_service
void reset_usage_scenario_options(const rocksdb::ColumnFamilyOptions &base_opts,
rocksdb::ColumnFamilyOptions *target_opts);

void reset_allow_ingest_behind_option(const rocksdb::DBOptions &base_db_opt,rocksdb::DBOptions *target_db_opt,const std::map<std::string, std::string> &envs);

void reset_rocksdb_options(const rocksdb::ColumnFamilyOptions &base_opts,
rocksdb::ColumnFamilyOptions *target_opts);
rocksdb::ColumnFamilyOptions *target_opts,const rocksdb::DBOptions &base_db_opt,rocksdb::DBOptions *target_db_opt,const std::map<std::string, std::string> &envs);

// return true if successfully set
bool set_options(const std::unordered_map<std::string, std::string> &new_options);
Expand Down

0 comments on commit b07110a

Please sign in to comment.