Debian Codegraph @

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

raw
1 ################################################################################
2 # Test case to verify that concurrent transactions with intersecting
3 # write set, on json array with unique keys, do conflict.
4 #
5 # Test:
6 # 0. The test requires two servers: M1 and M2.
7 # 1. With both members ONLINE. Create a table on M1.
8 # 2. Set a debug sync before broadcast message to group on M1. Commit a
9 # transaction that will be blocked before broadcast.
10 # 3. Wait until M1 reaches the debug sync point.
11 # 4. Execute a transaction on M2, that will reach first certification, since M1
12 # is blocked before broadcast.
13 # 5. Signal the waiting thread on M1 to resume.
14 # 6. It will end up in an error stating that it was aborted, since transactions
15 # are conflicting and M2 was ordered first.
16 # 7. Assert that number of certified transactions are the expected ones.
17 #
18 # Checking the positive case in which there is no conflict:
19 # 8. Set a debug sync before broadcast message to group on M1. Commit a
20 # transaction that will be block before broadcast.
21 # 9. Wait until M1 reaches the debug sync point.
22 # 10. Execute a transaction on M2, that will reach first certification, since M1
23 # is blocked before broadcast.
24 # 11. Signal the waiting thread on M1 to resume.
25 # 12. It will execute without error as the conflicting transactions have been
26 # removed.
27 # 13. Assert that number of certified transactions are the expected ones.
28 # 14. Clean up.
29 ################################################################################
30 --source include/have_debug_sync.inc
31 --source include/have_group_replication_plugin.inc
32 --source include/group_replication.inc
33
34
35 --echo
36 --echo ############################################################
37 --echo # Create a table on server1.
38 --let $rpl_connection_name= server1
39 --source include/rpl_connection.inc
40 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY, data JSON,
41 UNIQUE KEY zips((CAST(CAST(data AS JSON) AS UNSIGNED ARRAY))));
42 INSERT INTO t1(c1,data) VALUES (1,'[0,1,2]');
43 INSERT INTO t1(c1,data) VALUES (2,'[100,101]');
44 --source include/rpl_sync.inc
45
46
47 --echo
48 --echo ############################################################
49 --echo # Checking the conflict case.
50 --let $local_server_connection1=server1
51 --let $local_server_connection2=server_1
52 --let $remote_server_connection=server2
53 --let $local_transaction= UPDATE t1 SET data = '[6,7,8]' WHERE JSON_CONTAINS(CAST(data AS JSON),'1')
54 --let $remote_transaction=UPDATE t1 SET data = '[3,4,5]' WHERE JSON_CONTAINS(CAST(data AS JSON),'1')
55 --let $conflict_test=1
56 --source include/gr_parallel_local_and_remote_transactions.inc
57
58
59 --echo
60 --echo ############################################################
61 --echo # Checking the conflict case.
62 --let $local_server_connection1=server1
63 --let $local_server_connection2=server_1
64 --let $remote_server_connection=server2
65 --let $local_transaction= INSERT INTO t1(c1,data) VALUES (4,'[13,14]');
66 --let $remote_transaction=INSERT INTO t1(c1,data) VALUES (3,'[12,13]');
67 --let $conflict_test=1
68 --source include/gr_parallel_local_and_remote_transactions.inc
69
70
71 --echo
72 --echo ############################################################
73 --echo # Checking the positive case in which there is no conflict.
74 --let $local_server_connection1=server1
75 --let $local_server_connection2=server_1
76 --let $remote_server_connection=server2
77 --let $local_transaction= UPDATE t1 SET data = '[10,11]' WHERE JSON_CONTAINS(CAST(data AS JSON),'100')
78 --let $remote_transaction=UPDATE t1 SET data = '[9]' WHERE JSON_CONTAINS(CAST(data AS JSON),'3')
79 --let $conflict_test=0
80 --source include/gr_parallel_local_and_remote_transactions.inc
81
82
83 --echo
84 --echo ############################################################
85 --echo # Checking the positive case in which there is no conflict.
86 --let $local_server_connection1=server1
87 --let $local_server_connection2=server_1
88 --let $remote_server_connection=server2
89 --let $local_transaction= INSERT INTO t1(c1,data) VALUES (4,NULL);
90 --let $remote_transaction=INSERT INTO t1(c1,data) VALUES (5,NULL);
91 --let $conflict_test=0
92 --source include/gr_parallel_local_and_remote_transactions.inc
93
94
95 --echo
96 --echo ############################################################
97 --echo # Check the data sanity
98 --let $rpl_connection_name= server1
99 --source include/rpl_connection.inc
100
101 --let $assert_text= Table t1 will contain 2 rows after the above execution
102 --let $assert_cond= "[SELECT COUNT(*) FROM t1]" = "5"
103 --source include/assert.inc
104
105 --let $assert_text= Table t1 will contain row after the above execution
106 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1]" = "1"
107 --source include/assert.inc
108
109 --let $assert_text= Table t1 will contain row after the above execution
110 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 2, count, 1]" = "1"
111 --source include/assert.inc
112
113 --let $assert_text= Table t1 will contain row after the above execution
114 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 3, count, 1]" = "1"
115 --source include/assert.inc
116
117 --let $assert_text= Table t1 will contain row after the above execution
118 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 4, count, 1]" = "1"
119 --source include/assert.inc
120
121 --let $assert_text= Table t1 will contain row after the above execution
122 --let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 5, count, 1]" = "1"
123 --source include/assert.inc
124
125 SELECT * FROM t1;
126
127 --let $diff_tables=server1:t1, server2:t1
128 --source include/diff_tables.inc
129
130
131 --echo
132 --echo ############################################################
133 --echo # Clean up.
134 DROP TABLE t1;
135
136 --source include/group_replication_end.inc