Debian Codegraph @

mysql-test/suite/group_replication/include/gr_consistent_reads_after.inc

raw
1 # ==== Purpose ====
2 #
3 # Validate group_replication_consistency= 'AFTER' behaviour.
4 #
5 # Test:
6 # 00. The test requires two servers: M1 and M2.
7 # 01. Create two tables on the group.
8 # 02. Lock table t1 on server2 to block a future update.
9 # 03. Execute transaction T1, the transaction will block since
10 # server2 cannot prepare.
11 # 04. Validate transactions status.
12 # 05. Since T1 is not yet prepared on server2, new
13 # transactions are allowed.
14 # 06. Force server2 to block between T1 prepare and commit
15 # and unlock table t1.
16 # 07. Now that T1 is prepared on server2, server1 COMMIT is
17 # unblocked.
18 # 08. Now that T1 is prepared on server2 but it is not yet
19 # committed, new transactions are held.
20 # 09. Unblock T1 prepare on server2.
21 # 10. Clean up.
22 ################################################################################
23
24 #
25 # ==== Usage ====
26 #
27 # --let $set_gtid_next= UUID:GNO
28 #
29 #
30 # Parameters:
31 #
32 # $set_gtid_next
33 # Set the given GTID on transaction T1.
34 # We have two code paths on the certification code:
35 # 1) GTID generated automatically;
36 # 2) GTID assigned by SET GTID_NEXT.
37 # The parameter $set_gtid_next allow us to instrument both paths.
38 #
39 ################################################################################
40 --source include/have_debug_sync.inc
41 --source include/not_have_privilege_checks_user.inc
42 --source include/have_group_replication_plugin.inc
43 --source include/group_replication.inc
44
45 --echo
46 --echo ############################################################
47 --echo # 01. Create two tables on the group.
48 --let $rpl_connection_name= server1
49 --source include/rpl_connection.inc
50 SET @@SESSION.group_replication_consistency= 'AFTER';
51 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY);
52 CREATE TABLE t2 (c1 INT NOT NULL PRIMARY KEY);
53
54
55 --echo
56 --echo ############################################################
57 --echo # 02. Lock table t1 on server2 to block a future update.
58 --let $rpl_connection_name= server_2
59 --source include/rpl_connection.inc
60 LOCK table t1 READ;
61
62
63 --echo
64 --echo ############################################################
65 --echo # 03. Execute transaction T1, the transaction will block since
66 --echo # server2 cannot prepare.
67 --let $rpl_connection_name= server1
68 --source include/rpl_connection.inc
69 if ($set_gtid_next)
70 {
71 --eval SET GTID_NEXT= "$set_gtid_next"
72 }
73 BEGIN;
74 INSERT INTO t1 VALUES (1);
75 INSERT INTO t2 VALUES (1);
76 --send COMMIT
77
78
79 --echo
80 --echo ############################################################
81 --echo # 04. Validate transactions status.
82 # server1 is waiting for commit
83 --let $rpl_connection_name= server_1
84 --source include/rpl_connection.inc
85 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE user='root' AND state='waiting for handler commit' AND info='COMMIT'
86 --source include/wait_condition.inc
87
88 # server2 is waiting for the locked table
89 --let $rpl_connection_name= server2
90 --source include/rpl_connection.inc
91 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE user='system user' AND state='Waiting for table metadata lock'
92 --source include/wait_condition.inc
93
94
95 --echo
96 --echo ############################################################
97 --echo # 05. Since T1 is not yet prepared on server2, new
98 --echo # transactions are allowed.
99 --let $rpl_connection_name= server2
100 --source include/rpl_connection.inc
101 --let $assert_text= 'There are no values in table t2'
102 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2, count, 1] = 0
103 --source include/assert.inc
104
105
106 --echo
107 --echo ############################################################
108 --echo # 06. Force server2 to block between T1 prepare and commit
109 --echo # and unlock table t1.
110 --let $rpl_connection_name= server_2_1
111 --source include/rpl_connection.inc
112 SET @@GLOBAL.DEBUG= '+d,group_replication_wait_on_after_applier_prepare';
113
114 --let $rpl_connection_name= server_2
115 --source include/rpl_connection.inc
116 UNLOCK TABLES;
117
118 --let $rpl_connection_name= server_2_1
119 --source include/rpl_connection.inc
120 # Wait for the debug sync to be reached.
121 SET DEBUG_SYNC= "now WAIT_FOR signal.after_applier_prepare_waiting";
122
123
124 --echo
125 --echo ############################################################
126 --echo # 07. Now that T1 is prepared on server2, server1 COMMIT is
127 --echo # unblocked.
128 --let $rpl_connection_name= server1
129 --source include/rpl_connection.inc
130 --reap
131
132 if ($set_gtid_next)
133 {
134 SET GTID_NEXT= 'AUTOMATIC';
135 }
136
137 --let $assert_text= 'There is 1 value in table t1'
138 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE c1=1, count, 1] = 1
139 --source include/assert.inc
140
141 --let $assert_text= 'There is 1 value in table t2'
142 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=1, count, 1] = 1
143 --source include/assert.inc
144
145
146 --echo
147 --echo ############################################################
148 --echo # 08. Now that T1 is prepared on server2 but it is not yet
149 --echo # committed, new transactions are held.
150 --let $rpl_connection_name= server_2
151 --source include/rpl_connection.inc
152 --send SELECT COUNT(*) AS count FROM t2 WHERE c1=1
153
154 # server_2_1 is waiting for T1 to commit
155 --let $rpl_connection_name= server2
156 --source include/rpl_connection.inc
157 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE user='root' AND state='Executing hook on transaction begin.' AND info="SELECT COUNT(*) AS count FROM t2 WHERE c1=1"
158 --source include/wait_condition.inc
159
160
161 --echo
162 --echo ############################################################
163 --echo # 09. Unblock T1 prepare on server2.
164 --let $rpl_connection_name= server_2_1
165 --source include/rpl_connection.inc
166 # Signal debug sync to continue.
167 SET DEBUG_SYNC= 'now SIGNAL signal.after_applier_prepare_continue';
168 SET @@GLOBAL.DEBUG= '-d,group_replication_wait_on_after_applier_prepare';
169
170 --let $rpl_connection_name= server_2
171 --source include/rpl_connection.inc
172 --reap
173
174 --let $assert_text= 'There is 1 value in table t1'
175 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE c1=1, count, 1] = 1
176 --source include/assert.inc
177
178 --let $assert_text= 'There is 1 value in table t2'
179 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=1, count, 1] = 1
180 --source include/assert.inc
181
182
183 --echo
184 --echo ############################################################
185 --echo # 10. Clean up.
186 --let $rpl_connection_name= server1
187 --source include/rpl_connection.inc
188 DROP TABLE t1;
189 DROP TABLE t2;
190 SET @@SESSION.group_replication_consistency= DEFAULT;
191
192 --source include/group_replication_end.inc