Debian Codegraph @

mysql-test/suite/group_replication/include/gr_primary_auto_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. Make server1 leave the group, server2 will be the new
18 # primary.
19 # 6. Validate that server2 is the primary.
20 # 7. A transaction with consistency level BEFORE, AFTER and
21 # BEFORE_AND_AFTER on the new primary will be put on hold
22 # until the backlog is applied.
23 # 8. Validate transaction is on hold
24 # 9. UNLOCK tables to allow backlog to be applied on server2
25 # 10. The hold SELECT will now be done and will return the
26 # correct value 1.
27 # 11. 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. Make server1 leave the group, server2 will be the new
97 --echo # primary.
98 --let $rpl_connection_name= server1
99 --source include/rpl_connection.inc
100 --source include/stop_group_replication.inc
101
102
103 --echo
104 --echo ############################################################
105 --echo # 6. Validate that server2 is the primary.
106 --let $rpl_connection_name= server2
107 --source include/rpl_connection.inc
108 --let $group_replication_expected_uuid= $member2_uuid
109 --source include/gr_wait_primary_member_uuid.inc
110
111
112 --echo
113 --echo ############################################################
114 --echo # 7. A transaction with consistency level BEFORE, AFTER and
115 --echo # BEFORE_AND_AFTER on the new primary will be put on hold
116 --echo # until the backlog is applied.
117 --eval SET @@SESSION.group_replication_consistency= '$transaction_T1_consistency'
118 --send SELECT COUNT(*) FROM t1
119
120
121 --echo
122 --echo ############################################################
123 --echo # 8. Validate transaction is on hold
124 --let $rpl_connection_name= server_2
125 --source include/rpl_connection.inc
126 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.' AND INFO='SELECT COUNT(*) FROM t1'
127 --source include/wait_condition.inc
128
129
130 --echo
131 --echo ############################################################
132 --echo # 9. UNLOCK tables to allow backlog to be applied on server2
133 --let $rpl_connection_name= server_2
134 --source include/rpl_connection.inc
135 UNLOCK TABLES;
136
137
138 --echo
139 --echo ############################################################
140 --echo # 10. The hold SELECT will now be done and will return the
141 --echo # correct value 1.
142 --let $rpl_connection_name= server2
143 --source include/rpl_connection.inc
144 --reap
145 SET @@SESSION.group_replication_consistency= DEFAULT;
146
147
148 --echo
149 --echo ############################################################
150 --echo # 11. Cleanup
151 --let $rpl_connection_name= server1
152 --source include/rpl_connection.inc
153 SET SESSION sql_log_bin= 0;
154 DROP TABLE t1;
155 SET SESSION sql_log_bin= 1;
156
157 --let $rpl_connection_name= server2
158 --source include/rpl_connection.inc
159 --let $wait_condition= SELECT @@GLOBAL.read_only = 0
160 --source include/wait_condition_or_abort.inc
161 DROP TABLE t1;
162
163 --source include/group_replication_end.inc