Debian Codegraph @

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

raw
1 ###############################################################################
2 #
3 # A group of statements that belong to the same transaction shall run the
4 # hook only on the first statement, preventing multiple calls to plugin on same
5 # transaction
6 #
7 # Test:
8 # 0. This test requires two servers
9 # 1. Bootstrap group on server 1 and create table t1
10 # 2. Join server2 to group and lock tables t1
11 # 3. Execute transaction on primary server
12 # 4. Server2 will certify transaction but won't apply due lock tables
13 # 5. Start a transaction on secondary that will be elected as primary
14 # 6. Execute group_replication_set_as_primary to appoint server2 as
15 # primary
16 # 7. Validate that primary election is executing
17 # 8. Transaction started previous to primary election, it will not block
18 # due hook only run once by transaction.
19 # 9. A write will fail due SUPER_READ_ONLY=1 until primary election
20 # finishes
21 # 10. A start of a transaction to a new primary will be put on hold
22 # until all backlog's are applied
23 # 11. Validate statement is on hold
24 # 12. UNLOCK tables to allow backlog to be applied
25 # 12. Reap with success execution of set as primary server2
26 # 13. Reap with success start of transaction and execute some statements
27 # 14. Cleanup
28 #
29 ###############################################################################
30
31 --source include/have_group_replication_plugin.inc
32
33 --let $rpl_server_count= 2
34 --let $rpl_skip_group_replication_start= 1
35 --let $rpl_group_replication_single_primary_mode=1
36 --source include/group_replication.inc
37
38 --echo
39 --echo # 1. Bootstrap group on server 1 and create table t1
40
41 --source include/start_and_bootstrap_group_replication.inc
42
43 CREATE TABLE test.t1 (a INT PRIMARY KEY);
44
45 --echo
46 --echo # 2. Join server2 to group and lock tables t1
47
48 --let $rpl_connection_name= server_2
49 --source include/rpl_connection.inc
50
51 --source include/start_group_replication.inc
52
53 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
54
55 LOCK TABLES t1 READ;
56
57 --echo
58 --echo # 3. Execute transaction on primary server
59
60 --let $rpl_connection_name= server1
61 --source include/rpl_connection.inc
62
63 INSERT INTO t1 VALUES (1);
64
65 --echo
66 --echo # 4. Server2 will certify transaction but won't apply due lock tables
67
68 --let $rpl_connection_name= server2
69 --source include/rpl_connection.inc
70
71 --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
72 --source include/wait_condition.inc
73
74 --echo
75 --echo # 5. Start a transaction on secondary that will be elected as primary
76
77 SET @@SESSION.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
78
79 BEGIN;
80
81 --echo
82 --echo # 6. Execute group_replication_set_as_primary to appoint server2 as
83 --echo # primary
84
85 --let $rpl_connection_name= server1
86 --source include/rpl_connection.inc
87
88 --replace_result $member2_uuid MEMBER2_UUID
89 --send_eval SELECT group_replication_set_as_primary("$member2_uuid")
90
91 --echo
92 --echo # 7. Validate that primary election is executing
93
94 --let $rpl_connection_name= server2
95 --source include/rpl_connection.inc
96
97 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "stage/group_rpl/Primary Election: applying buffered transactions"
98 --source include/wait_condition.inc
99
100 --echo
101 --echo # 8. Transaction started previous to primary election, it will not block
102 --echo # due hook only run once by transaction.
103
104 SELECT * FROM t1;
105
106 --echo
107 --echo # 9. A write will fail due SUPER_READ_ONLY=1 until primary election
108 --echo # finishes
109
110 --error ER_OPTION_PREVENTS_STATEMENT
111 INSERT INTO t1 VALUES (2);
112
113 COMMIT;
114
115 --echo
116 --echo # 10. A start of a transaction to a new primary will be put on hold
117 --echo # until all backlog's are applied
118
119 SET @@SESSION.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
120
121 --send_eval BEGIN;
122
123 --echo
124 --echo # 11. Validate statement is on hold
125
126 --let $rpl_connection_name= server_2
127 --source include/rpl_connection.inc
128
129 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.' AND INFO='BEGIN'
130 --source include/wait_condition.inc
131
132 --echo
133 --echo # 12. UNLOCK tables to allow backlog to be applied
134
135 UNLOCK TABLES;
136
137 --echo
138 --echo # 12. Reap with success execution of set as primary server2
139
140 --let $rpl_connection_name= server1
141 --source include/rpl_connection.inc
142
143 --replace_result $member2_uuid MEMBER2_UUID
144 --reap
145
146 --echo
147 --echo # 13. Reap with success start of transaction and execute some statements
148
149 --let $rpl_connection_name= server2
150 --source include/rpl_connection.inc
151
152 --reap
153
154 SELECT * FROM t1;
155
156 COMMIT;
157
158 SET @@SESSION.group_replication_consistency= DEFAULT;
159
160 --echo
161 --echo # 14. Cleanup
162
163 DROP TABLE t1;
164
165 --source include/group_replication_end.inc