Debian Codegraph @

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

raw
1 ################################################################################
2 # In this test case, we verify if some DDL statements implicitly commit a
3 # transaction and are written directly to the binary log without going
4 # through either the Statement- or Transactional-Cache when used with Group
5 # REPLICATON.
6 #
7 # As any statement that goes through a cache is written to the binary log
8 # wrapped in a BEGIN...COMMIT, we proceed as follows:
9 #
10 # Test:
11 # 0. The test requires two servers: M1 and M2.
12 # 1. With both the members ONLINE. On M1, create tables and insert some values.
13 # 2. Check implicit commit:
14 # - Set auto_commit=0.
15 # - Create a transaction and insert some values into a transactional table.
16 # - Execute a DDL statement that is supposed to implicitly commit the previous
17 # transaction. Following DDLs are tested:-
18 # DROP DATABASE, CREATE DATABASE, DROP TABLE, RENAME TABLE, CREATE TABLE,
19 # DROP VIEW, ALTER VIEW, CREATE VIEW, DROP PROCEDURE, ALTER PROCEDURE,
20 # CREATE PROCEDURE, DROP FUNCTION, ALTER FUNCTION, CREATE FUNCTION,
21 # DROP EVENT, ALTER EVENT, CREATE EVENT, DROP USER, RENAME USER, REVOKE,
22 # SET PASSWORD, GRANT, CREATE USER, UNLOCK TABLES, LOCK TABLES,
23 # REPAIR TABLE, OPTIMIZE TABLE, CHECK TABLE, ANALYZE TABLE, LOAD INDEX
24 # - Check in the binary log for a COMMIT mark which is supposed to be written
25 # before the DDL statement.
26 # - Check in the binary log if the DML is not wrapped by a BEGIN..COMMIT.
27 # - Set auto_commit=1.
28 # 3. Checking the consistency on the two members.
29 # 4. Clean up.
30 ################################################################################
31 --source include/set_privilege_checks_user_as_system_user.inc
32 --let $rpl_privilege_checks_user_grant_option = 1
33 --source include/have_group_replication_plugin.inc
34 --source include/group_replication.inc
35
36 --echo #########################################################################
37 --echo # CONFIGURATION
38 --echo #########################################################################
39 --connection server1
40
41 --eval CREATE TABLE tt_1 (ddl_case INT, PRIMARY KEY(ddl_case)) ENGINE = innodb
42 --eval CREATE TABLE tt_2 (ddl_case INT, PRIMARY KEY(ddl_case)) ENGINE = innodb
43 --eval CREATE TABLE nt_1 (ddl_case INT, PRIMARY KEY(ddl_case)) ENGINE = innodb
44
45 INSERT INTO tt_1(ddl_case) VALUES(0);
46 INSERT INTO tt_2(ddl_case) VALUES(0);
47
48 --echo #########################################################################
49 --echo # CHECK IMPLICT COMMIT
50 --echo #########################################################################
51
52 # Creating a set of statements which goes through the implicit commit stage
53 # and checking the status of the group at the very end.
54 SET AUTOCOMMIT= 0;
55 --let $ddl_cases= 31
56 while ($ddl_cases >= 1)
57 {
58 --echo -b-b-b-b-b-b-b-b-b-b-b- >> << -b-b-b-b-b-b-b-b-b-b-b-
59 --let $in_temporary= no
60 --let $ok= yes
61 #
62 # In RBR mode, the commit event is usually the fourth event in the binary log:
63 #
64 # 1: BEGIN
65 # 2: TABLE MAP EVENT
66 # 3: ROW EVENT
67 # 4: COMMIT
68 # 5: DDL EVENT which triggered the previous commmit.
69 #
70
71 --let $commit_event_row_number= 4
72 --let $first_binlog_position= query_get_value("SHOW MASTER STATUS", Position, 1)
73 --enable_query_log
74 --eval INSERT INTO tt_1(ddl_case) VALUES ($ddl_cases)
75
76 if ($ddl_cases == 31)
77 {
78 --let $cmd= LOAD INDEX INTO CACHE nt_1 IGNORE LEAVES
79 }
80 if ($ddl_cases == 30)
81 {
82 --let $cmd= LOAD INDEX INTO CACHE tt_1, tt_2 IGNORE LEAVES
83 }
84 if ($ddl_cases == 29)
85 {
86 --let $cmd= ANALYZE TABLE nt_1
87 }
88 if ($ddl_cases == 28)
89 {
90 --let $cmd= CHECK TABLE nt_1
91 }
92 if ($ddl_cases == 27)
93 {
94 --let $cmd= OPTIMIZE TABLE nt_1
95 }
96 if ($ddl_cases == 26)
97 {
98 --let $cmd= REPAIR TABLE nt_1
99 }
100 if ($ddl_cases == 25)
101 {
102 --let $cmd= LOCK TABLES tt_1 WRITE
103 }
104 if ($ddl_cases == 24)
105 {
106 --let $cmd= UNLOCK TABLES
107 }
108 if ($ddl_cases == 23)
109 {
110 --let $cmd= CREATE USER 'user'@'localhost'
111 }
112 if ($ddl_cases == 22)
113 {
114 --let $cmd= GRANT ALL ON *.* TO 'user'@'localhost'
115 }
116 if ($ddl_cases == 21)
117 {
118 --let $cmd= SET PASSWORD FOR 'user'@'localhost' = 'newpass'
119 }
120 if ($ddl_cases == 20)
121 {
122 --let $cmd= REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'localhost'
123 }
124 if ($ddl_cases == 19)
125 {
126 --let $cmd= RENAME USER 'user'@'localhost' TO 'user_new'@'localhost'
127 }
128 if ($ddl_cases == 18)
129 {
130 --let $cmd= DROP USER 'user_new'@'localhost'
131 }
132 if ($ddl_cases == 17)
133 {
134 --let $cmd= CREATE EVENT evt ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO SELECT * FROM tt_1
135 }
136 if ($ddl_cases == 16)
137 {
138 --let $cmd= ALTER EVENT evt COMMENT 'evt'
139 }
140 if ($ddl_cases == 15)
141 {
142 --let $cmd= DROP EVENT evt
143 }
144 if ($ddl_cases == 14)
145 {
146 --let $cmd= CREATE FUNCTION fc () RETURNS VARCHAR(64) CHARSET utf8mb4 RETURN "fc"
147 }
148 if ($ddl_cases == 13)
149 {
150 --let $cmd= ALTER FUNCTION fc COMMENT 'fc'
151 }
152 if ($ddl_cases == 12)
153 {
154 --let $cmd= DROP FUNCTION fc
155 }
156 if ($ddl_cases == 11)
157 {
158 --let $cmd= CREATE PROCEDURE pc () UPDATE tt_2 SET ddl_case = ddl_case WHERE ddl_case= NEW.ddl_case
159 }
160 if ($ddl_cases == 10)
161 {
162 --let $cmd= ALTER PROCEDURE pc COMMENT 'pc'
163 }
164 if ($ddl_cases == 8)
165 {
166 --let $cmd= DROP PROCEDURE pc
167 }
168 if ($ddl_cases == 9)
169 {
170 --let $cmd= CREATE VIEW v AS SELECT * FROM tt_1
171 }
172 if ($ddl_cases == 7)
173 {
174 --let $cmd= ALTER VIEW v AS SELECT * FROM tt_1
175 }
176 if ($ddl_cases == 6)
177 {
178 --let $cmd= DROP VIEW v
179 }
180 if ($ddl_cases == 5)
181 {
182 --let $cmd= CREATE TABLE tt_xx (a int)
183 }
184 if ($ddl_cases == 4)
185 {
186 --let $cmd= RENAME TABLE tt_xx TO new_tt_xx
187 }
188 if ($ddl_cases == 3)
189 {
190 --let $cmd= DROP TABLE IF EXISTS tt_xx, new_tt_xx
191 }
192 if ($ddl_cases == 2)
193 {
194 --let $cmd= CREATE DATABASE db
195 }
196 if ($ddl_cases == 1)
197 {
198 --let $cmd= DROP DATABASE IF EXISTS db
199 }
200 --eval $cmd
201 --disable_query_log
202
203 --let $event_commit= query_get_value("SHOW BINLOG EVENTS FROM $first_binlog_position", Info, $commit_event_row_number)
204
205 --echo -e-e-e-e-e-e-e-e-e-e-e- >> << -e-e-e-e-e-e-e-e-e-e-e-
206 --let $binlog_start= $first_binlog_position;
207 --echo -b-b-b-b-b-b-b-b-b-b-b- >> << -b-b-b-b-b-b-b-b-b-b-b-
208 --let $mask_user_password_events=1
209 --let $mask_grant_as_events=1
210 --source include/show_binlog_events.inc
211 --let $mask_user_password_events=0
212 --let $mask_grant_as_events=0
213 --echo -e-e-e-e-e-e-e-e-e-e-e- >> << -e-e-e-e-e-e-e-e-e-e-e-
214 --echo
215 --dec $ddl_cases
216 }
217 SET AUTOCOMMIT= 1;
218
219 --echo ###################################################################################
220 --echo # CHECK CONSISTENCY
221 --echo ###################################################################################
222 --source include/rpl_sync.inc
223
224 # Checking the consistency on the two members.
225
226 --let $diff_tables= server1:tt_1,server2:tt_1
227 --source include/diff_tables.inc
228
229 --let $diff_tables= server1:tt_2,server2:tt_2
230 --source include/diff_tables.inc
231
232 --let $diff_tables= server1:nt_1,server2:nt_1
233 --source include/diff_tables.inc
234
235 --echo ###################################################################################
236 --echo # CLEAN
237 --echo ###################################################################################
238 --connection server1
239
240 DROP TABLE tt_1;
241 DROP TABLE tt_2;
242 DROP TABLE nt_1;
243
244 --source include/rpl_sync.inc
245 --source include/group_replication_end.inc