Debian Codegraph @

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

raw
1 ################################################################################
2 # Validate that BEFORE, AFTER and BEFORE_AND_AFTER consistency levels do
3 # protect against outdated reads when a new primary is still applying the
4 # backlog.
5 #
6 # Test:
7 # 0. The test requires two servers: M1 and M2.
8 # 1. Create a table on the group.
9 # 2. Join server2 to group and lock table t1 to block the
10 # the backlog apply on server2 once it is elected the
11 # primary.
12 # 3. Execute a transaction on the primary server (server1),
13 # server2 will be unable to apply it since table t1 is
14 # locked.
15 # 4. Validate that server2 did certify but did not apply the
16 # transaction.
17 # 5. Switch primary to server2.
18 # 6. Validate that primary election is executing
19 # 7. A transaction with consistency level BEFORE, AFTER and
20 # BEFORE_AND_AFTER on the new primary will be put on hold
21 # until the backlog is applied.
22 # 8. Validate transaction is on hold
23 # 9. UNLOCK tables to allow backlog to be applied on server2
24 # 10. The hold SELECT will now be done and will return the
25 # correct value 1.
26 # 11. Reap with success the primary switch.
27 # 12. Cleanup
28 ################################################################################
29 #
30 # ==== Usage ====
31 #
32 # --let $transaction_T1_consistency= ...
33 #
34 #
35 # Parameters:
36 #
37 # $transaction_T1_consistency
38 # Set the given consistency guarantee to transaction T1.
39 #
40 ################################################################################
41
42 if (!$transaction_T1_consistency)
43 {
44 --die "Missing argument 'transaction_T1_consistency'"
45 }
46
47 --source include/have_group_replication_plugin.inc
48 --let $rpl_skip_group_replication_start= 1
49 --let $rpl_group_replication_single_primary_mode=1
50 --source include/group_replication.inc
51
52 --echo
53 --echo ############################################################
54 --echo # 1. Create a table on the group.
55 --let $rpl_connection_name= server1
56 --source include/rpl_connection.inc
57 --source include/start_and_bootstrap_group_replication.inc
58 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY);
59
60
61 --echo
62 --echo ############################################################
63 --echo # 2. Join server2 to group and lock table t1 to block the
64 --echo # the backlog apply on server2 once it is elected the
65 --echo # primary.
66 --let $rpl_connection_name= server_2
67 --source include/rpl_connection.inc
68 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
69
70 --source include/start_group_replication.inc
71 LOCK TABLES t1 READ;
72
73
74 --echo
75 --echo ############################################################
76 --echo # 3. Execute a transaction on the primary server (server1),
77 --echo # server2 will be unable to apply it since table t1 is
78 --echo # locked.
79 --let $rpl_connection_name= server1
80 --source include/rpl_connection.inc
81 INSERT INTO t1 VALUES (1);
82
83
84 --echo
85 --echo ############################################################
86 --echo # 4. Validate that server2 did certify but did not apply the
87 --echo # transaction.
88 --let $rpl_connection_name= server2
89 --source include/rpl_connection.inc
90 --let $wait_condition= SELECT COUNT(*) = 1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member2_uuid' AND count_transactions_checked = 1 AND count_transactions_remote_in_applier_queue = 1
91 --source include/wait_condition.inc
92
93
94 --echo
95 --echo ############################################################
96 --echo # 5. Switch primary to server2.
97 --let $rpl_connection_name= server1
98 --source include/rpl_connection.inc
99 --replace_result $member2_uuid MEMBER2_UUID
100 --send_eval SELECT group_replication_set_as_primary("$member2_uuid")
101
102
103 --echo
104 --echo ############################################################
105 --echo # 6. Validate that primary election is executing
106 --let $rpl_connection_name= server2
107 --source include/rpl_connection.inc
108 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Switch: executing Primary election%"
109 --source include/wait_condition.inc
110
111 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election: applying buffered transactions%"
112 --source include/wait_condition.inc
113
114
115 --echo
116 --echo ############################################################
117 --echo # 7. A transaction with consistency level BEFORE, AFTER and
118 --echo # BEFORE_AND_AFTER on the new primary will be put on hold
119 --echo # until the backlog is applied.
120 --eval SET @@SESSION.group_replication_consistency= '$transaction_T1_consistency'
121 --send SELECT COUNT(*) FROM t1
122
123
124 --echo
125 --echo ############################################################
126 --echo # 8. Validate transaction is on hold
127 --let $rpl_connection_name= server_2
128 --source include/rpl_connection.inc
129 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.' AND INFO='SELECT COUNT(*) FROM t1'
130 --source include/wait_condition.inc
131
132
133 --echo
134 --echo ############################################################
135 --echo # 9. UNLOCK tables to allow backlog to be applied on server2
136 --let $rpl_connection_name= server_2
137 --source include/rpl_connection.inc
138 UNLOCK TABLES;
139
140
141 --echo
142 --echo ############################################################
143 --echo # 10. The hold SELECT will now be done and will return the
144 --echo # correct value 1.
145 --let $rpl_connection_name= server2
146 --source include/rpl_connection.inc
147 --reap
148 SET @@SESSION.group_replication_consistency= DEFAULT;
149
150
151 --echo
152 --echo ############################################################
153 --echo # 11. Reap with success the primary switch.
154 --let $rpl_connection_name= server1
155 --source include/rpl_connection.inc
156 --replace_result $member2_uuid MEMBER2_UUID
157 --reap
158
159
160 --echo
161 --echo ############################################################
162 --echo # 12. Cleanup
163 --let $rpl_connection_name= server2
164 --source include/rpl_connection.inc
165 --let $wait_condition= SELECT @@GLOBAL.read_only = 0
166 --source include/wait_condition_or_abort.inc
167 DROP TABLE t1;
168
169 --source include/group_replication_end.inc