Skip to content

Commit 3452648

Browse files
author
Jimmy Yang
committed
InnoDB NewDD worklogs(WL#9535 and WL#9536) to support Atomic DDL and
completely remove old InnoDB system tables: 1. WL#9535: InnoDB_New_DD: Remove InnoDB System Table and modify the view of their I_S counterparts This worklog obsoletes all InnoDB System tables, which are no longer used and could only be accessed by upgrade. All metadata is now persisted and read from DD system tables in "mysql tablespace" instead of "old" InnoDB System Tables. All corresponding information_schema.innodb_sys_* tables are replaced by new internal system views. These new views have the name similar to the names of old system tables, just removing the 'SYS_' from the middle of the names. 2. WL#9536: InnoDB_New_DD: Support crash-safe DDL This worklog starts to support crash-safe DDL for InnoDB. DDLs like CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, ALTER TABLE, CREATE TABLESPACE and DROP TABLESPACE are covered by this worklog. DDLs operations including DD system table updates and corresponding file changes(create, delete, rename etc.) are atomic. Physical data files would be synchronized with the transaction for DDL, thus there should be no physical data files for temporary tables or FTS auxiliary tables, etc. left after recovery.
1 parent f8076b3 commit 3452648

File tree

450 files changed

+22988
-27517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

450 files changed

+22988
-27517
lines changed

client/mysqldump.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,8 @@ static inline bool innodb_stats_tables(const char *db,
26852685
return (!my_strcasecmp(charset_info, db, "mysql")) &&
26862686
(!my_strcasecmp(charset_info, table, "innodb_table_stats") ||
26872687
!my_strcasecmp(charset_info, table, "innodb_index_stats") ||
2688-
!my_strcasecmp(charset_info, table, "innodb_dynamic_metadata"));
2688+
!my_strcasecmp(charset_info, table, "innodb_dynamic_metadata") ||
2689+
!my_strcasecmp(charset_info, table, "innodb_ddl_log"));
26892690
}
26902691

26912692
/**

mysql-test/extra/binlog_tests/binlog_ddl.inc

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
# CREATE TRIGGER, DROP TRIGGER, CREATE FUNCTION, ALTER FUNCTION,
77
# DROP FUNCTION, CREATE PROCEDURE, DROP PROCEDURE, CREATE EVENT,
88
# ALTER EVENT, DROP EVENT, CREATE VIEW, ALTER VIEW, DROP VIEW.
9-
#
10-
#
11-
# TODO: (WL7743 etc) add a piece of test of each DDL when it's been
12-
# turned into 2pc-capable.
13-
#
9+
# CREATE/DROP/ALTER TABLE, CREATE/DROP INDEX, TRUNCATE TABLE,
10+
# RENAME TABLE
1411
#
1512
# ==== Implementation ====
1613
# See comments in suite/binlog/t/binlog_crash_safe_ddl.test
@@ -205,3 +202,66 @@ DEALLOCATE PREPARE stmt;
205202
--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM mysql.func where NAME = 'metaphon'
206203
--let $post_binlog_crash_check=SELECT count(*) = 0 FROM mysql.func where NAME = 'metaphon'
207204
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
205+
206+
--let $ddl_query= CREATE TABLE test.t1(a int)
207+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.tables where table_name='t1'
208+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.tables where table_name='t1'
209+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
210+
211+
--let $ddl_query= ALTER TABLE test.t1 ADD COLUMN t1_new_col varchar(100);
212+
--let $pre_binlog_crash_check=SELECT count(*)=1 FROM information_schema.columns where table_name='t1'
213+
--let $post_binlog_crash_check=SELECT count(*)=2 FROM information_schema.columns where table_name='t1'
214+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
215+
216+
--let $ddl_query= ALTER TABLE test.t1 ADD index new_t1_idx(t1_new_col);
217+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.innodb_indexes where name='new_t1_idx'
218+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.innodb_indexes where name='new_t1_idx'
219+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
220+
221+
--let $ddl_query= ALTER TABLE test.t1 RENAME TO test.t2
222+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.tables where table_name='t2'
223+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.tables where table_name='t2'
224+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
225+
226+
--let $ddl_query= ALTER TABLE test.t2 DROP COLUMN a;
227+
--let $pre_binlog_crash_check=SELECT count(*)=2 FROM information_schema.columns where table_name='t2'
228+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.columns where table_name='t2'
229+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
230+
231+
--let $ddl_query= ALTER TABLE test.t2 CHANGE COLUMN t1_new_col t2_new_col char(10);
232+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.columns where table_name='t2' and column_name='t2_new_col'
233+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.columns where table_name='t2' and column_name='t2_new_col'
234+
235+
--let $ddl_query= ALTER TABLE test.t2 MODIFY COLUMN t2_new_col varchar(10);
236+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.columns where table_name='t2' and column_name='t2_new_col'
237+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.columns where table_name='t2' and column_name='t2_new_col'
238+
239+
--let $ddl_query= TRUNCATE TABLE test.t2
240+
--let $pre_binlog_crash_check=SELECT count(*)=1 FROM information_schema.tables where table_name='t2'
241+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.tables where table_name='t2'
242+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
243+
244+
--let $ddl_query= ALTER TABLE test.t2 ADD fulltext index full_t2_idx(t1_new_col);
245+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.innodb_indexes where name='full_t2_idx'
246+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.innodb_indexes where name='full_t2_idx'
247+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
248+
249+
--let $ddl_query= ALTER TABLE test.t2 DROP index full_t2_idx;
250+
--let $pre_binlog_crash_check=SELECT count(*)=1 FROM information_schema.innodb_indexes where name='full_t2_idx'
251+
--let $post_binlog_crash_check=SELECT count(*)=0 FROM information_schema.innodb_indexes where name='full_t2_idx'
252+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
253+
254+
--let $ddl_query= DROP TABLE test.t2
255+
--let $pre_binlog_crash_check=SELECT count(*)=1 FROM information_schema.tables where table_name='t2'
256+
--let $post_binlog_crash_check=SELECT count(*)=0 FROM information_schema.tables where table_name='t2'
257+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
258+
259+
--let $ddl_query= CREATE TABLESPACE ts ADD DATAFILE 'ts_0.ibd'
260+
--let $pre_binlog_crash_check=SELECT count(*)=0 FROM information_schema.INNODB_TABLESPACES WHERE name = 'ts'
261+
--let $post_binlog_crash_check=SELECT count(*)=1 FROM information_schema.INNODB_TABLESPACES WHERE name = 'ts'
262+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
263+
264+
--let $ddl_query= DROP TABLESPACE ts
265+
--let $pre_binlog_crash_check=SELECT count(*)=1 FROM information_schema.INNODB_TABLESPACES WHERE name = 'ts'
266+
--let $post_binlog_crash_check=SELECT count(*)=0 FROM information_schema.INNODB_TABLESPACES WHERE name = 'ts'
267+
--source extra/binlog_tests/binlog_crash_safe_ddl.inc

mysql-test/extra/binlog_tests/binlog_ddl_half_atomic.inc

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# CREATE TABLE, (not CREATE..SELECT)
2121
--let $ddl_query=CREATE TABLE $table (a int auto_increment primary key)
2222

23-
#--let $pre_binlog_crash_check=SELECT count(*) = 0 FROM information_schema.tables WHERE table_name = '$table'
23+
--let $pre_binlog_crash_check=SELECT count(*) = 0 FROM information_schema.tables WHERE table_name = '$table'
2424
--let $post_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table'
2525
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
2626

@@ -42,7 +42,7 @@
4242

4343
# RENAME
4444
--let $ddl_query=RENAME TABLE $table_renamed TO $table /* Name restored */
45-
#--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table_renamed'
45+
--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table_renamed'
4646
--let $post_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table'
4747
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
4848

@@ -54,9 +54,7 @@
5454
#
5555
--let $ddl_query=TRUNCATE TABLE $table
5656
#
57-
# todo_WL7016 or its substitute to activate ($do_pre_binlog:=1)
58-
# the $pre_binlog_crash_check
59-
#--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM $table
57+
--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM $table
6058
--let $post_binlog_crash_check=SELECT count(*) = 0 FROM $table
6159
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
6260

@@ -66,47 +64,43 @@
6664
--let $do_pre_binlog=0
6765
--let $ts=ts_0
6866
--let $ddl_query=CREATE TABLESPACE $ts ADD DATAFILE 'ts_0.ibd'
69-
--let $pre_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
70-
--let $post_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
67+
--let $pre_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
68+
--let $post_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
7169
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
7270

7371
# The following feature is just not implemented expect for NDB, e.g:
7472
#--error ER_CHECK_NOT_IMPLEMENTED
7573
#--let $ddl_query=ALTER TABLESPACE $ts ADD DATAFILE 'ts_1.ibd'
7674
# Otherwise the after crash checks would be:
77-
#--let $pre_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
78-
#--let $post_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
75+
#--let $pre_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
76+
#--let $post_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
7977
# --source extra/binlog_tests/binlog_crash_safe_ddl.inc
8078

8179
--let $ddl_query=DROP TABLESPACE $ts
82-
--let $pre_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
83-
--let $post_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_SYS_TABLESPACES WHERE name = '$ts'
80+
--let $pre_binlog_crash_check= SELECT COUNT(*) = 1 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
81+
--let $post_binlog_crash_check= SELECT COUNT(*) = 0 FROM information_schema.INNODB_TABLESPACES WHERE name = '$ts'
8482
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
8583

8684
#
8785
# CREATE,ALTER,DROP DB
8886
#
8987

90-
#
91-
# TODO: The pre_binlog_crash_check are to activated by WL9536 et al.
92-
#
93-
9488
--let $db=db_0
9589
--let $collate_old=latin1_general_ci
9690
--let $collate_new=utf8_general_ci
9791

9892
--let $ddl_query=CREATE DATABASE $db DEFAULT COLLATE $collate_old
99-
#--let $pre_binlog_crash_check= SELECT count(*) = 0 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
93+
--let $pre_binlog_crash_check= SELECT count(*) = 0 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
10094
--let $post_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
10195
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
10296

10397
--let $ddl_query=ALTER DATABASE $db DEFAULT COLLATE $collate_new
104-
#--let $pre_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db' and default_collation_name = '$collate_old'
98+
--let $pre_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db' and default_collation_name = '$collate_old'
10599
--let $post_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db' and default_collation_name = '$collate_new'
106100
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
107101

108102
--let $ddl_query=DROP DATABASE $db
109-
#--let $pre_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
103+
--let $pre_binlog_crash_check= SELECT count(*) = 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
110104
--let $post_binlog_crash_check= SELECT count(*) = 0 FROM information_schema.SCHEMATA WHERE schema_name = '$db'
111105
--source extra/binlog_tests/binlog_crash_safe_ddl.inc
112106

@@ -116,6 +110,6 @@
116110

117111
# DROP TABLE
118112
--let $ddl_query=DROP TABLE $table
119-
#--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table'
113+
--let $pre_binlog_crash_check=SELECT count(*) = 1 FROM information_schema.tables WHERE table_name = '$table'
120114
--let $post_binlog_crash_check=SELECT count(*) = 0 FROM information_schema.tables WHERE table_name = '$table'
121115
--source extra/binlog_tests/binlog_crash_safe_ddl.inc

mysql-test/extra/binlog_tests/database.test

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ source include/show_binlog_events.inc;
3535
FLUSH STATUS;
3636

3737
--echo
38-
--echo # 'DROP TABLE IF EXISTS <deleted tables>' is binlogged
39-
--echo # when 'DROP DATABASE' fails and at least one table is deleted
40-
--echo # from the database.
38+
--echo # 'DROP TABLE IF EXISTS <deleted table>' are binlogged
39+
--echo # for each table in SEs not supporting atomic DDL which
40+
--echo # were dropped by failed 'DROP DATABASE'.
4141
--echo #
4242
--echo # Unlike test for bug#11765416/58381 this test uses MyISAM
43-
--echo # for t1. So DROP DATABASE will have side-effect even when atomic
44-
--echo # DDL is introduced. DROP TABLE IF EXISTS should be logged
45-
--echo # for MyISAM table in this case.
43+
--echo # for t1. So failed DROP DATABASE will have side-effect even
44+
--echo # though removal of InnoDB tables is rolled back.
45+
--echo # DROP TABLE IF EXISTS is logged for MyISAM table in this case.
4646
RESET MASTER;
4747
CREATE DATABASE testing_1;
4848
USE testing_1;
@@ -77,17 +77,18 @@ DROP TABLE IF EXISTS t3;
7777
--enable_warnings
7878

7979
CREATE DATABASE db1;
80-
CREATE TABLE db1.t1 (a INT);
80+
CREATE TABLE db1.t1 (a INT) engine=innodb;
8181
CREATE TABLE db1.t2 (b INT, KEY(b)) engine=innodb;
8282
CREATE TABLE t3 (a INT, KEY (a), FOREIGN KEY(a) REFERENCES db1.t2(b))
8383
engine=innodb;
8484
RESET MASTER;
8585

8686
--error ER_ROW_IS_REFERENCED
8787
DROP DATABASE db1; # Fails because of the fk
88-
SHOW TABLES FROM db1; # t1 was dropped, t2 remains
88+
# Both t1 and t2 remain as the whole statement is rolled back.
89+
SHOW TABLES FROM db1;
8990
--let $mask_binlog_commit_events= 1
90-
--source include/show_binlog_events.inc # Check that the binlog drops t1
91+
--source include/show_binlog_events.inc # Check that the binlog is empty.
9192
--let $mask_binlog_commit_events= 0
9293

9394
# Cleanup

mysql-test/extra/rpl_tests/rpl_split_statements.test

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,29 @@ CREATE TABLE base_5_a (fk INT, FOREIGN KEY (fk) REFERENCES base_4_a(pk)) ENGINE
353353
--error ER_ROW_IS_REFERENCED
354354
DROP TABLES base_1_n, base_2_n, base_3_a, base_4_a;
355355

356-
--echo # In AUTOMATIC mode the above statement should be split into three:
357-
--echo # two statements for each of MyISAM tables and single statement
358-
--echo # dropping base_3_a. Note that this will change once InnoDB really
359-
--echo # supports atomic DDL.
360-
--let $gtid_step_count= 3
356+
--echo # In AUTOMATIC mode the above statement should be split into
357+
--echo # two statements for each of MyISAM tables.
358+
--echo # There should be no statement for dropping base_3_a as its
359+
--echo # removal is rolled back.
360+
--let $gtid_step_count= 2.
361361
--source include/gtid_step_assert.inc
362362

363-
--echo # base_4_a should still be there on master
363+
--echo # base_3_a and base_4_a should still be there on master
364+
SHOW CREATE TABLE base_3_a;
364365
SHOW CREATE TABLE base_4_a;
365366

366367
--source include/rpl_sync.inc
367368

368369
--connection slave
369370

370-
--echo # base_4_a should still be there on slave
371+
--echo # base_3_a and base_4_a should still be there on master
372+
SHOW CREATE TABLE base_3_a;
371373
SHOW CREATE TABLE base_4_a;
372374

373375
--connection master
374376

375377
CREATE TABLE base_1_n (a INT) ENGINE = MyISAM;
376378
CREATE TABLE base_2_n (a INT) ENGINE = MyISAM;
377-
CREATE TABLE base_3_a (a INT) ENGINE = InnoDB;
378379

379380
--source include/rpl_sync.inc
380381

@@ -398,26 +399,28 @@ if ($gtid_mode_on)
398399
if (!$gtid_mode_on)
399400
{
400401
--echo # Without GTID assigned the above statement should be split into
401-
--echo # three as in AUTOMATIC mode.
402-
--let $gtid_step_count= 3
402+
--echo # two as in AUTOMATIC mode.
403+
--let $gtid_step_count= 2
403404
--source include/gtid_step_assert.inc
404405
}
405406

406-
--echo # base_4_a should still be there on master
407+
--echo # base_3_a and base_4_a should still be there on master
408+
SHOW CREATE TABLE base_3_a;
407409
SHOW CREATE TABLE base_4_a;
408410

409411
--source include/rpl_sync.inc
410412

411413
--connection slave
412414

413-
--echo # base_4_a should still be there on slave
415+
--echo # base_3_a and base_4_a should still be there on master
416+
SHOW CREATE TABLE base_3_a;
414417
SHOW CREATE TABLE base_4_a;
415418

416419
--connection master
417420

418421
--echo ---- Clean up ----
419422

420-
DROP TABLE base_5_a, base_4_a;
423+
DROP TABLE base_5_a, base_4_a, base_3_a;
421424

422425
--source include/rpl_sync.inc
423426

0 commit comments

Comments
 (0)