Debian Codegraph @

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

raw
1 ################################################################################
2 # Test case to verify that concurrent transactions with intersecting
3 # write set, the same primary key, do conflict.
4 #
5 # Scenario 8.2: WL#6834
6 #
7 # T1: WS={t1.a= 1}
8 #
9 # T2: WS={t1.a= 1}
10 #
11 # Outcome: T1 must abort, T2 must commit.
12 #
13 # Full details on WL#6834 QA notes.
14 #
15 # Test:
16 # 0. The test requires two servers: M1 and M2.
17 # 1. With both members ONLINE. Create a table on M1.
18 # 2. Set a debug sync before broadcast message to group on M1. Commit a
19 # transaction that will be block before broadcast.
20 # 3. Wait until M1 reaches the debug sync point.
21 # 4. Execute a transaction on M2, that will reach first certification, since M1
22 # is blocked before broadcast.
23 # 5. Signal the waiting thread on M1 to resume.
24 # 6. It will end up in an error stating that it was aborted, since transactions
25 # are conflicting and M2 was ordered first.
26 # 7. Assert that number of certified transactions are the expected ones.
27 #
28 # Checking the positive case in which there is no conflict:
29 # 8. Set a debug sync before broadcast message to group on M1. Commit a
30 # transaction that will be block before broadcast.
31 # 9. Wait until M1 reaches the debug sync point.
32 # 10. Execute a transaction on M2, that will reach first certification, since M1
33 # is blocked before broadcast.
34 # 11. Signal the waiting thread on M1 to resume.
35 # 12. It will execute without error as the conflicting transactions have been
36 # removed.
37 # 13. Assert that number of certified transactions are the expected ones.
38 # 14. Clean up.
39 ################################################################################
40
41 --source include/have_debug_sync.inc
42 --source include/have_group_replication_plugin.inc
43 --source include/group_replication.inc
44
45 --echo
46 --echo ############################################################
47 --echo # 1. Create a table on server1.
48 --let $rpl_connection_name= server1
49 --source include/rpl_connection.inc
50 CREATE TABLE t1 (c1 INT PRIMARY KEY);
51 --source include/rpl_sync.inc
52
53 --echo
54 --echo ############################################################
55 --echo # 2. Set a debug sync before broadcast message to group on
56 --echo # connection server_1.
57 --echo # Commit a transaction that will be block before broadcast.
58 --let $rpl_connection_name= server_1
59 --source include/rpl_connection.inc
60 SET @debug_save= @@GLOBAL.DEBUG;
61 SET @@GLOBAL.DEBUG='d,group_replication_before_message_broadcast';
62 XA START 'trx';
63 INSERT INTO t1 VALUES (1);
64 XA END 'trx';
65 --send XA PREPARE 'trx'
66
67 --echo
68 --echo ############################################################
69 --echo # 3. Wait until server_1 connection reaches the
70 --echo # group_replication_before_message_broadcast debug sync point.
71 --let $rpl_connection_name= server1
72 --source include/rpl_connection.inc
73 --let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now'
74 --source include/wait_condition.inc
75
76 --echo
77 --echo ############################################################
78 --echo # 4. Execute a transaction on server2, that will reach first
79 --echo # certification, since server_1 is blocked before broadcast.
80 --let $rpl_connection_name= server2
81 --source include/rpl_connection.inc
82 INSERT INTO t1 VALUES (1);
83
84 --echo
85 --echo ############################################################
86 --echo # 5. Signal the waiting thread on server_1 to resume.
87 --let $rpl_connection_name= server1
88 --source include/rpl_connection.inc
89
90 # Wait for the transaction from server 2 to be certified
91 --let $member1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
92 --let $wait_condition= SELECT COUNT(*)=1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member1_uuid' AND count_transactions_checked=2
93 --source include/wait_condition.inc
94
95 SET DEBUG_SYNC='now SIGNAL waiting';
96 SET @@GLOBAL.DEBUG= @debug_save;
97
98 --echo
99 --echo ############################################################
100 --echo # 6. It will end up in an error stating that it was aborted,
101 --echo # since transactions are conflicting and server2 was
102 --echo # ordered first.
103 --let $rpl_connection_name= server_1
104 --source include/rpl_connection.inc
105 --error ER_TRANSACTION_ROLLBACK_DURING_COMMIT
106 --reap
107
108 --error ER_XAER_NOTA
109 XA COMMIT 'trx';
110
111 --echo
112 --echo ############################################################
113 --echo # 7. Assert that number of certified transactions are the
114 --echo # expected ones.
115 --let $rpl_connection_name= server1
116 --source include/rpl_connection.inc
117
118 --let $certified_transactions= query_get_value(SELECT Count_Transactions_Checked from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Transactions_Checked, 1)
119 --let $assert_text= The value of Count_Transactions_Checked should be 3 after starting group replication
120 --let $assert_cond= "$certified_transactions" = 3
121 --source include/assert.inc
122
123 --let $negatively_certified= query_get_value(SELECT Count_Conflicts_Detected from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Conflicts_Detected, 1)
124 --let $assert_text= The value of Count_Conflicts_Detected should be 1 after starting group replication
125 --let $assert_cond= "$negatively_certified" = 1
126 --source include/assert.inc
127
128 --echo
129 --echo ############################################################
130 --echo # Checking the positive case in which there is no conflict.
131 --echo ############################################################
132 --echo
133 --echo ############################################################
134 --echo # 1. Set a debug sync before broadcast message to group on
135 --echo # connection server_1.
136 --echo # Commit a transaction that will be block before broadcast.
137 --let $rpl_connection_name= server_1
138 --source include/rpl_connection.inc
139 SET @@GLOBAL.DEBUG='d,group_replication_before_message_broadcast';
140 XA START 'trx2';
141 INSERT INTO t1 VALUES (2);
142 XA END 'trx2';
143 --send XA PREPARE 'trx2'
144
145 --echo
146 --echo ############################################################
147 --echo # 2. Wait until server_1 connection reaches the
148 --echo # group_replication_before_message_broadcast debug sync point.
149 --let $rpl_connection_name= server1
150 --source include/rpl_connection.inc
151 --let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now'
152 --source include/wait_condition.inc
153
154 --echo
155 --echo ############################################################
156 --echo # 3. Execute a transaction on server2, that will reach first
157 --echo # certification, since server_1 is blocked before broadcast.
158 --let $rpl_connection_name= server2
159 --source include/rpl_connection.inc
160 INSERT INTO t1 VALUES (3);
161 --let $sync_slave_connection= server1
162 --source include/sync_slave_sql_with_master.inc
163
164 --echo
165 --echo ############################################################
166 --echo # 4. Signal the waiting thread on server_1 to resume.
167 --let $rpl_connection_name= server1
168 --source include/rpl_connection.inc
169 SET DEBUG_SYNC='now SIGNAL waiting';
170 SET @@GLOBAL.DEBUG= @debug_save;
171
172 --echo
173 --echo ########################################################################
174 --echo # 5. It will execute without error as the conflicting transactions have
175 --echo # been removed.
176 --let $rpl_connection_name= server_1
177 --source include/rpl_connection.inc
178 --reap
179 XA COMMIT 'trx2';
180
181 --source include/rpl_sync.inc
182 --echo
183 --echo ############################################################
184 --echo # 6. Assert that number of certified transactions are the
185 --echo # expected ones.
186 --let $rpl_connection_name= server1
187 --source include/rpl_connection.inc
188
189 --let $assert_text= Table t1 will contain row after the above execution
190 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1]" = "1"
191 --source include/assert.inc
192
193 --let $assert_text= Table t1 will contain row after the above execution
194 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 2, count, 1]" = "1"
195 --source include/assert.inc
196
197 --let $assert_text= Table t1 will contain row after the above execution
198 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 3, count, 1]" = "1"
199 --source include/assert.inc
200
201 --let $assert_text= Table t1 will contain 3 rows after the above execution
202 --let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "3"
203 --source include/assert.inc
204
205 --let $certified_transactions= query_get_value(SELECT Count_Transactions_Checked from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Transactions_Checked, 1)
206 --let $assert_text= The value of Count_Transactions_Checked should be 6 after starting group replication
207 --let $assert_cond= "$certified_transactions" = 6
208 --source include/assert.inc
209
210 --let $negatively_certified= query_get_value(SELECT Count_Conflicts_Detected from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Conflicts_Detected, 1)
211 --let $assert_text= The value of Count_Conflicts_Detected should be 1 after starting group replication
212 --let $assert_cond= "$negatively_certified" = 1
213 --source include/assert.inc
214
215 --echo
216 --echo ############################################################
217 --echo # Clean up.
218 DROP TABLE t1;
219
220 --source include/group_replication_end.inc