Debian Codegraph @

mysql-test/suite/ndb_binlog/t/ndb_binlog_ddl_multi.test

raw
1 -- source include/have_multi_ndb.inc
2 -- source include/have_binlog_format_mixed_or_row.inc
3
4 --disable_warnings
5 --connection server1
6 reset master;
7 --connection server2
8 reset master;
9 --enable_warnings
10
11 #
12 # Basic test to see if DDL distribution works across
13 # binlogs in different MySQL Server(s)
14 #
15
16 # create database
17 --connection server1
18 create database mysqltest;
19
20 # create table
21 --connection server1
22 use mysqltest;
23 create table t1 (a int primary key) engine=ndb;
24
25 --connection server2
26 create table t2 (a int primary key) engine=ndb;
27 --source include/show_binlog_events.inc
28
29 --connection server1
30 --source include/show_binlog_events.inc
31
32 # alter table
33 --connection server1
34 reset master;
35 --connection server2
36 reset master;
37
38 --connection server2
39 alter table t2 add column (b int);
40
41 --connection server1
42 --source include/show_binlog_events.inc
43
44 # alter database
45 --connection server1
46 reset master;
47 --connection server2
48 reset master;
49
50 --connection server2
51 ALTER DATABASE mysqltest CHARACTER SET latin1;
52
53
54 --connection server1
55 --source include/show_binlog_events.inc
56
57 #--connection server2
58 drop table mysqltest.t1;
59
60 # drop database and drop should come after data events
61 --connection server1
62 reset master;
63 --connection server2
64 reset master;
65
66 --connection server1
67 use test;
68 insert into t2 values (1,2);
69 drop database mysqltest;
70 create table t1 (a int primary key) engine=ndb;
71
72 --connection server2
73 --source include/show_binlog_events.inc
74
75 --connection server2
76 drop table t2;
77
78 # logfile groups and table spaces
79 --connection server1
80 reset master;
81 --connection server2
82 reset master;
83
84 --connection server1
85 CREATE LOGFILE GROUP lg1
86 ADD UNDOFILE 'undofile.dat'
87 INITIAL_SIZE 16M
88 UNDO_BUFFER_SIZE = 1M
89 ENGINE=NDB;
90
91 ALTER LOGFILE GROUP lg1
92 ADD UNDOFILE 'undofile02.dat'
93 INITIAL_SIZE = 4M
94 ENGINE=NDB;
95
96 CREATE TABLESPACE ts1
97 ADD DATAFILE 'datafile.dat'
98 USE LOGFILE GROUP lg1
99 INITIAL_SIZE 12M
100 ENGINE NDB;
101
102 ALTER TABLESPACE ts1
103 ADD DATAFILE 'datafile02.dat'
104 INITIAL_SIZE = 4M;
105
106 ALTER TABLESPACE ts1
107 DROP DATAFILE 'datafile.dat';
108
109 ALTER TABLESPACE ts1
110 DROP DATAFILE 'datafile02.dat';
111
112 DROP TABLESPACE ts1;
113
114 DROP LOGFILE GROUP lg1
115 ENGINE =NDB;
116
117 --connection server2
118 --source include/show_binlog_events.inc
119
120 drop table t1;
121
122 #
123 # Bug #17827 cluster: rename of several tables in one statement,
124 # gets multiply logged
125 #
126 --connection server1
127 reset master;
128 show tables;
129 --connection server2
130 reset master;
131 show tables;
132
133 --connection server1
134 create table t1 (a int key) engine=ndb;
135 create table t2 (a int key) engine=ndb;
136 create table t3 (a int key) engine=ndb;
137 rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
138 --connection server2
139 --source include/show_binlog_events.inc
140
141 drop table t1;
142 drop table t2;
143 drop table t3;
144
145 #
146 # Bug #17838 binlog not setup on seconday master after rename
147 #
148 #
149 --connection server1
150 reset master;
151 show tables;
152 --connection server2
153 reset master;
154 show tables;
155
156 --connection server1
157 create table t1 (a int key) engine=ndb;
158 insert into t1 values(1);
159 rename table t1 to t2;
160 insert into t2 values(2);
161
162 # now we should see data in table t1 _and_ t2
163 # prior to bug fix, data was missing for t2
164 --connection server2
165 drop table t2;
166 --source include/show_binlog_events.inc
167
168 ##########################
169 # Bug#22135584: BINLOG CONTAINS SCHEMA EVENTS IN INCORRECT ORDER
170 #
171 # DDL operations are sometimes inserted in the incorrect relative order
172 # vs. the DML operations.
173 ##########################
174 --connection server1
175 reset master;
176 --connection server2
177 reset master;
178
179 ##################################################
180 # Check whether we have a debug compiled binary:
181 # @@global.debug can't be referred without this.
182 # However, instead of skipping entire test without debug,
183 # we run it without setting the specific debug flags.
184 ###################################################
185 --connection server2
186 --let $have_debug= `select (version() like '%debug%')`
187
188 disable_query_log;
189 if ($have_debug)
190 {
191 # Force server2 to yield the CPU inbetween polling the event buffer
192 set @save_debug= @@global.debug;
193 set global debug='+d,ndb_binlog_injector_yield_before_schema_pollEvent';
194 }
195 enable_query_log;
196
197 --connection server1
198 use test;
199
200 --echo The relative order between DML and DDL statements below are
201 --echo expected to follow the same order in binlog as shown below.
202 let $i=5;
203 while ($i)
204 {
205 create database mysqltest;
206 create table t1 (a int primary key) engine=ndb;
207 insert into t1 values (1);
208 drop database mysqltest;
209 drop table t1;
210 dec $i;
211 }
212 # Dummy synchronization to flush prior events to binlog
213 create table dummy (dummyk int primary key) engine = ndb;
214
215 --connection server2
216 disable_query_log;
217 if ($have_debug)
218 {
219 set global debug= @save_debug;
220 }
221 enable_query_log;
222
223 --connection server2
224
225 # Ensure that synchronization dummy reached log
226 drop table dummy;
227 --source include/show_binlog_events.inc
228
229 ##########################
230 # Bug#22842538:
231 #
232 # New mysqld's joining the schema distribution may cause
233 # ongoing DDL operations to never complete -> timeout
234 #
235 ##########################
236 connection server1;
237
238
239 # Procedure p1 communicate through 'progress' table
240 CREATE TABLE progress(
241 cnt int, stop_flag int
242 ) ENGINE NDB;
243
244
245 # Create a procedure for producing a background load of
246 # DDL operations. Any operations, like a CREATE TABLE, would
247 # do. However, we have experienced that CREATE LOGFILE seems
248 # to be most likely to trigger this bug (Due to timing?)
249 #
250 disable_query_log;
251 delimiter %;
252 create procedure p1()
253 begin
254 declare done int default 0;
255 repeat
256 UPDATE progress set cnt=cnt+1;
257 COMMIT;
258 CREATE LOGFILE GROUP lg_1
259 ADD UNDOFILE 'undo_1.dat'
260 INITIAL_SIZE 4M
261 UNDO_BUFFER_SIZE 2M
262 ENGINE NDB;
263 UPDATE progress set cnt=cnt+1;
264 COMMIT;
265 DROP LOGFILE GROUP lg_1 ENGINE NDB;
266 SELECT stop_flag INTO done FROM progress;
267 until done end repeat;
268 end%
269 delimiter ;%
270 enable_query_log;
271
272
273 insert into progress value(0,0);
274
275 --echo Start background load distributing schema changes.
276 send call p1();
277
278 connection server2;
279 let $1 = 4;
280 while ($1)
281 {
282 # Ignore the warning generated by ndbcluster's binlog thread
283 # when cluster is restarted
284 --disable_query_log ONCE
285 call mtr.add_suppression("mysqld startup An incident event has been written");
286
287 --echo Restart mysqld 'server2'
288 let $mysqld_name=mysqld.2.1;
289 --source include/restart_mysqld.inc
290
291 --echo Checking for schema ops. still making progress
292 let $initial_cnt = `select cnt from progress`;
293 let $progress_cnt = $initial_cnt;
294
295 let $max_wait = 10;
296 while ($progress_cnt == $initial_cnt)
297 {
298 sleep 1;
299 dec $max_wait;
300 if ($max_wait == 0)
301 {
302 die Schema distribution timed out without progress;
303 }
304 let $progress_cnt = `select cnt from progress`;
305 }
306 dec $1;
307 }
308
309 --echo Stopping background load distributing schema changes.
310 update progress set stop_flag=1;
311
312 connection server1;
313
314 --echo Wait for background schema distribution load to complete.
315 reap;
316
317 --echo Cleanup
318 drop procedure p1;
319 drop table progress;
320
321 --echo #
322 --echo # WL#12936 : Implement DDL transaction context logger in ndbcluster
323 --echo #
324
325 # When a DDL transaction fails, it will be rolled back and distributed to
326 # other connected mysql servers. But even before the failure, the actual
327 # changes would have been distributed to other participants and the query
328 # would be logged in their binlogs. This can't be avoided. This testcase
329 # is here to document this behaviour.
330
331 --connection server1
332 reset master;
333 show tables;
334 --connection server2
335 reset master;
336 show tables;
337
338 --connection server1
339 --echo # Setup
340 CREATE TABLE t1 (
341 a int,
342 b int
343 ) ENGINE NDB;
344
345 INSERT INTO t1 VALUES (1, NULL);
346
347 # Use CREATE TABLE .. AS SELECT .. FROM t1 and create a similar table t1
348 # with column a NOT NULL. This will fail when the Server tries to copy rows
349 # from t1 to t2 but only after the CREATE has been distributed to other
350 # other tables. The CREATE should fail and drop the table in NDB and across
351 # drop the table in NDB and across all connected mysqlds during
352 # rollback. But the participant binlog will have the CREATE query.
353 --error ER_BAD_NULL_ERROR
354 CREATE TABLE t2 (
355 a int,
356 b int not null
357 ) ENGINE NDB
358 AS SELECT * FROM t1;
359
360 --echo # Verify that table does not exist
361 --error ER_NO_SUCH_TABLE
362 SELECT * FROM t2;
363 --echo # Verify that the CREATE TABLE t2 query is not present in binlog
364 --source include/show_binlog_events.inc
365
366 --connection server2
367 --echo # Table should not exist in participant also
368 --error ER_NO_SUCH_TABLE
369 SELECT * FROM t2;
370 --echo # Verify that the CREATE TABLE t2 query is present in binlog
371 --source include/show_binlog_events.inc
372
373 --echo #Cleanup
374 DROP TABLE t1;