Bug #79820 Assertion `thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, ""
Submitted: 1 Jan 2016 22:14 Modified: 5 Oct 2017 18:44
Reporter: Roel Van de Paar Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S6 (Debug Builds)
Version:5.7.10, 5.7.11, 8.0.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: debug

[1 Jan 2016 22:14] Roel Van de Paar
Description:
+bt
#0  0x00007f7d173bb771 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:61
#1  0x00000000017ef4b0 in my_write_core (sig=6) at /git/mysql-server_dbg/mysys/stacktrace.c:247
#2  0x0000000000e58274 in handle_fatal_signal (sig=6) at /git/mysql-server_dbg/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x00007f7d157555d7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#5  0x00007f7d15756cc8 in __GI_abort () at abort.c:90
#6  0x00007f7d1574e546 in __assert_fail_base (fmt=0x7f7d1589e128 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x1f4dc78 "thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, \"\", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)", file=file@entry=0x1f4dc10 "/git/mysql-server_dbg/sql/unireg.cc", line=line@entry=263, function=function@entry=0x1f4dfa0 <mysql_create_frm(THD*, char const*, char const*, char const*, st_ha_create_information*, List<Create_field>&, unsigned int, st_key*, handler*)::__PRETTY_FUNCTION__> "bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*)") at assert.c:92
#7  0x00007f7d1574e5f2 in __GI___assert_fail (assertion=0x1f4dc78 "thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, \"\", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)", file=0x1f4dc10 "/git/mysql-server_dbg/sql/unireg.cc", line=263, function=0x1f4dfa0 <mysql_create_frm(THD*, char const*, char const*, char const*, st_ha_create_information*, List<Create_field>&, unsigned int, st_key*, handler*)::__PRETTY_FUNCTION__> "bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*)") at assert.c:101
#8  0x00000000015eda69 in mysql_create_frm (thd=0x7f7c4a019000, file_name=0x7f7d179a9fc0 "./test/#sql-8d9_2.frm", db=0x7f7c4a02bf88 "test", table=0x7f7d179abe90 "#sql-8d9_2", create_info=0x7f7d179acce0, create_fields=..., keys=0, key_info=0x7f7c4a02c480, db_file=0x7f7c4a02c190) at /git/mysql-server_dbg/sql/unireg.cc:260
#9  0x00000000015ee8fa in rea_create_table (thd=0x7f7c4a019000, path=0x7f7d179ac6e4 "./test/#sql-8d9_2", db=0x7f7c4a02bf88 "test", table_name=0x7f7d179abe90 "#sql-8d9_2", create_info=0x7f7d179acce0, create_fields=..., keys=0, key_info=0x7f7c4a02c480, file=0x7f7c4a02c190, no_ha_table=true) at /git/mysql-server_dbg/sql/unireg.cc:507
#10 0x000000000156ffc0 in create_table_impl (thd=0x7f7c4a019000, db=0x7f7c4a02bf88 "test", table_name=0x7f7d179abe90 "#sql-8d9_2", path=0x7f7d179ac6e4 "./test/#sql-8d9_2", create_info=0x7f7d179acce0, alter_info=0x7f7d179acc30, internal_tmp_table=true, select_field_count=0, no_ha_table=true, is_trans=0x0, key_info=0x7f7d179ac908, key_count=0x7f7d179ac904) at /git/mysql-server_dbg/sql/sql_table.cc:5193
#11 0x0000000001578e7b in mysql_alter_table (thd=0x7f7c4a019000, new_db=0x7f7c4a02bf88 "test", new_name=0x0, create_info=0x7f7d179acce0, table_list=0x7f7c4a02ba00, alter_info=0x7f7d179acc30) at /git/mysql-server_dbg/sql/sql_table.cc:9229
#12 0x00000000016cf8af in Sql_cmd_alter_table::execute (this=0x7f7c4a02bfa0, thd=0x7f7c4a019000) at /git/mysql-server_dbg/sql/sql_alter.cc:316
#13 0x00000000014e959d in mysql_execute_command (thd=0x7f7c4a019000, first_level=true) at /git/mysql-server_dbg/sql/sql_parse.cc:4796
#14 0x00000000014eb36d in mysql_parse (thd=0x7f7c4a019000, parser_state=0x7f7d179ae560) at /git/mysql-server_dbg/sql/sql_parse.cc:5508
#15 0x00000000014e0ca7 in dispatch_command (thd=0x7f7c4a019000, com_data=0x7f7d179aecb0, command=COM_QUERY) at /git/mysql-server_dbg/sql/sql_parse.cc:1425
#16 0x00000000014dfb71 in do_command (thd=0x7f7c4a019000) at /git/mysql-server_dbg/sql/sql_parse.cc:993
#17 0x000000000160ad5b in handle_connection (arg=0x7f7c6378d820) at /git/mysql-server_dbg/sql/conn_handler/connection_handler_per_thread.cc:301
#18 0x000000000181b8fc in pfs_spawn_thread (arg=0x7f7c63be8120) at /git/mysql-server_dbg/storage/perfschema/pfs.cc:2192
#19 0x00007f7d173b6df5 in start_thread (arg=0x7f7d179af700) at pthread_create.c:308
#20 0x00007f7d158161ad in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

2016-01-01T22:01:19.594091Z 0 [Note] /sdc/MS-mysql-5.7.10-linux-x86_64-debug/bin/mysqld: ready for connections.
Version: '5.7.10-debug'  socket: '/sdc/MS-mysql-5.7.10-linux-x86_64-debug/socket.sock'  port: 18119  MySQL Community Server (GPL)
mysqld: /git/mysql-server_dbg/sql/unireg.cc:263: bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*): Assertion `thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, "", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)' failed.
22:01:24 UTC - mysqld got signal 6 ;
[...]
Query (7f7c4a02b030): ALTER TABLE t1 TABLESPACE ts STORAGE DISK ENGINE=InnoDB
Connection ID (thread ID): 2
Status: NOT_KILLED

How to repeat:
# mysqld options required for replay:  --sql_mode=
DROP DATABASE test;CREATE DATABASE test;USE test;
CREATE TABLE t3(c5 int);
CREATE TABLE t2(c3 int,c4 int);
CREATE TABLE t1(c1 int,c2 int);
LOCK TABLE t1 WRITE,t2 WRITE,t3 WRITE;
ALTER TABLE t1 TABLESPACE ts STORAGE DISK ENGINE=InnoDB;
[2 Jan 2016 3:52] MySQL Verification Team
Hello Roel,

Thank you for the report and test case.
Observed that 5.7.10, 5.7.11 and 5.8.0 debug builds are affected.

Thanks,
Umesh
[1 Mar 2016 7:41] Sivert Sørumgård
Posted by developer:
 
ALTER TABLE ... TABLESPACE under LOCK TABLE will not acquire meta data lock on the new tablespace name. For schema handling in a similar setting, locks har acquired in Alter_table_ctx::is_database_changed(). We probably need a similar mechanism for tablespaces; alternatively, get_and_lock_tablespace_names() must be extended to also acquire locks when under LOCK TABLE.
[18 Jun 2016 21:35] Omer Barnir
Posted by developer:
 
Reported version value updated to reflect release name change from 5.8 to 8.0
[5 Oct 2017 18:44] Paul DuBois
Posted by developer:
 
Fixed in 8.0.4.

Failure to acquire tablespace metadata locks for ALTER TABLE when a
LOCK TABLES was active could cause an assertion to be raised.
[28 Jan 2020 18:09] Tomislav Plavcic
Seems this is still reproducible in 5.7.29:

Client:
5.7.29>CREATE TABLE t3(c5 int);
Query OK, 0 rows affected (0.02 sec)

5.7.29>CREATE TABLE t2(c3 int,c4 int);
Query OK, 0 rows affected (0.01 sec)

5.7.29>CREATE TABLE t1(c1 int,c2 int);
Query OK, 0 rows affected (0.00 sec)

5.7.29>LOCK TABLE t1 WRITE,t2 WRITE,t3 WRITE;
Query OK, 0 rows affected (0.01 sec)

5.7.29>ALTER TABLE t1 TABLESPACE ts STORAGE DISK ENGINE=InnoDB;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Error log:
2020-01-28T18:05:48.741084Z 0 [Note] /home/tomislav.plavcic/build/mysql-5.7.29-linux-x86_64-debug/bin/mysqld: ready for connections.
Version: '5.7.29-debug'  socket: '/home/tomislav.plavcic/build/mysql-5.7.29-linux-x86_64-debug/socket.sock'  port: 18895  MySQL Community Server (GPL)
mysqld: /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/unireg.cc:270: bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*): Assertion `thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, "", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)' failed.
18:05:54 UTC - mysqld got signal 6 ;

GDB:
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x0000560494a793b8 in my_write_core (sig=6) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/mysys/stacktrace.c:261
#2  0x000056049401938a in handle_fatal_signal (sig=6) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/signal_handler.cc:227
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007fe034462801 in __GI_abort () at abort.c:79
#6  0x00007fe03445239a in __assert_fail_base (fmt=0x7fe0345d97d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
    assertion=assertion@entry=0x560495230548 "thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, \"\", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)",
    file=file@entry=0x5604952304c8 "/home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/unireg.cc", line=line@entry=270,
    function=function@entry=0x560495230800 <mysql_create_frm(THD*, char const*, char const*, char const*, st_ha_create_information*, List<Create_field>&, unsigned int, st_key*, handler*)::__PRETTY_FUNCTION__> "bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*)") at assert.c:92
#7  0x00007fe034452412 in __GI___assert_fail (assertion=0x560495230548 "thd->mdl_context.owns_equal_or_stronger_lock( MDL_key::TABLESPACE, \"\", create_info->tablespace, MDL_INTENTION_EXCLUSIVE)",
    file=0x5604952304c8 "/home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/unireg.cc", line=270,
    function=0x560495230800 <mysql_create_frm(THD*, char const*, char const*, char const*, st_ha_create_information*, List<Create_field>&, unsigned int, st_key*, handler*)::__PRETTY_FUNCTION__> "bool mysql_create_frm(THD*, const char*, const char*, const char*, HA_CREATE_INFO*, List<Create_field>&, uint, KEY*, handler*)") at assert.c:101
#8  0x0000560494824eb5 in mysql_create_frm (thd=0x7fe00b419000, file_name=0x7fe036b0aee0 "./test/#sql-4d91_4.frm", db=0x7fe00b427f90 "test", table=0x7fe036b0ccf0 "#sql-4d91_4", create_info=0x7fe036b0dd10,
    create_fields=..., keys=0, key_info=0x7fe00b428488, db_file=0x7fe00b428198) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/unireg.cc:267
#9  0x0000560494826072 in rea_create_table (thd=0x7fe00b419000, path=0x7fe036b0d544 "./test/#sql-4d91_4", db=0x7fe00b427f90 "test", table_name=0x7fe036b0ccf0 "#sql-4d91_4", create_info=0x7fe036b0dd10,
    create_fields=..., keys=0, key_info=0x7fe00b428488, file=0x7fe00b428198, no_ha_table=true) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/unireg.cc:548
#10 0x00005604947a3db0 in create_table_impl (thd=0x7fe00b419000, db=0x7fe00b427f90 "test", table_name=0x7fe036b0ccf0 "#sql-4d91_4", error_table_name=0x7fe00b4279d0 "t1",
    path=0x7fe036b0d544 "./test/#sql-4d91_4", create_info=0x7fe036b0dd10, alter_info=0x7fe036b0dc60, internal_tmp_table=true, select_field_count=0, no_ha_table=true, is_trans=0x0, key_info=0x7fe036b0c2b0,
    key_count=0x7fe036b0c284) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_table.cc:5350
#11 0x00005604947add9f in mysql_alter_table (thd=0x7fe00b419000, new_db=0x7fe00b427f90 "test", new_name=0x0, create_info=0x7fe036b0dd10, table_list=0x7fe00b427a08, alter_info=0x7fe036b0dc60)
    at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_table.cc:9640
#12 0x0000560494938617 in Sql_cmd_alter_table::execute (this=0x7fe00b427fa8, thd=0x7fe00b419000) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_alter.cc:333
#13 0x00005604947112e8 in mysql_execute_command (thd=0x7fe00b419000, first_level=true) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_parse.cc:4845
#14 0x00005604947133f5 in mysql_parse (thd=0x7fe00b419000, parser_state=0x7fe036b0f4f0) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_parse.cc:5584
#15 0x00005604947082f9 in dispatch_command (thd=0x7fe00b419000, com_data=0x7fe036b0fda0, command=COM_QUERY) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_parse.cc:1491
#16 0x0000560494707183 in do_command (thd=0x7fe00b419000) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/sql_parse.cc:1032
#17 0x000056049484b074 in handle_connection (arg=0x7fe015efd500) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/sql/conn_handler/connection_handler_per_thread.cc:313
#18 0x0000560494f46a60 in pfs_spawn_thread (arg=0x7fe01efd4220) at /home/tomislav.plavcic/build/tmp/mysql-server_dbg/storage/perfschema/pfs.cc:2197
#19 0x00007fe0351596db in start_thread (arg=0x7fe036b10700) at pthread_create.c:463
#20 0x00007fe03454388f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95