diff --git a/include/dsn/dist/replication/replica_envs.h b/include/dsn/dist/replication/replica_envs.h index a1b8e4afef..baa610c5db 100644 --- a/include/dsn/dist/replication/replica_envs.h +++ b/include/dsn/dist/replication/replica_envs.h @@ -57,6 +57,7 @@ class replica_envs static const std::string REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS; static const std::string READ_QPS_THROTTLING; static const std::string READ_SIZE_THROTTLING; + static const std::string SPLIT_VALIDATE_PARTITION_HASH; }; } // namespace replication diff --git a/src/common/replication_common.cpp b/src/common/replication_common.cpp index e711046f6d..a1d0a10f7e 100644 --- a/src/common/replication_common.cpp +++ b/src/common/replication_common.cpp @@ -628,6 +628,8 @@ const std::string replica_envs::REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS( "replica_access_controller.allowed_users"); const std::string replica_envs::READ_QPS_THROTTLING("replica.read_throttling"); const std::string replica_envs::READ_SIZE_THROTTLING("replica.read_throttling_by_size"); +const std::string + replica_envs::SPLIT_VALIDATE_PARTITION_HASH("replica.split.validate_partition_hash"); const std::string bulk_load_constant::BULK_LOAD_INFO("bulk_load_info"); const int32_t bulk_load_constant::BULK_LOAD_REQUEST_INTERVAL = 10; diff --git a/src/meta/app_env_validator.cpp b/src/meta/app_env_validator.cpp index c7021c6fff..422b7d8bc0 100644 --- a/src/meta/app_env_validator.cpp +++ b/src/meta/app_env_validator.cpp @@ -123,6 +123,16 @@ bool check_throttling(const std::string &env_value, std::string &hint_message) return true; } +bool check_split_validation(const std::string &env_value, std::string &hint_message) +{ + bool result = false; + if (!dsn::buf2bool(env_value, result)) { + hint_message = fmt::format("invalid string {}, should be \"true\" or \"false\"", env_value); + return false; + } + return true; +} + bool app_env_validator::validate_app_env(const std::string &env_name, const std::string &env_value, std::string &hint_message) @@ -172,7 +182,9 @@ void app_env_validator::register_all_validators() {replica_envs::READ_QPS_THROTTLING, std::bind(&check_throttling, std::placeholders::_1, std::placeholders::_2)}, {replica_envs::READ_SIZE_THROTTLING, - std::bind(&check_throttling, std::placeholders::_1, std::placeholders::_2)}}; + std::bind(&check_throttling, std::placeholders::_1, std::placeholders::_2)}, + {replica_envs::SPLIT_VALIDATE_PARTITION_HASH, + std::bind(&check_split_validation, std::placeholders::_1, std::placeholders::_2)}}; } } // namespace replication diff --git a/src/meta/meta_split_service.cpp b/src/meta/meta_split_service.cpp index 1d10493055..1070411d79 100644 --- a/src/meta/meta_split_service.cpp +++ b/src/meta/meta_split_service.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include "meta_split_service.h" @@ -55,7 +56,6 @@ void meta_split_service::start_partition_split(start_split_rpc rpc) response.err = app == nullptr ? ERR_APP_NOT_EXIST : ERR_APP_DROPPED; response.hint_msg = fmt::format( "app {}", response.err == ERR_APP_NOT_EXIST ? "not existed" : "dropped"); - return; } @@ -101,6 +101,7 @@ void meta_split_service::do_start_partition_split(std::shared_ptr app app->partition_count *= 2; app->helpers->contexts.resize(app->partition_count); app->partitions.resize(app->partition_count); + app->envs[replica_envs::SPLIT_VALIDATE_PARTITION_HASH] = "true"; for (int i = 0; i < app->partition_count; ++i) { app->helpers->contexts[i].config_owner = &app->partitions[i]; @@ -121,8 +122,8 @@ void meta_split_service::do_start_partition_split(std::shared_ptr app } auto copy = *app; copy.partition_count *= 2; + copy.envs[replica_envs::SPLIT_VALIDATE_PARTITION_HASH] = "true"; blob value = dsn::json::json_forwarder::encode(copy); - _meta_svc->get_meta_storage()->set_data( _state->get_app_path(*app), std::move(value), on_write_storage_complete); } diff --git a/src/meta/test/meta_split_service_test.cpp b/src/meta/test/meta_split_service_test.cpp index a4719ec143..b322b7efa5 100644 --- a/src/meta/test/meta_split_service_test.cpp +++ b/src/meta/test/meta_split_service_test.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "meta_service_test_app.h" #include "meta_test_base.h" @@ -273,6 +274,9 @@ TEST_F(meta_split_service_test, start_split_test) ASSERT_EQ(start_partition_split(test.app_name, test.new_partition_count), test.expected_err); ASSERT_EQ(app->partition_count, test.expected_partition_count); + if (test.expected_err == ERR_OK) { + ASSERT_EQ(app->envs[replica_envs::SPLIT_VALIDATE_PARTITION_HASH], "true"); + } } }