diff options
author | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2021-10-29 19:04:53 +0900 |
---|---|---|
committer | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2022-06-13 23:44:59 +0900 |
commit | 06e9ce798c582ffb5a2f3cfbb0f8e33fe221feae (patch) | |
tree | 2ab25ed94d2d659c6c7c9f767bc690ebcf1cda5a | |
parent | d4760d8c016c6b65a473fbd6f66ca4db02749106 (diff) | |
download | mariadb-git-06e9ce798c582ffb5a2f3cfbb0f8e33fe221feae.tar.gz |
MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION
During rebuild of partition, the partitioning engine calls
alter_close_table(), which does not unlock and close some table
instances of the target table.
Then, the engine fails to rename partitions because there are table
instances that are still locked.
Closing all the table instance of the target table fixes the bug.
-rw-r--r-- | mysql-test/suite/parts/inc/part_alter_values.inc | 8 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_innodb.result | 7 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_maria.result | 7 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_myisam.result | 7 | ||||
-rw-r--r-- | sql/sql_partition.cc | 35 |
5 files changed, 55 insertions, 9 deletions
diff --git a/mysql-test/suite/parts/inc/part_alter_values.inc b/mysql-test/suite/parts/inc/part_alter_values.inc index ca18faa5758..d3b63a4610f 100644 --- a/mysql-test/suite/parts/inc/part_alter_values.inc +++ b/mysql-test/suite/parts/inc/part_alter_values.inc @@ -78,3 +78,11 @@ if (`SELECT IF('$engine' != 'InnoDB', 1, 0)`) --remove_files_wildcard $MYSQLTEST_VARDIR/tmp/mdev_27065 * --rmdir $MYSQLTEST_VARDIR/tmp/mdev_27065 + +--echo # +--echo # MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION +--echo # +--eval CREATE TABLE t1 (c INT) ENGINE=$engine PARTITION BY KEY(c) PARTITIONS 4; +LOCK TABLES t1 WRITE, t1 AS a READ; +ALTER TABLE t1 REBUILD PARTITION p0; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/r/partition_alter_innodb.result b/mysql-test/suite/parts/r/partition_alter_innodb.result index ae3caaa4981..6afa133f989 100644 --- a/mysql-test/suite/parts/r/partition_alter_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter_innodb.result @@ -61,3 +61,10 @@ PARTITION p1 VALUES LESS THAN MAXVALUE Warnings: Warning 1618 <DATA DIRECTORY> table option of old schema is ignored DROP TABLE t1; +# +# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION +# +CREATE TABLE t1 (c INT) ENGINE=InnoDB PARTITION BY KEY(c) PARTITIONS 4;; +LOCK TABLES t1 WRITE, t1 AS a READ; +ALTER TABLE t1 REBUILD PARTITION p0; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/r/partition_alter_maria.result b/mysql-test/suite/parts/r/partition_alter_maria.result index 358ffbdfbe7..eca8378430f 100644 --- a/mysql-test/suite/parts/r/partition_alter_maria.result +++ b/mysql-test/suite/parts/r/partition_alter_maria.result @@ -95,3 +95,10 @@ PARTITION p1 VALUES LESS THAN MAXVALUE Warnings: Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored DROP TABLE t2; +# +# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION +# +CREATE TABLE t1 (c INT) ENGINE=Aria PARTITION BY KEY(c) PARTITIONS 4;; +LOCK TABLES t1 WRITE, t1 AS a READ; +ALTER TABLE t1 REBUILD PARTITION p0; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/r/partition_alter_myisam.result b/mysql-test/suite/parts/r/partition_alter_myisam.result index 9d76881fdfa..ba1a0fe05c4 100644 --- a/mysql-test/suite/parts/r/partition_alter_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter_myisam.result @@ -68,6 +68,13 @@ PARTITION p1 VALUES LESS THAN MAXVALUE Warnings: Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored DROP TABLE t2; +# +# MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION +# +CREATE TABLE t1 (c INT) ENGINE=MyISAM PARTITION BY KEY(c) PARTITIONS 4;; +LOCK TABLES t1 WRITE, t1 AS a READ; +ALTER TABLE t1 REBUILD PARTITION p0; +DROP TABLE t1; create table t1 ( c1 int, c2 int, c3 varchar(100)) delay_key_write=1 partition by key(c1) ( partition p01 data directory = 'MYSQL_TMP_DIR' diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 1cf2d009d37..78f56992f46 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2005, 2017, Oracle and/or its affiliates. - Copyright (c) 2009, 2020, MariaDB + Copyright (c) 2009, 2022, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -6817,16 +6817,33 @@ static bool alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt) static int alter_close_table(ALTER_PARTITION_PARAM_TYPE *lpt) { - int error= 0; + THD *thd= lpt->thd; + TABLE_SHARE *share= lpt->table->s; DBUG_ENTER("alter_close_table"); - if (lpt->table->db_stat) - { - error= mysql_lock_remove(lpt->thd, lpt->thd->lock, lpt->table); - error= lpt->table->file->ha_close(); - lpt->table->db_stat= 0; // Mark file closed - } - DBUG_RETURN(error); + TABLE *table= thd->open_tables; + do { + table= find_locked_table(table, share->db.str, share->table_name.str); + if (!table) + { + DBUG_RETURN(0); + } + + if (table->db_stat) + { + if (int error= mysql_lock_remove(thd, thd->lock, table)) + { + DBUG_RETURN(error); + } + if (int error= table->file->ha_close()) + { + DBUG_RETURN(error); + } + table->db_stat= 0; // Mark file closed + } + } while ((table= table->next)); + + DBUG_RETURN(0); } |