Bug #76424 thd->mdl_context.owns_equal_or_stronger_lock | create_info->tablespace
Submitted: 21 Mar 2015 6:43 Modified: 16 Apr 2015 18:16
Reporter: Roel Van de Paar (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S6 (Debug Builds)
Version:5.7.5-m16, 5.7.6, 5.7.8 OS:Any
Assigned to: CPU Architecture:Any

[21 Mar 2015 6:43] Roel Van de Paar
Description:
2015-03-21T06:33:50.489148Z 0 [Note] /sda/MS-mysql-5.7.6-m16-linux-x86_64-debug/bin/mysqld: ready for connections.
Version: '5.7.6-m16-debug'  socket: '/dev/shm/go/socket.sock'  port: 55893  MySQL Community Server (GPL)
mysqld: /bzr/mysql-5.7.6-m16_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.
06:33:52 UTC - mysqld got signal 6 ;

+bt
#0  0x00007f4276d2b771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x00000000013a521c in my_write_core (sig=6) at /bzr/mysql-5.7.6-m16_dbg/mysys/stacktrace.c:247
#2  0x0000000000bb713c in handle_fatal_signal (sig=6) at /bzr/mysql-5.7.6-m16_dbg/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x00007f427592f5c9 in raise () from /lib64/libc.so.6
#5  0x00007f4275930cd8 in abort () from /lib64/libc.so.6
#6  0x00007f4275928536 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f42759285e2 in __assert_fail () from /lib64/libc.so.6
#8  0x00000000011a7298 in mysql_create_frm (thd=0x7f4204000bb0, file_name=0x7f426c755450 "./test/#sql-5402_2.frm", db=0x7f42040062a0 "test", table=0x7f426c757740 "#sql-5402_2", create_info=0x7f426c758590, create_fields=..., keys=0, key_info=0x7f4204006860, db_file=0x7f4204006580) at /bzr/mysql-5.7.6-m16_dbg/sql/unireg.cc:260
#9  0x00000000011a8074 in rea_create_table (thd=0x7f4204000bb0, path=0x7f426c757f94 "./test/#sql-5402_2", db=0x7f42040062a0 "test", table_name=0x7f426c757740 "#sql-5402_2", create_info=0x7f426c758590, create_fields=..., keys=0, key_info=0x7f4204006860, file=0x7f4204006580, no_ha_table=true) at /bzr/mysql-5.7.6-m16_dbg/sql/unireg.cc:493
#10 0x000000000112ebe1 in create_table_impl (thd=0x7f4204000bb0, db=0x7f42040062a0 "test", table_name=0x7f426c757740 "#sql-5402_2", path=0x7f426c757f94 "./test/#sql-5402_2", create_info=0x7f426c758590, alter_info=0x7f426c7584e0, internal_tmp_table=true, select_field_count=0, no_ha_table=true, is_trans=0x0, key_info=0x7f426c7581c0, key_count=0x7f426c7581bc) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_table.cc:5054
#11 0x0000000001136f8e in mysql_alter_table (thd=0x7f4204000bb0, new_db=0x7f42040062a0 "test", new_name=0x0, create_info=0x7f426c758590, table_list=0x7f4204005d28, alter_info=0x7f426c7584e0) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_table.cc:8750
#12 0x00000000012890db in Sql_cmd_alter_table::execute (this=0x7f42040062b0, thd=0x7f4204000bb0) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_alter.cc:316
#13 0x00000000010a917e in mysql_execute_command (thd=0x7f4204000bb0) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_parse.cc:4452
#14 0x00000000010aae7a in mysql_parse (thd=0x7f4204000bb0, parser_state=0x7f426c759e40) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_parse.cc:5129
#15 0x00000000010a0bd4 in dispatch_command (command=COM_QUERY, thd=0x7f4204000bb0, packet=0x7f4204009e61 "ALTER TABLE t1 TABLESPACE=s1", packet_length=28) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_parse.cc:1249
#16 0x000000000109f925 in do_command (thd=0x7f4204000bb0) at /bzr/mysql-5.7.6-m16_dbg/sql/sql_parse.cc:835
#17 0x00000000011c2fd9 in handle_connection (arg=0x3eedab0) at /bzr/mysql-5.7.6-m16_dbg/sql/conn_handler/connection_handler_per_thread.cc:298
#18 0x00000000013d2299 in pfs_spawn_thread (arg=0x3dd37f0) at /bzr/mysql-5.7.6-m16_dbg/storage/perfschema/pfs.cc:2147
#19 0x00007f4276d26df3 in start_thread () from /lib64/libpthread.so.0
#20 0x00007f42759f01ad in clone () from /lib64/libc.so.6

How to repeat:
Testcase:

DROP TABLE IF EXISTS t1;
CREATE TABLESPACE s1 ADD DATAFILE 'a.ibd';
CREATE TABLE t1 (c int) TABLESPACE s1;
ALTER TABLE t1 DISCARD PARTITION p TABLESPACE;
ALTER TABLE t1 TABLESPACE=s1;

Specific replay (make_binary_distribution based setup):

$ cat ./replay
ps -ef | egrep "/dev/shm/go" | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null
rm -Rf /dev/shm/go
mkdir -p /dev/shm/go/data
/sda/MS-mysql-5.7.6-m16-linux-x86_64-debug/bin/mysqld --initialize-insecure --basedir=/sda/MS-mysql-5.7.6-m16-linux-x86_64-debug --datadir=/dev/shm/go/datamkdir -p /dev/shm/go/data/test
/sda/MS-mysql-5.7.6-m16-linux-x86_64-debug/bin/mysqld --no-defaults --basedir=/sda/MS-mysql-5.7.6-m16-linux-x86_64-debug --datadir=/dev/shm/go/data --tmpdir=/dev/shm/go --core-file --port=55893 --pid_file=/dev/shm/go/pid.pid --socket=/dev/shm/go/socket.sock --log-output=none --log-error=/dev/shm/go/master.err &
sleep 5
/sda/MS-mysql-5.7.6-m16-linux-x86_64-debug/bin/mysql -uroot --socket=/dev/shm/go/socket.sock --force test < ./test.sql

Suggested fix:
This bug is seen very regularly in testing, many failures each round. Looks like a serious bug or regression in m16.
[21 Mar 2015 10:28] Umesh Shastry
Hello Roel,

Thank you for the report and test case.
Confirmed that 5.7.6 debug build is affected.

Thanks,
Umesh
[16 Apr 2015 18:16] Paul Dubois
Noted in 5.7.8, 5.8.0 changelogs.

A failing ALTER TABLE tablespace operation (DISCARD TABLESPACE or 
IMPORT TABLESPACE could produce an incorrect internal tablespace
state, causing a succeeding statement to fail.