Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Jul 22, 2024
1 parent f08ce98 commit 2284105
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/common/replication_other_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ inline bool is_member(const partition_configuration &pc, const rpc_address &node
inline bool is_partition_config_equal(const partition_configuration &pc1,
const partition_configuration &pc2)
{
// secondaries no need to be same order
if (pc1.ballot != pc2.ballot || pc1.pid != pc2.pid ||
pc1.max_replica_count != pc2.max_replica_count ||
pc1.last_committed_decree != pc2.last_committed_decree) {
return false;
}

host_port pc1_primary;
GET_HOST_PORT(pc1, primary, pc1_primary);
host_port pc2_primary;
GET_HOST_PORT(pc2, primary, pc2_primary);
if (pc1_primary != pc2_primary) {
return false;
}

// secondaries no need to be in the same order.
std::vector<host_port> pc1_secondaries;
GET_HOST_PORTS(pc1, secondaries, pc1_secondaries);
for (const auto &pc1_secondary : pc1_secondaries) {
Expand All @@ -88,17 +102,10 @@ inline bool is_partition_config_equal(const partition_configuration &pc1,
}
}

// last_drops is not considered into equality check
host_port pc1_primary;
GET_HOST_PORT(pc1, primary, pc1_primary);
host_port pc2_primary;
GET_HOST_PORT(pc2, primary, pc2_primary);
std::vector<host_port> pc2_secondaries;
GET_HOST_PORTS(pc2, secondaries, pc2_secondaries);
return pc1.ballot == pc2.ballot && pc1.pid == pc2.pid &&
pc1.max_replica_count == pc2.max_replica_count && pc1_primary == pc2_primary &&
pc1_secondaries.size() == pc2_secondaries.size() &&
pc1.last_committed_decree == pc2.last_committed_decree;
// last_drops is not considered into equality check
return pc1_secondaries.size() == pc2_secondaries.size();
}

class replica_helper
Expand Down
2 changes: 1 addition & 1 deletion src/replica/storage/simple_kv/test/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void parti_config::convert_from(const partition_configuration &pc)
pid = pc.pid;
ballot = pc.ballot;
primary = address_to_node(pc.hp_primary);
for (auto &secondary : pc.hp_secondaries) {
for (const auto &secondary : pc.hp_secondaries) {
secondaries.push_back(address_to_node(secondary));
}
std::sort(secondaries.begin(), secondaries.end());
Expand Down

0 comments on commit 2284105

Please sign in to comment.