Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(split): add app_env split_validate_partition_hash #745

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/dsn/dist/replication/replica_envs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion src/meta/app_env_validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/meta/meta_split_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <dsn/dist/fmt_logging.h>
#include <dsn/dist/replication/replica_envs.h>
#include <dsn/utility/fail_point.h>

#include "meta_split_service.h"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -101,6 +101,7 @@ void meta_split_service::do_start_partition_split(std::shared_ptr<app_state> 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];
Expand All @@ -121,8 +122,8 @@ void meta_split_service::do_start_partition_split(std::shared_ptr<app_state> app
}
auto copy = *app;
copy.partition_count *= 2;
copy.envs[replica_envs::SPLIT_VALIDATE_PARTITION_HASH] = "true";
blob value = dsn::json::json_forwarder<app_info>::encode(copy);

_meta_svc->get_meta_storage()->set_data(
_state->get_app_path(*app), std::move(value), on_write_storage_complete);
}
Expand Down
4 changes: 4 additions & 0 deletions src/meta/test/meta_split_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <gtest/gtest.h>
#include <dsn/service_api_c.h>
#include <dsn/dist/replication/replica_envs.h>

#include "meta_service_test_app.h"
#include "meta_test_base.h"
Expand Down Expand Up @@ -262,6 +263,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");
}
}
}

Expand Down