Debian Codegraph @

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

raw
1 ################################################################################
2 # Validate group_replication_consistency= 'BEFORE' behaviour.
3 #
4 # Test:
5 # 00. The test requires three servers: M1, M2 and M3.
6 # 01. Create two tables on the group.
7 # 02. Lock table t1 on server2 to block a future update.
8 # 03. Execute transaction T1, the transaction will block on
9 # server2 due to the table lock.
10 # 04. Wait until T1 is delivered to server2.
11 # 05. Execute a read transaction on server2 with
12 # group_replication_consistency= 'BEFORE' , it will wait
13 # for T1 commit.
14 # 06. Execute a write transaction on server2 with
15 # group_replication_consistency= 'BEFORE' , it will wait
16 # for T1 commit.
17 # 07. Execute transaction T2 on server1, it will execute
18 # on all servers 1 and 3.
19 # 08. Unblock T1 on server2.
20 # 09. Validate data.
21 # 10. Clean up.
22 ################################################################################
23 --source include/have_group_replication_plugin.inc
24 --let $rpl_server_count= 3
25 --source include/group_replication.inc
26
27 --echo
28 --echo ############################################################
29 --echo # 01. Create two tables on the group.
30 --let $rpl_connection_name= server1
31 --source include/rpl_connection.inc
32 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY);
33 CREATE TABLE t2 (c1 INT NOT NULL PRIMARY KEY);
34 --source include/rpl_sync.inc
35
36
37 --echo
38 --echo ############################################################
39 --echo # 02. Lock table t1 on server2 to block a future update.
40 --let $rpl_connection_name= server_2
41 --source include/rpl_connection.inc
42 LOCK table t1 READ;
43
44
45 --echo
46 --echo ############################################################
47 --echo # 03. Execute transaction T1, the transaction will block on
48 --echo # server2 due to the table lock.
49 --let $rpl_connection_name= server1
50 --source include/rpl_connection.inc
51 BEGIN;
52 INSERT INTO t1 VALUES (1);
53 INSERT INTO t2 VALUES (100);
54 COMMIT;
55
56
57 --echo
58 --echo ############################################################
59 --echo # 04. Wait until T1 is delivered to server2.
60 --let $rpl_connection_name= server2
61 --source include/rpl_connection.inc
62 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
63 --let $wait_condition= SELECT COUNT(*)=1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member2_uuid' AND count_transactions_checked=3 AND count_transactions_remote_in_applier_queue=1
64 --source include/wait_condition.inc
65
66
67 --echo
68 --echo ############################################################
69 --echo # 05. Execute a read transaction on server2 with
70 --echo # group_replication_consistency= 'BEFORE' , it will wait
71 --echo # for T1 commit.
72 --let $rpl_connection_name= server_2_1
73 --source include/rpl_connection.inc
74 SET @@SESSION.group_replication_consistency= 'BEFORE';
75 --send SELECT COUNT(*) AS count FROM t2 WHERE c1 >= 99
76
77 --let $rpl_connection_name= server2
78 --source include/rpl_connection.inc
79 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Executing hook on transaction begin.' AND info='SELECT COUNT(*) AS count FROM t2 WHERE c1 >= 99'
80 --source include/wait_condition.inc
81
82
83 --echo
84 --echo ############################################################
85 --echo # 06. Execute a write transaction on server2 with
86 --echo # group_replication_consistency= 'BEFORE' , it will wait
87 --echo # for T1 commit.
88 --let $rpl_connection_name= slave
89 --source include/rpl_connection.inc
90 SET @@SESSION.group_replication_consistency= 'BEFORE';
91 --send UPDATE t2 SET c1=99 WHERE c1=100
92
93 --let $rpl_connection_name= server2
94 --source include/rpl_connection.inc
95 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Executing hook on transaction begin.' AND info='UPDATE t2 SET c1=99 WHERE c1=100'
96 --source include/wait_condition.inc
97
98
99 --echo
100 --echo ############################################################
101 --echo # 07. Execute transaction T2 on server1, it will execute
102 --echo # on servers 1 and 3.
103 --echo # server2 will apply it in order not because of the
104 --echo # consistency but due to --replica_preserve_commit_order
105 --echo # or single thread applier which will make T2 be
106 --echo # committed after the UPDATE.
107 --let $rpl_connection_name= server1
108 --source include/rpl_connection.inc
109 INSERT INTO t2 VALUES (2);
110
111 --let $assert_text= 'There is a 2 in table t2'
112 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=2, count, 1] = 1
113 --source include/assert.inc
114
115 --let $rpl_connection_name= server3
116 --source include/rpl_connection.inc
117 --let $wait_condition=SELECT COUNT(*)=1 FROM t2 WHERE c1=2
118 --source include/wait_condition.inc
119
120
121 --echo
122 --echo ############################################################
123 --echo # 08. Unblock T1 on server2.
124 --let $rpl_connection_name= server_2
125 --source include/rpl_connection.inc
126 UNLOCK TABLES;
127
128 --let $rpl_connection_name= server_2_1
129 --source include/rpl_connection.inc
130 --reap
131 SET @@SESSION.group_replication_consistency= DEFAULT;
132
133 --let $rpl_connection_name= slave
134 --source include/rpl_connection.inc
135 --reap
136 SET @@SESSION.group_replication_consistency= DEFAULT;
137
138
139 --echo
140 --echo ############################################################
141 --echo # 09. Validate data.
142 --let $rpl_connection_name= server2
143 --source include/rpl_connection.inc
144 --let $assert_text= 'There is a 1 in table t1'
145 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE c1=1, count, 1] = 1
146 --source include/assert.inc
147
148 --let $assert_text= 'There is a 99 in table t2'
149 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=99, count, 1] = 1
150 --source include/assert.inc
151
152 # Ensure that T2 is already committed on server2.
153 --source include/rpl_sync.inc
154 --let $rpl_connection_name= server2
155 --source include/rpl_connection.inc
156 --let $assert_text= 'There is a 2 in table t2'
157 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=2, count, 1] = 1
158 --source include/assert.inc
159
160 --let $rpl_connection_name= server1
161 --source include/rpl_connection.inc
162 --let $assert_text= 'There is a 1 in table t1'
163 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE c1=1, count, 1] = 1
164 --source include/assert.inc
165
166 --let $assert_text= 'There is a 99 in table t2'
167 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=99, count, 1] = 1
168 --source include/assert.inc
169
170 --let $assert_text= 'There is a 2 in table t2'
171 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=2, count, 1] = 1
172 --source include/assert.inc
173
174 --let $rpl_connection_name= server3
175 --source include/rpl_connection.inc
176 --let $assert_text= 'There is a 1 in table t1'
177 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE c1=1, count, 1] = 1
178 --source include/assert.inc
179
180 --let $assert_text= 'There is a 99 in table t2'
181 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=99, count, 1] = 1
182 --source include/assert.inc
183
184 --let $assert_text= 'There is a 2 in table t2'
185 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2 WHERE c1=2, count, 1] = 1
186 --source include/assert.inc
187
188 --let $diff_tables=server1:t1, server2:t1, server3:t1
189 --source include/diff_tables.inc
190
191 --let $diff_tables=server1:t2, server2:t2, server3:t2
192 --source include/diff_tables.inc
193
194
195 --echo
196 --echo ############################################################
197 --echo # 10. Clean up.
198 --let $rpl_connection_name= server1
199 --source include/rpl_connection.inc
200 DROP TABLE t1;
201 DROP TABLE t2;
202
203 --source include/group_replication_end.inc