From 6e83846bd0b088b011a16a7594d4e3d6a18ab422 Mon Sep 17 00:00:00 2001 From: Dan Wang Date: Sat, 9 Oct 2021 00:52:08 +0800 Subject: [PATCH] feat: support single replica --- src/client/replication_ddl_client.cpp | 4 ++-- src/meta/greedy_load_balancer.cpp | 8 ++++++-- src/meta/meta_options.cpp | 16 +++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/client/replication_ddl_client.cpp b/src/client/replication_ddl_client.cpp index ef89208028..72231201a2 100644 --- a/src/client/replication_ddl_client.cpp +++ b/src/client/replication_ddl_client.cpp @@ -128,8 +128,8 @@ dsn::error_code replication_ddl_client::create_app(const std::string &app_name, return ERR_INVALID_PARAMETERS; } - if (replica_count < 2) { - std::cout << "create app " << app_name << " failed: replica_count should >= 2" << std::endl; + if (replica_count < 1) { + std::cout << "create app " << app_name << " failed: replica_count should >= 1" << std::endl; return ERR_INVALID_PARAMETERS; } diff --git a/src/meta/greedy_load_balancer.cpp b/src/meta/greedy_load_balancer.cpp index d9b43e174d..16da837e6b 100644 --- a/src/meta/greedy_load_balancer.cpp +++ b/src/meta/greedy_load_balancer.cpp @@ -47,6 +47,8 @@ DSN_DEFINE_uint32("meta_server", "balance operation count per round for cluster balancer"); DSN_TAG_VARIABLE(balance_op_count_per_round, FT_MUTABLE); +DSN_DECLARE_uint64(min_live_node_count_for_unfreeze); + uint32_t get_partition_count(const node_state &ns, cluster_balance_type type, int32_t app_id) { unsigned count = 0; @@ -795,7 +797,8 @@ void greedy_load_balancer::shortest_path(std::vector &visit, bool greedy_load_balancer::primary_balancer_per_app(const std::shared_ptr &app, bool only_move_primary) { - dassert(t_alive_nodes > 2, "too few alive nodes will lead to freeze"); + dassert(t_alive_nodes >= FLAGS_min_live_node_count_for_unfreeze, + "too few alive nodes will lead to freeze"); ddebug("primary balancer for app(%s:%d)", app->app_name.c_str(), app->app_id); const node_mapper &nodes = *(t_global_view->nodes); @@ -888,7 +891,8 @@ bool greedy_load_balancer::all_replica_infos_collected(const node_state &ns) void greedy_load_balancer::greedy_balancer(const bool balance_checker) { - dassert(t_alive_nodes > 2, "too few nodes will be freezed"); + dassert(t_alive_nodes >= FLAGS_min_live_node_count_for_unfreeze, + "too few nodes will be freezed"); number_nodes(*t_global_view->nodes); for (auto &kv : *(t_global_view->nodes)) { diff --git a/src/meta/meta_options.cpp b/src/meta/meta_options.cpp index 9084416564..81c24aa50b 100644 --- a/src/meta/meta_options.cpp +++ b/src/meta/meta_options.cpp @@ -34,9 +34,19 @@ */ #include "meta_options.h" +#include + namespace dsn { namespace replication { +DSN_DEFINE_uint64("meta_server", + min_live_node_count_for_unfreeze, + 3, + "minimum live node count without which the state is freezed"); +DSN_TAG_VARIABLE(min_live_node_count_for_unfreeze, FT_MUTABLE); +DSN_DEFINE_validator(min_live_node_count_for_unfreeze, + [](uint64_t min_live_node_count) -> bool { return min_live_node_count > 0; }); + std::string meta_options::concat_path_unix_style(const std::string &prefix, const std::string &postfix) { @@ -72,11 +82,7 @@ void meta_options::initialize() "if live_node_count * 100 < total_node_count * node_live_percentage_threshold_for_update, " "then freeze the cluster; default is 65"); - min_live_node_count_for_unfreeze = - dsn_config_get_value_uint64("meta_server", - "min_live_node_count_for_unfreeze", - 3, - "minimum live node count without which the state is freezed"); + min_live_node_count_for_unfreeze = FLAGS_min_live_node_count_for_unfreeze; meta_function_level_on_start = meta_function_level::fl_invalid; const char *level_str = dsn_config_get_value_string(