Debian Codegraph @

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

raw
1 ################################################################################
2 # Validate the behaviour of consistent transactions during primary failover.
3 #
4 # Test:
5 # 00. The test requires three servers: server1,server2,server3
6 # 01. Create a table on the group.
7 # 02. Lock table t1 on server3
8 # 03. Perform a trasanction T1 on server1 on table t1 with 'AFTER'
9 # 04. Try to query table t1 (Transaction T2) on server2, it
10 # will be blocked since T1 is prepared but not committed.
11 # 05. Crash server1. Ensure that server2 is elected as primary.
12 # 06. Unlock tables on server3. Check the transaction from
13 # server1 succeeds now.
14 # 07. Check that transaction T2 will read transaction T1 data.
15 # 08. Clean up.
16 ################################################################################
17
18 #
19 # ==== Usage ====
20 #
21 # --let $transaction_T2_consistency= ...
22 # --let $transaction_T2_error= ERROR_NAME
23 #
24 #
25 # Parameters:
26 #
27 # $transaction_T2_consistency
28 # Set the given consistency guarantee to transaction T2.
29 # $transaction_T2_error
30 # Expect this error from T2 outcome.
31 #
32 ################################################################################
33
34 --source include/big_test.inc
35 --source include/have_debug_sync.inc
36 # Don't test this under valgrind, memory leaks will occur
37 --source include/not_valgrind.inc
38 --source include/force_restart.inc
39 --source include/have_group_replication_plugin.inc
40 --let $rpl_group_replication_single_primary_mode=1
41 --let $rpl_server_count= 3
42 --let $rpl_skip_group_replication_start= 1
43 --source include/group_replication.inc
44
45
46 --echo
47 --echo ############################################################
48 --echo # 01. Create a table on the group.
49 --let $rpl_connection_name= server1
50 --source include/rpl_connection.inc
51 --source include/start_and_bootstrap_group_replication.inc
52 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY);
53
54 --let $rpl_connection_name= server2
55 --source include/rpl_connection.inc
56
57 --source include/start_group_replication.inc
58 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
59
60 --let $rpl_connection_name= server3
61 --source include/rpl_connection.inc
62
63 --source include/start_group_replication.inc
64
65
66 --echo
67 --echo ############################################################
68 --echo # 02. Lock table t1 on server3
69 --let $rpl_connection_name= server3
70 --source include/rpl_connection.inc
71 LOCK TABLE t1 READ;
72
73
74 --echo
75 --echo ############################################################
76 --echo # 03. Perform a transaction T1 on server1 on table t1 with 'AFTER'
77 --let $rpl_connection_name= server1
78 --source include/rpl_connection.inc
79
80 SET @@SESSION.group_replication_consistency='AFTER';
81 --send INSERT INTO t1 VALUES(11)
82
83 # Check that T1 is blocked on server1, server2 for server3's ack.
84 --let $rpl_connection_name= server_1
85 --source include/rpl_connection.inc
86 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state LIKE 'waiting for handler commit' AND info LIKE 'INSERT INTO t1 VALUES%'
87 --source include/wait_condition.inc
88
89 --let $rpl_connection_name= server2
90 --source include/rpl_connection.inc
91 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.threads WHERE processlist_state LIKE 'waiting for handler commit' AND name LIKE 'thread/sql/replica_%'
92 --source include/wait_condition.inc
93
94
95 --echo
96 --echo ############################################################
97 --echo # 04. Try to query table t1 (Transaction T2) on server2, it
98 --echo # will be blocked since T1 is prepared but not committed.
99 --let $rpl_connection_name= server2
100 --source include/rpl_connection.inc
101
102 if ($transaction_T2_consistency)
103 {
104 --eval SET @@SESSION.group_replication_consistency= '$transaction_T2_consistency'
105 }
106 --send SELECT * FROM test.t1
107
108 --let $rpl_connection_name= server_2
109 --source include/rpl_connection.inc
110 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.threads WHERE processlist_state LIKE 'waiting for handler commit' AND name LIKE 'thread/sql/replica_%'
111 --source include/wait_condition.inc
112
113 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE user='root' AND state='Executing hook on transaction begin.'
114 --source include/wait_condition.inc
115
116
117 --echo
118 --echo ############################################################
119 --echo # 05. Crash server1. Ensure that server2 is elected as primary.
120 --let $rpl_connection_name= server_1
121 --source include/rpl_connection.inc
122 --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
123 --shutdown_server 0
124 --source include/wait_until_disconnected.inc
125
126 --let $rpl_connection_name= server1
127 --source include/rpl_connection.inc
128 --error CR_SERVER_LOST
129 --reap
130
131 --let $rpl_connection_name= server_2
132 --source include/rpl_connection.inc
133 --let $wait_condition= SELECT MEMBER_ROLE="PRIMARY" FROM performance_schema.replication_group_members where member_id='$member2_uuid'
134 --source include/wait_condition.inc
135
136 # Ensure that transaction from server2 is still blocked, also "select" on a parallel session is blocked.
137 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.threads WHERE processlist_state LIKE 'waiting for handler commit' AND name LIKE 'thread/sql/replica_%'
138 --source include/wait_condition.inc
139
140 --let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE user='root' AND state='Executing hook on transaction begin.'
141 --source include/wait_condition.inc
142
143
144 --echo
145 --echo ############################################################
146 --echo # 06. Unlock tables on server3. Check the transaction from
147 --echo # server1 succeeds now.
148 --let $rpl_connection_name= server3
149 --source include/rpl_connection.inc
150 --let $transactions_applied= query_get_value(SELECT COUNT_TRANSACTIONS_REMOTE_APPLIED FROM performance_schema.replication_group_member_stats WHERE MEMBER_ID IN (SELECT @@server_uuid), COUNT_TRANSACTIONS_REMOTE_APPLIED, 1)
151 SET @@GLOBAL.DEBUG= '+d,group_replication_wait_before_message_send_after_applier_prepare';
152 UNLOCK TABLES;
153
154 --inc $transactions_applied
155 --let $wait_condition=SELECT COUNT_TRANSACTIONS_REMOTE_APPLIED = $transactions_applied FROM performance_schema.replication_group_member_stats WHERE MEMBER_ID IN (SELECT @@server_uuid)
156 --source include/wait_condition_or_abort.inc
157 SET DEBUG_SYNC= "now WAIT_FOR signal.after_before_message_send_after_applier_prepare_waiting";
158 SET DEBUG_SYNC= "now SIGNAL signal.after_before_message_send_after_applier_prepare_continue";
159 SET @@GLOBAL.DEBUG= '-d,group_replication_wait_before_message_send_after_applier_prepare';
160
161 --let $assert_text= 'Table t1 must have 1 entry.'
162 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t1,count, 1] = 1
163 --source include/assert.inc
164
165
166 --echo
167 --echo #############################################################
168 --echo # 07. Check that transaction T2 will read transaction T1 data.
169 --let $rpl_connection_name= server2
170 --source include/rpl_connection.inc
171 --reap
172
173 --let $assert_text= 'Table t1 must have 1 entry.'
174 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t1,count, 1] = 1
175 --source include/assert.inc
176
177
178 --echo
179 --echo ############################################################
180 --echo # 8. Clean up.
181 --let $rpl_connection_name= server1
182 --source include/rpl_connection.inc
183 --let $rpl_server_number= 1
184 --source include/rpl_reconnect.inc
185
186 --let $assert_text= 'Table t1 must not have 1 entry.'
187 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t1,count, 1] = 0
188 --source include/assert.inc
189
190 SET SESSION sql_log_bin= 0;
191 DROP TABLE t1;
192 SET SESSION sql_log_bin= 1;
193
194 --let $rpl_connection_name= server2
195 --source include/rpl_connection.inc
196 DROP TABLE t1;
197
198 --source include/group_replication_end.inc