Debian Codegraph @

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

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