Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Jul 26, 2024
1 parent 1b51d14 commit e674275
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 160 deletions.
32 changes: 16 additions & 16 deletions src/meta/test/balancer_validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co
CHECK(!pc.hp_primary, "");
CHECK(pc.secondaries.empty(), "");
CHECK(pc.hp_secondaries.empty(), "");
CHECK_EQ(act.node, act.target);
CHECK_EQ(act.hp_node, act.hp_target);
const auto node = nodes.find(act.hp_node);
CHECK_EQ(act.node1, act.target1);
CHECK_EQ(act.hp_node1, act.hp_target1);
const auto node = nodes.find(act.hp_node1);
CHECK(node != nodes.end(), "");
ns = &node->second;
CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE);
ns->put_partition(pc.pid, true);
SET_OBJ_IP_AND_HOST_PORT(pc, primary, act, node);
SET_OBJ_IP_AND_HOST_PORT(pc, primary, act, node1);
break;
}
case config_type::CT_ADD_SECONDARY: {
CHECK(!is_member(pc, act.node), "");
CHECK(!is_member(pc, act.hp_node), "");
CHECK_EQ(pc.primary, act.target);
CHECK_EQ(pc.hp_primary, act.hp_target);
const auto node = nodes.find(act.hp_node);
CHECK(!is_member(pc, act.node1), "");
CHECK(!is_member(pc, act.hp_node1), "");
CHECK_EQ(pc.primary, act.target1);
CHECK_EQ(pc.hp_primary, act.hp_target1);
const auto node = nodes.find(act.hp_node1);
CHECK(node != nodes.end(), "");
ADD_IP_AND_HOST_PORT(pc, secondaries, act.node, act.hp_node);
ADD_IP_AND_HOST_PORT(pc, secondaries, act.node1, act.hp_node1);
ns = &node->second;
CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE);
ns->put_partition(pc.pid, false);
Expand All @@ -110,14 +110,14 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co
CHECK_EQ(act.type, config_type::CT_UPGRADE_TO_PRIMARY);
CHECK(!pc.primary, "");
CHECK(!pc.hp_primary, "");
CHECK_EQ(act.node, act.target);
CHECK_EQ(act.hp_node, act.hp_target);
CHECK(is_secondary(pc, act.node), "");
CHECK(is_secondary(pc, act.hp_node), "");
const auto node = nodes.find(act.hp_node);
CHECK_EQ(act.node1, act.target1);
CHECK_EQ(act.hp_node1, act.hp_target1);
CHECK(is_secondary(pc, act.node1), "");
CHECK(is_secondary(pc, act.hp_node1), "");
const auto node = nodes.find(act.hp_node1);
CHECK(node != nodes.end(), "");
ns = &node->second;
SET_OBJ_IP_AND_HOST_PORT(pc, primary, act, node);
SET_OBJ_IP_AND_HOST_PORT(pc, primary, act, node1);
std::remove(pc.secondaries.begin(), pc.secondaries.end(), pc.primary);
std::remove(pc.hp_secondaries.begin(), pc.hp_secondaries.end(), pc.hp_primary);
CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_SECONDARY);
Expand Down
102 changes: 51 additions & 51 deletions src/meta/test/meta_partition_guardian_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ static void apply_update_request(/*in-out*/ configuration_update_request &update
switch (update_req.type) {
case config_type::CT_ASSIGN_PRIMARY:
case config_type::CT_UPGRADE_TO_PRIMARY:
SET_OBJ_IP_AND_HOST_PORT(pc, primary, update_req, node);
SET_OBJ_IP_AND_HOST_PORT(pc, primary, update_req, node1);
// TODO(yingchun): optimize the following code
replica_helper::remove_node(update_req.node, pc.secondaries);
replica_helper::remove_node(update_req.hp_node, pc.hp_secondaries);
replica_helper::remove_node(update_req.node1, pc.secondaries);
replica_helper::remove_node(update_req.hp_node1, pc.hp_secondaries);
break;

case config_type::CT_ADD_SECONDARY:
case config_type::CT_ADD_SECONDARY_FOR_LB:
ADD_IP_AND_HOST_PORT(pc, secondaries, update_req.node, update_req.hp_node);
ADD_IP_AND_HOST_PORT(pc, secondaries, update_req.node1, update_req.hp_node1);
update_req.type = config_type::CT_UPGRADE_TO_SECONDARY;
break;

case config_type::CT_REMOVE:
case config_type::CT_DOWNGRADE_TO_INACTIVE:
if (update_req.hp_node == pc.hp_primary) {
CHECK_EQ(update_req.node, pc.primary);
if (update_req.hp_node1 == pc.hp_primary) {
CHECK_EQ(update_req.node1, pc.primary);
RESET_IP_AND_HOST_PORT(pc, primary);
} else {
CHECK_NE(update_req.node, pc.primary);
replica_helper::remove_node(update_req.node, pc.secondaries);
replica_helper::remove_node(update_req.hp_node, pc.hp_secondaries);
CHECK_NE(update_req.node1, pc.primary);
replica_helper::remove_node(update_req.node1, pc.secondaries);
replica_helper::remove_node(update_req.hp_node1, pc.hp_secondaries);
}
break;

Expand Down Expand Up @@ -235,12 +235,12 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_UPGRADE_TO_PRIMARY);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node));
EXPECT_TRUE(is_secondary(pc, update_req->node));
EXPECT_EQ(target, update_req->hp_node);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node1));
EXPECT_TRUE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, update_req->hp_node1);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node1);

last_addr = update_req->hp_node;
last_addr = update_req->hp_node1;
proposal_sent = true;
return nullptr;
});
Expand All @@ -260,10 +260,10 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(config_type::CT_UPGRADE_TO_PRIMARY, update_req->type);
EXPECT_EQ(update_req->hp_node, last_addr);
EXPECT_EQ(update_req->node, dsn::dns_resolver::instance().resolve_address(last_addr));
EXPECT_EQ(target, update_req->hp_node);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node);
EXPECT_EQ(update_req->hp_node1, last_addr);
EXPECT_EQ(update_req->node1, dsn::dns_resolver::instance().resolve_address(last_addr));
EXPECT_EQ(target, update_req->hp_node1);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node1);

proposal_sent = true;
apply_update_request(*update_req);
Expand Down Expand Up @@ -299,13 +299,13 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_UPGRADE_TO_PRIMARY);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node));
EXPECT_TRUE(is_secondary(pc, update_req->node));
EXPECT_EQ(target, update_req->hp_node);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node1));
EXPECT_TRUE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, update_req->hp_node1);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node1);

proposal_sent = true;
last_addr = update_req->hp_node;
last_addr = update_req->hp_node1;
svc->set_node_state({target}, false);
return nullptr;
});
Expand All @@ -325,10 +325,10 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_UPGRADE_TO_PRIMARY);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node));
EXPECT_TRUE(is_secondary(pc, update_req->node));
EXPECT_EQ(target, update_req->hp_node);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node);
EXPECT_TRUE(is_secondary(pc, update_req->hp_node1));
EXPECT_TRUE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, update_req->hp_node1);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), update_req->node1);
EXPECT_NE(target, last_addr);

proposal_sent = true;
Expand Down Expand Up @@ -364,11 +364,11 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node));
EXPECT_FALSE(is_secondary(pc, update_req->node));
EXPECT_FALSE(is_secondary(pc, update_req->hp_node1));
EXPECT_FALSE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, nodes[0]);

last_addr = update_req->hp_node;
last_addr = update_req->hp_node1;
proposal_sent = true;
return nullptr;
});
Expand All @@ -388,8 +388,8 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_EQ(update_req->hp_node, last_addr);
EXPECT_EQ(update_req->node, dsn::dns_resolver::instance().resolve_address(last_addr));
EXPECT_EQ(update_req->hp_node1, last_addr);
EXPECT_EQ(update_req->node1, dsn::dns_resolver::instance().resolve_address(last_addr));
EXPECT_EQ(target, nodes[0]);

proposal_sent = true;
Expand Down Expand Up @@ -425,13 +425,13 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node));
EXPECT_FALSE(is_secondary(pc, update_req->node));
EXPECT_FALSE(is_secondary(pc, update_req->hp_node1));
EXPECT_FALSE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, nodes[0]);

update_req->config.ballot++;
update_req->type = config_type::CT_DOWNGRADE_TO_INACTIVE;
SET_OBJ_IP_AND_HOST_PORT(*update_req, node, update_req->config, secondaries[0]);
SET_OBJ_IP_AND_HOST_PORT(*update_req, node1, update_req->config, secondaries[0]);
CLEAR_IP_AND_HOST_PORT(update_req->config, secondaries);

proposal_sent = true;
Expand Down Expand Up @@ -467,12 +467,12 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node));
EXPECT_FALSE(is_secondary(pc, update_req->node));
EXPECT_FALSE(is_secondary(pc, update_req->hp_node1));
EXPECT_FALSE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, nodes[0]);

last_addr = update_req->hp_node;
svc->set_node_state({update_req->hp_node}, false);
last_addr = update_req->hp_node1;
svc->set_node_state({update_req->hp_node1}, false);
proposal_sent = true;
return nullptr;
});
Expand All @@ -492,13 +492,13 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_NE(update_req->hp_node, last_addr);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node));
EXPECT_FALSE(is_secondary(pc, update_req->node));
EXPECT_NE(update_req->hp_node1, last_addr);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node1));
EXPECT_FALSE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, nodes[0]);

proposal_sent = true;
last_addr = update_req->hp_node;
last_addr = update_req->hp_node1;
apply_update_request(*update_req);
svc->set_filter(default_filter);
return update_req;
Expand Down Expand Up @@ -531,8 +531,8 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ADD_SECONDARY);
EXPECT_FALSE(is_secondary(pc, update_req->hp_node));
EXPECT_FALSE(is_secondary(pc, update_req->node));
EXPECT_FALSE(is_secondary(pc, update_req->hp_node1));
EXPECT_FALSE(is_secondary(pc, update_req->node1));
EXPECT_EQ(target, pc.hp_primary);
EXPECT_EQ(dsn::dns_resolver::instance().resolve_address(target), pc.primary);

Expand Down Expand Up @@ -566,7 +566,7 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ASSIGN_PRIMARY);
EXPECT_EQ(update_req->hp_node, nodes[2]);
EXPECT_EQ(update_req->hp_node1, nodes[2]);
EXPECT_EQ(target, nodes[2]);

proposal_sent = true;
Expand Down Expand Up @@ -631,7 +631,7 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ASSIGN_PRIMARY);
EXPECT_EQ(update_req->hp_node, nodes[1]);
EXPECT_EQ(update_req->hp_node1, nodes[1]);
EXPECT_EQ(target, nodes[1]);

proposal_sent = true;
Expand Down Expand Up @@ -725,7 +725,7 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ASSIGN_PRIMARY);
EXPECT_EQ(update_req->hp_node, nodes[1]);
EXPECT_EQ(update_req->hp_node1, nodes[1]);
EXPECT_EQ(target, nodes[1]);

proposal_sent = true;
Expand All @@ -751,7 +751,7 @@ void meta_partition_guardian_test::cure_test()
destroy_message(recv_request);

EXPECT_EQ(update_req->type, config_type::CT_ASSIGN_PRIMARY);
EXPECT_EQ(update_req->hp_node, nodes[0]);
EXPECT_EQ(update_req->hp_node1, nodes[0]);
EXPECT_EQ(target, nodes[0]);

proposal_sent = true;
Expand Down Expand Up @@ -835,8 +835,8 @@ void meta_partition_guardian_test::cure()
fake_request.info = *app;
fake_request.config = pc;
fake_request.type = action.type;
SET_OBJ_IP_AND_HOST_PORT(fake_request, node, action, node);
fake_request.host_node = action.node;
SET_OBJ_IP_AND_HOST_PORT(fake_request, node1, action, node1);
fake_request.host_node1 = action.node1;

guardian.reconfig({&apps, &nodes}, fake_request);
check_nodes_loads(nodes);
Expand Down
Loading

0 comments on commit e674275

Please sign in to comment.