1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-14585 Automatically remove #sql- tables in InnoDB dictionary during recovery

This is a backport of the following commits:
commit b4165985c9
commit 69e88de0fe
commit 40f4525f43
commit 656f66def2

Now that MDEV-14717 made RENAME TABLE crash-safe within InnoDB,
it should be safe to drop the #sql- tables within InnoDB during
crash recovery. These tables can be one of two things:

(1) #sql-ib related to deferred DROP TABLE (follow-up to MDEV-13407)
or to table-rebuilding ALTER TABLE...ALGORITHM=INPLACE
(since MDEV-14378, only related to the intermediate copy of a table),

(2) #sql- related to the intermediate copy of a table during
ALTER TABLE...ALGORITHM=COPY

We will not drop tables whose name starts with #sql2, because
the server can be killed during an ALGORITHM=COPY operation at
a point where the original table was renamed to #sql2 but the
finished intermediate copy was not yet renamed from #sql-
to the original table name.

If an old version of MariaDB Server before 10.2.13 (MDEV-11415)
was killed while ALTER TABLE...ALGORITHM=COPY was in progress,
after recovery there could be undo log records for some records that were
inserted into an intermediate copy of the table. Due to these undo log
records, InnoDB would resurrect locks at recovery, and the intermediate
table would be locked while we are trying to drop it. This would cause
a call to row_rename_table_for_mysql(), either from
row_mysql_drop_garbage_tables() or from the rollback of a RENAME
operation that was part of the ALTER TABLE.

row_rename_table_for_mysql(): Do not attempt to parse FOREIGN KEY
constraints when renaming from #sql-something to #sql-something-else,
because it does not make any sense.

row_drop_table_for_mysql(): When deferring DROP TABLE due to locks,
do not rename the table if its name already starts with the #sql-
prefix, which is what row_mysql_drop_garbage_tables() uses.
Previously, the too strict prefix #sql-ib was used, and some
tables were renamed unnecessarily.
This commit is contained in:
Marko Mäkelä
2018-09-06 11:51:50 +03:00
parent 8dcacd3b01
commit 73ed19e44f
12 changed files with 70 additions and 68 deletions

View File

@ -72,9 +72,6 @@ let $orig_table_id = `SELECT table_id
--error 2013
ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
--echo # Restart mysqld after the crash and reconnect.
--source include/start_mysqld.inc
let TABLENAME_INC= $MYSQLTEST_VARDIR/tmp/tablename.inc;
perl;
die unless open OUT, ">$ENV{TABLENAME_INC}";
@ -86,12 +83,15 @@ EOF
source $TABLENAME_INC;
remove_file $TABLENAME_INC;
move_file $datadir/test/$tablename.frm $datadir/test/t1.frm;
--echo # Restart mysqld after the crash and reconnect.
--source include/start_mysqld.inc
--replace_result $orig_table_id ID
eval SELECT * FROM information_schema.innodb_sys_tables
WHERE table_id = $orig_table_id;
move_file $datadir/test/$tablename.frm $datadir/test/t1.frm;
--echo # Files in datadir after manual recovery.
--list_files $MYSQLD_DATADIR/test
@ -125,27 +125,13 @@ let $orig_table_id = `SELECT table_id
--error 2013
ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
remove_files_wildcard $datadir/test #sql-*.frm;
--echo # Startup the server after the crash
--source include/start_mysqld.inc
SELECT * FROM information_schema.innodb_sys_tables
WHERE name LIKE 'test/#sql-ib%';
let TABLENAME_INC= $MYSQLTEST_VARDIR/tmp/tablename.inc;
perl;
die unless open OUT, ">$ENV{TABLENAME_INC}";
chdir "$ENV{'datadir'}/test";
my @frm_file = map { substr($_, 0, -4) } glob "#sql-*.frm";
print OUT 'let $tablename=', $frm_file[0], ';';
close OUT or die;
EOF
source $TABLENAME_INC;
remove_file $TABLENAME_INC;
--echo # Drop the orphaned rebuilt table.
--disable_query_log
eval DROP TABLE `#mysql50#$tablename`;
--enable_query_log
WHERE name LIKE 'test/#sql-%';
SHOW TABLES;
INSERT INTO t2 VALUES (5,6),(7,8);
@ -181,13 +167,6 @@ let $orig_table_id = `select table_id from
--error 2013
ALTER TABLE t1 ADD INDEX (b), CHANGE c d int, ALGORITHM=INPLACE;
--echo # Restart mysqld after the crash and reconnect.
--source include/start_mysqld.inc
--replace_result $orig_table_id ID
eval SELECT * FROM information_schema.innodb_sys_tables
WHERE table_id = $orig_table_id;
perl;
die unless open OUT, ">$ENV{TABLENAME_INC}";
chdir "$ENV{'datadir'}/test";
@ -195,12 +174,17 @@ my @frm_file = map { substr($_, 0, -4) } glob "#sql-*.frm";
print OUT 'let $tablename=', $frm_file[0], ';';
close OUT or die;
EOF
source $TABLENAME_INC;
remove_file $TABLENAME_INC;
move_file $datadir/test/$tablename.frm $datadir/test/t1.frm;
FLUSH TABLES;
--echo # Restart mysqld after the crash and reconnect.
--source include/start_mysqld.inc
--replace_result $orig_table_id ID
eval SELECT * FROM information_schema.innodb_sys_tables
WHERE table_id = $orig_table_id;
--echo # Files in datadir after manual recovery.
--list_files $MYSQLD_DATADIR/test