From 7952f7720f967b43873e4fac13583984803fae3b Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 15 Oct 2019 20:26:40 +0300 Subject: [PATCH] MDEV-10748 Server crashes in ha_maria::implicit_commit Problem was in a combination of LOCK TABLES on several Aria tables followed by an ALTER TABLE. After the ALTER TABLE there was a force close + reopen of the alter table. The close failed because the table was still part of a transaction. Fixed by calling extra(HA_EXTRA_PREPARE_FOR_FORCED_CLOSE) as part of closing the table, which ensures that the table is not anymore part of the current transaction. --- mysql-test/suite/maria/lock.result | 12 ++++++++++++ mysql-test/suite/maria/lock.test | 17 +++++++++++++++++ sql/sql_base.cc | 14 +++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/maria/lock.result b/mysql-test/suite/maria/lock.result index b7d5a9c220d..a1f533e80fb 100644 --- a/mysql-test/suite/maria/lock.result +++ b/mysql-test/suite/maria/lock.result @@ -109,4 +109,16 @@ ALTER TABLE t1 ADD UNIQUE KEY (f1); ERROR 23000: Duplicate entry 'foo' for key 'f1' ALTER TABLE t1 ADD KEY (f2); DROP TABLE t1; +# +# MDEV-10748 Server crashes in ha_maria::implicit_commit upon ALTER TABLE +# +CREATE TABLE t1 (a INT, b INT) ENGINE=Aria; +SELECT * FROM t1; +a b +CREATE TABLE t2 (c INT) ENGINE=Aria; +LOCK TABLE t2 READ, t1 WRITE; +ALTER TABLE t1 CHANGE b a INT; +ERROR 42S21: Duplicate column name 'a' +UNLOCK TABLES; +DROP TABLE t1, t2; # End of 10.2 tests diff --git a/mysql-test/suite/maria/lock.test b/mysql-test/suite/maria/lock.test index b22c9cc70d7..220e3839010 100644 --- a/mysql-test/suite/maria/lock.test +++ b/mysql-test/suite/maria/lock.test @@ -118,4 +118,21 @@ ALTER TABLE t1 ADD UNIQUE KEY (f1); ALTER TABLE t1 ADD KEY (f2); DROP TABLE t1; + +--echo # +--echo # MDEV-10748 Server crashes in ha_maria::implicit_commit upon ALTER TABLE +--echo # + +CREATE TABLE t1 (a INT, b INT) ENGINE=Aria; +SELECT * FROM t1; +CREATE TABLE t2 (c INT) ENGINE=Aria; + +LOCK TABLE t2 READ, t1 WRITE; +--error ER_DUP_FIELDNAME +ALTER TABLE t1 CHANGE b a INT; + +# Cleanup +UNLOCK TABLES; +DROP TABLE t1, t2; + --echo # End of 10.2 tests diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 7276467f188..761c4daa88b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2426,9 +2426,17 @@ Locked_tables_list::reopen_tables(THD *thd, bool need_reopen) { if (!table_list->table || !table_list->table->needs_reopen()) continue; - /* no need to remove the table from the TDC here, thus (TABLE*)1 */ - close_all_tables_for_name(thd, table_list->table->s, - HA_EXTRA_NOT_USED, (TABLE*)1); + for (TABLE **prev= &thd->open_tables; *prev; prev= &(*prev)->next) + { + if (*prev == table_list->table) + { + thd->locked_tables_list.unlink_from_list(thd, table_list, false); + mysql_lock_remove(thd, thd->lock, *prev); + (*prev)->file->extra(HA_EXTRA_PREPARE_FOR_FORCED_CLOSE); + close_thread_table(thd, prev); + break; + } + } DBUG_ASSERT(table_list->table == NULL); } else