Skip to content

Commit

Permalink
refactor(conf): use DSN_DEFINE_string to load string type of configs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 authored Mar 1, 2023
1 parent 2c69117 commit 98e3598
Show file tree
Hide file tree
Showing 39 changed files with 291 additions and 308 deletions.
27 changes: 14 additions & 13 deletions src/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ DSN_DEFINE_bool(replication,
"whether to disable empty write, default is false");
DSN_TAG_VARIABLE(empty_write_disabled, FT_MUTABLE);

DSN_DEFINE_string(replication, slog_dir, "", "The shared log directory");
DSN_DEFINE_string(replication, data_dirs, "", "replica directory list");
DSN_DEFINE_string(replication,
data_dirs_black_list_file,
"/home/work/.pegasus_data_dirs_black_list",
"replica directory black list file");
DSN_DEFINE_string(replication,
cold_backup_root,
"",
"The prefix of cold backup data path on remote storage");

replication_options::~replication_options() {}

void replication_options::initialize()
Expand All @@ -99,7 +110,7 @@ void replication_options::initialize()
// slog_dir:
// - if config[slog_dir] is empty: "app_dir/slog"
// - else: "config[slog_dir]/app_name/slog"
slog_dir = dsn_config_get_value_string("replication", "slog_dir", "", "shared log directory");
slog_dir = FLAGS_slog_dir;
if (slog_dir.empty()) {
slog_dir = app_dir;
} else {
Expand All @@ -108,23 +119,16 @@ void replication_options::initialize()
slog_dir = utils::filesystem::path_combine(slog_dir, "slog");

// get config_data_dirs and config_data_dir_tags from config
const std::string &dirs_str =
dsn_config_get_value_string("replication", "data_dirs", "", "replica directory list");
std::vector<std::string> config_data_dirs;
std::vector<std::string> config_data_dir_tags;
std::string error_msg = "";
bool flag = get_data_dir_and_tag(
dirs_str, app_dir, app_name, config_data_dirs, config_data_dir_tags, error_msg);
FLAGS_data_dirs, app_dir, app_name, config_data_dirs, config_data_dir_tags, error_msg);
CHECK(flag, error_msg);

// check if data_dir in black list, data_dirs doesn't contain dir in black list
std::string black_list_file =
dsn_config_get_value_string("replication",
"data_dirs_black_list_file",
"/home/work/.pegasus_data_dirs_black_list",
"replica directory black list file");
std::vector<std::string> black_list_dirs;
get_data_dirs_in_black_list(black_list_file, black_list_dirs);
get_data_dirs_in_black_list(FLAGS_data_dirs_black_list_file, black_list_dirs);
for (auto i = 0; i < config_data_dirs.size(); ++i) {
if (check_if_in_black_list(black_list_dirs, config_data_dirs[i])) {
continue;
Expand All @@ -135,9 +139,6 @@ void replication_options::initialize()

CHECK(!data_dirs.empty(), "no replica data dir found, maybe not set or excluded by black list");

cold_backup_root = dsn_config_get_value_string(
"replication", "cold_backup_root", "", "cold backup remote storage path prefix");

max_concurrent_bulk_load_downloading_count = FLAGS_max_concurrent_bulk_load_downloading_count;

CHECK(replica_helper::load_meta_servers(meta_servers), "invalid meta server config");
Expand Down
2 changes: 0 additions & 2 deletions src/common/replication_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class replication_options
std::vector<std::string> data_dirs;
std::vector<std::string> data_dir_tags;

std::string cold_backup_root;

int32_t max_concurrent_bulk_load_downloading_count;

public:
Expand Down
8 changes: 4 additions & 4 deletions src/meta/meta_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "meta/meta_bulk_load_service.h"

namespace dsn {
namespace dist {
DSN_DECLARE_string(hosts_list);
} // namespace dist
namespace replication {

struct list_nodes_helper
Expand Down Expand Up @@ -456,10 +459,7 @@ void meta_http_service::get_cluster_info_handler(const http_request &req, http_r
}
tp.add_row_name_and_data("meta_servers", meta_servers_str);
tp.add_row_name_and_data("primary_meta_server", dsn_primary_address().to_std_string());
std::string zk_hosts =
dsn_config_get_value_string("zookeeper", "hosts_list", "", "zookeeper_hosts");
zk_hosts.erase(std::remove_if(zk_hosts.begin(), zk_hosts.end(), ::isspace), zk_hosts.end());
tp.add_row_name_and_data("zookeeper_hosts", zk_hosts);
tp.add_row_name_and_data("zookeeper_hosts", dsn::dist::FLAGS_hosts_list);
tp.add_row_name_and_data("zookeeper_root", _service->_cluster_root);
tp.add_row_name_and_data(
"meta_function_level",
Expand Down
69 changes: 24 additions & 45 deletions src/meta/meta_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@

namespace dsn {
namespace replication {
// TODO(yingchun): add more description for string configs, and add validators
DSN_DEFINE_string(meta_server,
meta_state_service_parameters,
"",
"meta_state_service provider parameters");
DSN_DEFINE_string(meta_server,
meta_function_level_on_start,
"steady",
"meta function level on start");
DSN_DEFINE_string(meta_server,
distributed_lock_service_parameters,
"",
"distributed_lock_service provider parameters");
DSN_DEFINE_string(meta_server,
replica_white_list,
"",
"white list of replica-servers in meta-server");

std::string meta_options::concat_path_unix_style(const std::string &prefix,
const std::string &postfix)
{
Expand All @@ -52,24 +70,10 @@ std::string meta_options::concat_path_unix_style(const std::string &prefix,

void meta_options::initialize()
{
cluster_root = dsn_config_get_value_string(
"meta_server", "cluster_root", "/", "cluster root of meta state service on remote");

meta_state_service_type = dsn_config_get_value_string("meta_server",
"meta_state_service_type",
"meta_state_service_simple",
"meta_state_service provider type");
const char *meta_state_service_parameters =
dsn_config_get_value_string("meta_server",
"meta_state_service_parameters",
"",
"meta_state_service provider parameters");
utils::split_args(meta_state_service_parameters, meta_state_service_args);
utils::split_args(FLAGS_meta_state_service_parameters, meta_state_service_args);

meta_function_level_on_start = meta_function_level::fl_invalid;
const char *level_str = dsn_config_get_value_string(
"meta_server", "meta_function_level_on_start", "steady", "meta function level on start");
std::string level = std::string("fl_") + level_str;
std::string level = std::string("fl_") + FLAGS_meta_function_level_on_start;
for (auto &kv : _meta_function_level_VALUES_TO_NAMES) {
if (level == kv.second) {
meta_function_level_on_start = (meta_function_level::type)kv.first;
Expand All @@ -79,36 +83,11 @@ void meta_options::initialize()
CHECK_NE_MSG(meta_function_level_on_start,
meta_function_level::fl_invalid,
"invalid function level: {}",
level_str);

/// failure detector options
_fd_opts.distributed_lock_service_type =
dsn_config_get_value_string("meta_server",
"distributed_lock_service_type",
"distributed_lock_service_simple",
"dist lock provider");
const char *distributed_lock_service_parameters =
dsn_config_get_value_string("meta_server",
"distributed_lock_service_parameters",
"",
"distributed_lock_service provider parameters");
utils::split_args(distributed_lock_service_parameters, _fd_opts.distributed_lock_service_args);

/// load balancer options
_lb_opts.server_load_balancer_type =
dsn_config_get_value_string("meta_server",
"server_load_balancer_type",
"greedy_load_balancer",
"server load balancer provider");

partition_guardian_type = dsn_config_get_value_string("meta_server",
"partition_guardian_type",
"partition_guardian",
"partition guardian provider");
FLAGS_meta_function_level_on_start);

const char *replica_white_list_raw = dsn_config_get_value_string(
"meta_server", "replica_white_list", "", "white list of replica-servers in meta-server");
utils::split_args(replica_white_list_raw, replica_white_list, ',');
utils::split_args(FLAGS_distributed_lock_service_parameters,
_fd_opts.distributed_lock_service_args);
utils::split_args(FLAGS_replica_white_list, replica_white_list, ',');
}
} // namespace replication
} // namespace dsn
12 changes: 1 addition & 11 deletions src/meta/meta_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,21 @@
namespace dsn {
namespace replication {

// TODO(yingchun): remove it
class fd_suboptions
{
public:
std::string distributed_lock_service_type;
std::vector<std::string> distributed_lock_service_args;
};

class lb_suboptions
{
public:
std::string server_load_balancer_type;
};

class meta_options
{
public:
std::string cluster_root;
std::string meta_state_service_type;
std::vector<std::string> meta_state_service_args;

meta_function_level::type meta_function_level_on_start;

fd_suboptions _fd_opts;
lb_suboptions _lb_opts;
std::string partition_guardian_type;
std::vector<std::string> replica_white_list;

public:
Expand Down
6 changes: 5 additions & 1 deletion src/meta/meta_server_failure_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ DSN_DEFINE_uint64(meta_server,
stable_rs_min_running_seconds,
600,
"The minimal running seconds for a stable replica server");
DSN_DEFINE_string(meta_server,
distributed_lock_service_type,
"distributed_lock_service_simple",
"dist lock provider");

namespace dsn {
namespace replication {
Expand All @@ -59,7 +63,7 @@ meta_server_failure_detector::meta_server_failure_detector(meta_service *svc)
{
_fd_opts = &(svc->get_meta_options()._fd_opts);
_lock_svc = dsn::utils::factory_store<dist::distributed_lock_service>::create(
_fd_opts->distributed_lock_service_type.c_str(), PROVIDER_TYPE_MAIN);
FLAGS_distributed_lock_service_type, PROVIDER_TYPE_MAIN);
error_code err = _lock_svc->initialize(_fd_opts->distributed_lock_service_args);
CHECK_EQ_MSG(err, ERR_OK, "init distributed_lock_service failed");
}
Expand Down
36 changes: 27 additions & 9 deletions src/meta/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include "meta_bulk_load_service.h"

namespace dsn {
namespace dist {
DSN_DECLARE_string(hosts_list);
} // namespace dist

namespace replication {
DSN_DEFINE_bool(meta_server,
recover_from_replica_server,
Expand Down Expand Up @@ -75,12 +79,29 @@ DSN_DEFINE_uint64(meta_server,
65,
"If live_node_count * 100 < total_node_count * "
"node_live_percentage_threshold_for_update, then freeze the cluster.");
DSN_DEFINE_string(meta_server,
meta_state_service_type,
"meta_state_service_simple",
"meta_state_service provider type");
DSN_DEFINE_string(meta_server,
cluster_root,
"/",
"The root of the cluster meta state service to be stored on remote storage");
DSN_DEFINE_string(meta_server,
server_load_balancer_type,
"greedy_load_balancer",
"server load balancer provider");
DSN_DEFINE_string(meta_server,
partition_guardian_type,
"partition_guardian",
"partition guardian provider");

DSN_DECLARE_bool(duplication_enabled);
DSN_DECLARE_int32(fd_beacon_interval_seconds);
DSN_DECLARE_int32(fd_check_interval_seconds);
DSN_DECLARE_int32(fd_grace_seconds);
DSN_DECLARE_int32(fd_lease_seconds);
DSN_DECLARE_string(cold_backup_root);

meta_service::meta_service()
: serverlet("meta_service"), _failure_detector(nullptr), _started(false), _recovering(false)
Expand Down Expand Up @@ -144,7 +165,7 @@ error_code meta_service::remote_storage_initialize()
// create storage
dsn::dist::meta_state_service *storage =
dsn::utils::factory_store<::dsn::dist::meta_state_service>::create(
_meta_opts.meta_state_service_type.c_str(), PROVIDER_TYPE_MAIN);
FLAGS_meta_state_service_type, PROVIDER_TYPE_MAIN);
error_code err = storage->initialize(_meta_opts.meta_state_service_args);
if (err != ERR_OK) {
LOG_ERROR("init meta_state_service failed, err = {}", err);
Expand All @@ -154,7 +175,7 @@ error_code meta_service::remote_storage_initialize()
_meta_storage.reset(new mss::meta_storage(_storage.get(), &_tracker));

std::vector<std::string> slices;
utils::split_args(_meta_opts.cluster_root.c_str(), slices, '/');
utils::split_args(FLAGS_cluster_root, slices, '/');
std::string current = "";
for (unsigned int i = 0; i != slices.size(); ++i) {
current = meta_options::concat_path_unix_style(current, slices[i]);
Expand Down Expand Up @@ -357,13 +378,13 @@ error_code meta_service::start()

// initialize the load balancer
server_load_balancer *balancer = utils::factory_store<server_load_balancer>::create(
_meta_opts._lb_opts.server_load_balancer_type.c_str(), PROVIDER_TYPE_MAIN, this);
FLAGS_server_load_balancer_type, PROVIDER_TYPE_MAIN, this);
_balancer.reset(balancer);
// register control command to singleton-container for load balancer
_balancer->register_ctrl_commands();

partition_guardian *guardian = utils::factory_store<partition_guardian>::create(
_meta_opts.partition_guardian_type.c_str(), PROVIDER_TYPE_MAIN, this);
FLAGS_partition_guardian_type, PROVIDER_TYPE_MAIN, this);
_partition_guardian.reset(guardian);
_partition_guardian->register_ctrl_commands();

Expand All @@ -374,7 +395,7 @@ error_code meta_service::start()
_backup_handler = std::make_shared<backup_service>(
this,
meta_options::concat_path_unix_style(_cluster_root, "backup"),
_opts.cold_backup_root,
FLAGS_cold_backup_root,
[](backup_service *bs) { return std::make_shared<policy_context>(bs); });
}

Expand Down Expand Up @@ -633,11 +654,8 @@ void meta_service::on_query_cluster_info(configuration_cluster_info_rpc rpc)
response.values.push_back(oss.str());
response.keys.push_back("primary_meta_server");
response.values.push_back(dsn_primary_address().to_std_string());
std::string zk_hosts =
dsn_config_get_value_string("zookeeper", "hosts_list", "", "zookeeper_hosts");
zk_hosts.erase(std::remove_if(zk_hosts.begin(), zk_hosts.end(), ::isspace), zk_hosts.end());
response.keys.push_back("zookeeper_hosts");
response.values.push_back(zk_hosts);
response.values.push_back(dsn::dist::FLAGS_hosts_list);
response.keys.push_back("zookeeper_root");
response.values.push_back(_cluster_root);
response.keys.push_back("meta_function_level");
Expand Down
8 changes: 5 additions & 3 deletions src/meta/test/backup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace dsn {
namespace replication {

DSN_DECLARE_int32(cold_backup_checkpoint_reserve_minutes);
DSN_DECLARE_string(cluster_root);
DSN_DECLARE_string(meta_state_service_type);

struct method_record
{
Expand Down Expand Up @@ -728,11 +730,11 @@ class meta_backup_service_test : public meta_test_base
meta_test_base::SetUp();

meta_options &opt = _meta_svc->_meta_opts;
opt.cluster_root = "/meta_test";
opt.meta_state_service_type = "meta_state_service_simple";
FLAGS_cluster_root = "/meta_test";
FLAGS_meta_state_service_type = "meta_state_service_simple";
_meta_svc->remote_storage_initialize();
std::string backup_root = "/backup_test";
std::string policy_meta_root = opt.cluster_root + "/backup_policies";
std::string policy_meta_root = std::string(FLAGS_cluster_root) + "/backup_policies";
_meta_svc->_backup_handler = std::make_shared<backup_service>(
_meta_svc.get(), policy_meta_root, backup_root, [](backup_service *bs) {
return std::make_shared<mock_policy>(bs);
Expand Down
6 changes: 4 additions & 2 deletions src/meta/test/meta_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace dsn {
namespace replication {

DSN_DECLARE_uint64(min_live_node_count_for_unfreeze);
DSN_DECLARE_string(partition_guardian_type);
DSN_DECLARE_string(server_load_balancer_type);

meta_test_base::~meta_test_base() {}

Expand All @@ -39,9 +41,9 @@ void meta_test_base::SetUp()
_ms = make_unique<fake_receiver_meta_service>();
_ms->_failure_detector.reset(new meta_server_failure_detector(_ms.get()));
_ms->_balancer.reset(utils::factory_store<server_load_balancer>::create(
_ms->_meta_opts._lb_opts.server_load_balancer_type.c_str(), PROVIDER_TYPE_MAIN, _ms.get()));
FLAGS_server_load_balancer_type, PROVIDER_TYPE_MAIN, _ms.get()));
_ms->_partition_guardian.reset(utils::factory_store<partition_guardian>::create(
_ms->_meta_opts.partition_guardian_type.c_str(), PROVIDER_TYPE_MAIN, _ms.get()));
FLAGS_partition_guardian_type, PROVIDER_TYPE_MAIN, _ms.get()));
ASSERT_EQ(_ms->remote_storage_initialize(), ERR_OK);
_ms->initialize_duplication_service();
ASSERT_TRUE(_ms->_dup_svc);
Expand Down
Loading

0 comments on commit 98e3598

Please sign in to comment.