Debian Codegraph @

mysql-test/suite/group_replication/t/gr_switch_primary_timeout_transactions_commit_rollback.test

raw
1 ################################################################################
2 # This test validates UDF group_replication_set_as_primary and confirms
3 # that connection running a transactions that did not reach commit stage is
4 # disconnected when UDF group_replication_set_as_primary is executed.
5 # UDF group_replication_set_as_primary runs successfully and primary is changed.
6 #
7 # Test:
8 # 0. The test requires two servers: M1 and M2.
9 # 1. Setup group of 2 servers, M1(primary) and M2(secondary).
10 # 2. Block all commits on server1 and initiate a transaction.
11 # Begin change of primary from server2(secondary).
12 # 3. Unblock transactions on server1.
13 # Transaction should fail it was not committing so it was killed
14 # and client connection dropped.
15 # 4. Assert primary changed.
16 # Assert data is not present on M1 and M2.
17 # 5. Block all commits on server2 and initiate a transaction.
18 # Begin change of primary from server2(primary).
19 # 6. Unblock transactions on server2.
20 # Transaction should fail it was not committing so it was killed
21 # and client connection dropped.
22 # 7. Assert primary changed.
23 # Assert data is not present on M1 and M2.
24 # 8. Cleanup.
25 ################################################################################
26
27 --source include/have_debug_sync.inc
28 --source include/have_group_replication_plugin.inc
29 --let $rpl_skip_group_replication_start= 1
30 --let $rpl_group_replication_single_primary_mode=1
31 --source include/group_replication.inc
32
33 --echo
34 --echo # 1. Setup group of 2 servers, M1(primary) and M2(secondary).
35
36 --let $rpl_connection_name= server1
37 --source include/rpl_connection.inc
38
39 --let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
40
41 --source include/start_and_bootstrap_group_replication.inc
42
43 CREATE TABLE t1(c1 int primary key);
44
45 --let $rpl_connection_name= server2
46 --source include/rpl_connection.inc
47
48 --let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
49
50 --source include/start_group_replication.inc
51
52 --echo
53 --echo # 2. Block all commits on server1 and initiate a transaction.
54 --echo # Begin change of primary from server2(secondary).
55
56 --let $rpl_connection_name= server1
57 --source include/rpl_connection.inc
58
59 SET @@GLOBAL.DEBUG= '+d,trans_delegate_before_commit_before_before_call_observers';
60
61 --send INSERT INTO t1 values(1)
62
63 --let $rpl_connection_name= server_1
64 --source include/rpl_connection.inc
65
66 SET DEBUG_SYNC= "now WAIT_FOR signal.trans_delegate_before_commit_before_before_call_observers_reached";
67 SET @@GLOBAL.DEBUG= '-d,trans_delegate_before_commit_before_before_call_observers';
68
69 --let $rpl_connection_name= server2
70 --source include/rpl_connection.inc
71
72 # There is an ongoing transaction INSERT going on.
73 # So UDF group_replication_set_as_primary will start but to
74 # finish successfully all ongoing transactions must finish.
75 # UDF group_replication_set_as_primary finishes successfully
76 # after setting the killed flag in THD running INSERT operation post expiry of
77 # timeout and killed transactions are not counted by service
78 # `mysql_ongoing_transactions_query`
79 --replace_result $server2_uuid SERVER2_UUID
80 --eval SELECT group_replication_set_as_primary("$server2_uuid", 0);
81
82 --echo
83 --echo # 3. Unblock transactions on server1.
84 --echo # Transaction should fail it was not committing so it was killed
85 --echo # and client connection dropped.
86
87 --let $rpl_connection_name= server_1
88 --source include/rpl_connection.inc
89
90 SET DEBUG_SYNC= "now SIGNAL signal.trans_delegate_before_commit_before_before_call_observers_waiting";
91
92 --let $rpl_connection_name= server1
93 --source include/rpl_connection.inc
94 --error CR_SERVER_LOST
95 --reap
96
97 --enable_reconnect
98 --source include/wait_until_connected_again.inc
99 --disable_reconnect
100
101 SET DEBUG_SYNC= 'RESET';
102
103 --echo
104 --echo # 4. Assert primary changed.
105 --echo # Assert data is not present on M1 and M2.
106
107 --let $rpl_connection_name= server2
108 --source include/rpl_connection.inc
109
110 --source include/gr_assert_primary_member.inc
111
112 --let $rpl_connection_name= server1
113 --source include/rpl_connection.inc
114
115 --source include/gr_assert_secondary_member.inc
116
117 --let $assert_text= 'There is no value 1 in table t1.'
118 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 0
119 --source include/assert.inc
120
121 --let $diff_tables= server1:test.t1, server2:test.t1
122 --source include/diff_tables.inc
123
124 --echo
125 --echo # 5. Block all commits on server2 and initiate a transaction.
126 --echo # Begin change of primary from server2(primary).
127
128 --let $rpl_connection_name= server2
129 --source include/rpl_connection.inc
130
131 SET @@GLOBAL.DEBUG= '+d,trans_delegate_before_commit_before_before_call_observers';
132
133 --send INSERT INTO t1 values(1)
134
135 --let $rpl_connection_name= server_2
136 --source include/rpl_connection.inc
137
138 SET DEBUG_SYNC= "now WAIT_FOR signal.trans_delegate_before_commit_before_before_call_observers_reached";
139 SET @@GLOBAL.DEBUG= '-d,trans_delegate_before_commit_before_before_call_observers';
140
141 --replace_result $server1_uuid SERVER1_UUID
142 --eval SELECT group_replication_set_as_primary("$server1_uuid", 2);
143
144 --echo
145 --echo # 6. Unblock transactions on server2.
146 --echo # Transaction should fail it was not committing so it was killed
147 --echo # and client connection dropped.
148
149 SET DEBUG_SYNC= "now SIGNAL signal.trans_delegate_before_commit_before_before_call_observers_waiting";
150
151 --let $rpl_connection_name= server2
152 --source include/rpl_connection.inc
153
154 --error CR_SERVER_LOST
155 --reap
156
157 --enable_reconnect
158 --source include/wait_until_connected_again.inc
159 --disable_reconnect
160
161 SET DEBUG_SYNC= 'RESET';
162
163 --echo
164 --echo # 7. Assert primary changed.
165 --echo # Assert data is not present on M1 and M2.
166
167 --let $rpl_connection_name= server1
168 --source include/rpl_connection.inc
169
170 --source include/gr_assert_primary_member.inc
171
172 --let $rpl_connection_name= server2
173 --source include/rpl_connection.inc
174
175 --source include/gr_assert_secondary_member.inc
176
177 --let $assert_text= 'There is no value 1 in table t1.'
178 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 0
179 --source include/assert.inc
180
181 --let $diff_tables= server1:test.t1, server2:test.t1
182 --source include/diff_tables.inc
183
184 --echo
185 --echo # 8. Cleanup.
186
187 --let $rpl_connection_name= server1
188 --source include/rpl_connection.inc
189
190 DROP TABLE t1;
191 --source include/rpl_sync.inc
192
193 --source include/group_replication_end.inc