Skip to content

Commit

Permalink
fix(dup): reject add_dup if remote address incorrect (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Tao authored May 25, 2020
1 parent 98f5e22 commit 4ebbd1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void meta_duplication_service::add_duplication(duplication_add_rpc rpc)
response.__set_hint("illegal operation: adding duplication to itself");
return;
}

auto remote_cluster_id = get_duplication_cluster_id(request.remote_cluster_name);
if (!remote_cluster_id.is_ok()) {
response.err = ERR_INVALID_PARAMETERS;
Expand All @@ -150,6 +149,14 @@ void meta_duplication_service::add_duplication(duplication_add_rpc rpc)
remote_cluster_id.get_error()));
return;
}
std::vector<std::string> clusters;
dsn_config_get_all_keys("pegasus.clusters", clusters);
if (std::find(clusters.begin(), clusters.end(), request.remote_cluster_name) ==
clusters.end()) {
response.err = ERR_INVALID_PARAMETERS;
response.__set_hint("failed to find cluster address in config [pegasus.clusters]");
return;
}

auto app = _state->get_app(request.app_name);
if (!app || app->status != app_status::AS_AVAILABLE) {
Expand Down
5 changes: 5 additions & 0 deletions src/dist/replication/test/meta_test/unit_test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ args =
[duplication-group]
master-cluster = 1
slave-cluster = 2
cluster_without_address_for_test = 3

[pegasus.clusters]
master-cluster = 127.0.0.1:34601
slave-cluster = 127.0.0.1:35601
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ class meta_duplication_service_test : public meta_test_base
std::string invalid_remote = "test-invalid-remote";
std::string ok_remote = "slave-cluster";

std::string cluster_without_address = "cluster_without_address_for_test";

create_app(test_app);

create_app(test_app_invalid_ver);
Expand All @@ -328,6 +330,8 @@ class meta_duplication_service_test : public meta_test_base
{test_app, invalid_remote, ERR_INVALID_PARAMETERS},

{test_app, get_current_cluster_name(), ERR_INVALID_PARAMETERS},

{test_app, cluster_without_address, ERR_INVALID_PARAMETERS},
};

for (auto tt : tests) {
Expand Down

0 comments on commit 4ebbd1b

Please sign in to comment.