Debian Codegraph @

unittest/gunit/libmysqlgcs/xcom/gcs_xcom_expels_in_progress-t.cc

raw symbols SCIP
1 /* Copyright (c) 2020, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 #include "unittest/gunit/libmysqlgcs/include/gcs_base_test.h"
24
25 #include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_expels_in_progress.h"
26
27 namespace gcs_xcom_expels_in_progress_unittest {
28
29 class GcsXcomExpelsInProgressTest : public GcsBaseTest {
30 protected:
31 GcsXcomExpelsInProgressTest() = default;
32
33 ~GcsXcomExpelsInProgressTest() override = default;
34
35 Gcs_xcom_expels_in_progress m_expels_in_progress;
36 };
37
38 /* This test validates the memory of expels in progress that the GCS suspicion
39 manager keeps track of.
40
41 It checks that we keep track of expels and the configuration ID that lead to
42 them.
43 It checks that we count members that were expelled but not yet removed as
44 suspects for the purposes of majority calculation. It checks that we forget
45 about expels once they take effect in a
46 configuration after the one in which the expels were issued. */
47 TEST_F(GcsXcomExpelsInProgressTest, ExpelTracking) {
48 std::string m1_endpoint{"127.0.0.1:12345"};
49 auto m1_gcs = std::make_unique<Gcs_member_identifier>(m1_endpoint);
50 Gcs_xcom_node_information m1_xcom{m1_endpoint};
51 std::string m2_endpoint{"127.0.0.1:12346"};
52 auto m2_gcs = std::make_unique<Gcs_member_identifier>(m2_endpoint);
53 Gcs_xcom_node_information m2_xcom{m2_endpoint};
54 std::string m3_endpoint{"127.0.0.1:12347"};
55 auto m3_gcs = std::make_unique<Gcs_member_identifier>(m3_endpoint);
56 Gcs_xcom_node_information m3_xcom{m3_endpoint};
57
58 Gcs_xcom_nodes expels_issued;
59 synode_no synode_0{0, 0, 0};
60 synode_no synode_1{0, 1, 0};
61 synode_no synode_2{0, 2, 0};
62 synode_no synode_3{0, 3, 0};
63 std::vector<Gcs_member_identifier *> suspected_members;
64 std::vector<Gcs_member_identifier *> suspected_nonmembers;
65 std::vector<Gcs_member_identifier *> members_that_left;
66
67 /* Expel m1 in synode_1.
68
69 expels={m1} */
70 expels_issued.add_node(m1_xcom);
71 m_expels_in_progress.remember_expels_issued(synode_1, expels_issued);
72 ASSERT_EQ(m_expels_in_progress.size(), 1);
73 ASSERT_TRUE(m_expels_in_progress.contains(*m1_gcs.get(), synode_1));
74 expels_issued.clear_nodes();
75
76 /* Expel m2 in synode_2.
77
78 expels={m1,m2} */
79 expels_issued.add_node(m2_xcom);
80 m_expels_in_progress.remember_expels_issued(synode_2, expels_issued);
81 ASSERT_EQ(m_expels_in_progress.size(), 2);
82 ASSERT_TRUE(m_expels_in_progress.contains(*m2_gcs.get(), synode_2));
83 expels_issued.clear_nodes();
84
85 /* Count m2 as "alive and expelled but not yet removed."
86
87 expels={m1,m2}
88 suspects={m1} */
89 suspected_members.push_back(m1_gcs.get());
90 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
91 suspected_members, suspected_nonmembers),
92 1);
93 suspected_members.clear();
94
95 /* Count m1 as "alive and expelled but not yet removed."
96
97 expels={m1,m2}
98 suspects={m2} */
99 suspected_nonmembers.push_back(m2_gcs.get());
100 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
101 suspected_members, suspected_nonmembers),
102 1);
103 suspected_nonmembers.clear();
104
105 /* Count no one as "alive and expelled but not yet removed."
106
107 expels={m1,m2}
108 suspects={m1,m2} */
109 suspected_members.push_back(m2_gcs.get());
110 suspected_nonmembers.push_back(m1_gcs.get());
111 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
112 suspected_members, suspected_nonmembers),
113 0);
114 suspected_members.clear();
115 suspected_nonmembers.clear();
116
117 /* Count m1 and m2 as "alive and expelled but not yet removed."
118
119 expels={m1,m2}
120 suspects={} */
121 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
122 suspected_members, suspected_nonmembers),
123 2);
124
125 /* Count m1 and m2 as "alive and expelled but not yet removed."
126
127 expels={m1,m2}
128 suspects={m3} */
129 suspected_members.push_back(m3_gcs.get());
130 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
131 suspected_members, suspected_nonmembers),
132 2);
133 suspected_members.clear();
134
135 suspected_nonmembers.push_back(m3_gcs.get());
136 ASSERT_EQ(m_expels_in_progress.number_of_expels_not_about_suspects(
137 suspected_members, suspected_nonmembers),
138 2);
139 suspected_nonmembers.clear();
140
141 /* Do not forget that we expelled m1 on synode_1 due to view from the past
142 (synode_0).
143
144 expels={(m1,1)}
145 left={m1} synode=0 */
146 members_that_left.push_back(m1_gcs.get());
147 m_expels_in_progress.forget_expels_that_have_taken_effect(synode_0,
148 members_that_left);
149 ASSERT_EQ(m_expels_in_progress.size(), 2);
150 members_that_left.clear();
151
152 /* Do not forget that we expelled m2 on synode_2 due to view from the past
153 (synode_1).
154
155 expels={(m2,2)}
156 left={m2} synode=1 */
157 members_that_left.push_back(m2_gcs.get());
158 m_expels_in_progress.forget_expels_that_have_taken_effect(synode_1,
159 members_that_left);
160 ASSERT_EQ(m_expels_in_progress.size(), 2);
161 members_that_left.clear();
162
163 /* Do not forget that we expelled m1 and m2.
164
165 expels={(m1,1); (m2,2)}
166 left={} synode=3 */
167 m_expels_in_progress.forget_expels_that_have_taken_effect(synode_3,
168 members_that_left);
169 ASSERT_EQ(m_expels_in_progress.size(), 2);
170
171 /* Do not forget that we expelled m1 and m2.
172
173 expels={(m1,1); (m2,2)}
174 left={m3} synode=3 */
175 members_that_left.push_back(m3_gcs.get());
176 m_expels_in_progress.forget_expels_that_have_taken_effect(synode_3,
177 members_that_left);
178 ASSERT_EQ(m_expels_in_progress.size(), 2);
179 members_that_left.clear();
180
181 /* Forget that we expelled m1 and m2.
182
183 expels={(m1,1); (m2,2)}
184 left={m1,m2} synode=3 */
185 members_that_left.push_back(m1_gcs.get());
186 members_that_left.push_back(m2_gcs.get());
187 members_that_left.push_back(m3_gcs.get());
188 m_expels_in_progress.forget_expels_that_have_taken_effect(synode_3,
189 members_that_left);
190 ASSERT_EQ(m_expels_in_progress.size(), 0);
191 members_that_left.clear();
192 }
193 } // namespace gcs_xcom_expels_in_progress_unittest