Bug #76236 failing MDL tablespace assertion for alter ndb table in unireg.cc:263
Submitted: 10 Mar 2015 7:59 Modified: 16 Apr 2015 13:04
Reporter: Mattias Jonsson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Locking Severity:S3 (Non-critical)
Version:5.7.7 OS:Any
Assigned to: CPU Architecture:Any

[10 Mar 2015 7:59] Mattias Jonsson
Description:
ndb.ndb_dd_restore_compat asserts in Debug on the following assert:

      DBUG_ASSERT(thd->mdl_context.owns_equal_or_stronger_lock(
                                     MDL_key::TABLESPACE, "",
                                     create_info->tablespace,
                                     MDL_INTENTION_EXCLUSIVE));

According to the test the TABLESPACE is not recorded in the .frm file, so this may be the cause there is no MDL lock taken for the TABLESPACE used by the table.

Thread 1 (Thread 0x7fef0c0f5700 (LWP 8226)):
#0  0x0000003c3e80c63c in pthread_kill () from /lib64/libpthread.so.0
#1  0x000000000151e15d in my_write_core (sig=6) at /home/mjonsson/branches/test-5.7/mysys/stacktrace.c:247
#2  0x0000000000cb1cf0 in handle_fatal_signal (sig=6) at /home/mjonsson/branches/test-5.7/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x0000003fe7032885 in raise () from /lib64/libc.so.6
#5  0x0000003fe7034065 in abort () from /lib64/libc.so.6
#6  0x0000003fe702b9fe in __assert_fail_base () from /lib64/libc.so.6
#7  0x0000003fe702bac0 in __assert_fail () from /lib64/libc.so.6
#8  0x0000000001310848 in mysql_create_frm (thd=0x7fee70011ff0, file_name=0x7fef0c0ef8c0 "./test/#sql-1f53_4.frm", db=0x7fee700c1e18 "test", table=0x7fef0c0f0c10 "#sql-1f53_4", create_info=0x7fef0c0f2ab0, create_fields=..., keys=1, key_info=0x7fee701b2240, db_file=0x7fee700049e0) at /home/mjonsson/branches/test-5.7/sql/unireg.cc:263
#9  0x0000000001311666 in rea_create_table (thd=0x7fee70011ff0, path=0x7fef0c0f1464 "./test/#sql-1f53_4", db=0x7fee700c1e18 "test", table_name=0x7fef0c0f0c10 "#sql-1f53_4", create_info=0x7fef0c0f2ab0, create_fields=..., keys=1, key_info=0x7fee701b2240, file=0x7fee700049e0, no_ha_table=true) at /home/mjonsson/branches/test-5.7/sql/unireg.cc:493
#10 0x0000000001296af6 in create_table_impl (thd=0x7fee70011ff0, db=0x7fee700c1e18 "test", table_name=0x7fef0c0f0c10 "#sql-1f53_4", path=0x7fef0c0f1464 "./test/#sql-1f53_4", create_info=0x7fef0c0f2ab0, alter_info=0x7fef0c0f2b90, internal_tmp_table=true, select_field_count=0, no_ha_table=true, is_trans=0x0, key_info=0x7fef0c0f2218, key_count=0x7fef0c0f2214) at /home/mjonsson/branches/test-5.7/sql/sql_table.cc:5066
#11 0x000000000129f1ec in mysql_alter_table (thd=0x7fee70011ff0, new_db=0x7fee700c1e18 "test", new_name=0x0, create_info=0x7fef0c0f2ab0, table_list=0x7fee700c1890, alter_info=0x7fef0c0f2b90) at /home/mjonsson/branches/test-5.7/sql/sql_table.cc:8767
#12 0x00000000013fee8b in Sql_cmd_alter_table::execute (this=0x7fee700c1f00, thd=0x7fee70011ff0) at /home/mjonsson/branches/test-5.7/sql/sql_alter.cc:316
#13 0x000000000120e7b8 in mysql_execute_command (thd=0x7fee70011ff0) at /home/mjonsson/branches/test-5.7/sql/sql_parse.cc:4477
#14 0x0000000001210527 in mysql_parse (thd=0x7fee70011ff0, parser_state=0x7fef0c0f4540) at /home/mjonsson/branches/test-5.7/sql/sql_parse.cc:5154
#15 0x00000000012055da in dispatch_command (command=COM_QUERY, thd=0x7fee70011ff0, packet=0x7fee70101741 "ALTER TABLE t1 ADD COLUMN c int", packet_length=31) at /home/mjonsson/branches/test-5.7/sql/sql_parse.cc:1249
#16 0x0000000001204099 in do_command (thd=0x7fee70011ff0) at /home/mjonsson/branches/test-5.7/sql/sql_parse.cc:835
#17 0x000000000132ce1b in handle_connection (arg=0x50398b0) at /home/mjonsson/branches/test-5.7/sql/conn_handler/connection_handler_per_thread.cc:298
#18 0x0000000001af3fb5 in pfs_spawn_thread (arg=0x4f8e130) at /home/mjonsson/branches/test-5.7/storage/perfschema/pfs.cc:2147
#19 0x0000003c3e8077f1 in start_thread () from /lib64/libpthread.so.0
#20 0x0000003fe70e5ccd in clone () from /lib64/libc.so.6

How to repeat:
Build mysql-5.7 with cmake -DWITH_NDBCLUSTER=1 -DWITH_DEBUG=1
cd mysql-test
./mtr ndb.ndb_dd_restore_compat

Suggested fix:
Handle TABLESPACE MDL correctly also for NDB.
[16 Apr 2015 13:04] Paul DuBois
Noted in 5.7.8, 5.8.0 changelogs.

NDB could raise an assertion for failure to get the tablespace name
when attempting to acquire a metadata lock.