Bug #114739 MySQL don't acquire dd::Tablespace's MDL lock in locked_tables_mode
Submitted: 23 Apr 8:04 Modified: 23 Apr 8:31
Reporter: biao li Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S6 (Debug Builds)
Version:8.0.36 OS:Any
Assigned to: CPU Architecture:Any
Tags: Genaral tablespace, truncate table

[23 Apr 8:04] biao li
Description:
mysqld: /home/lb/mysql-server/sql/dd/impl/cache/dictionary_client.cc:940: bool dd::cache::Dictionary_client::acquire(const K&, const T**, bool*, bool*) [with K = dd::Primary_id_key; T = dd::Tablespace]: Assertion `MDL_checker::is_read_locked(m_thd, *object)' failed.
3279 2024-04-23T07:46:15Z UTC - mysqld got signal 6 ;
3280 Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware.
3281 BuildID[sha1]=13d9e618acc56b08e2e4703e0359ad1934babae9
3282 Thread pointer: 0x7f5af0000da0
3283 Attempting backtrace. You can use the following information to find out
3284 where mysqld died. If you see no messages after this, something went
3285 terribly wrong...
3286 stack_bottom = 7f5c8c615a30 thread_stack 0x100000
3287 /home/lb/mysql-server/install/bin/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x43) [0x4aad5a0]
3288 /home/lb/mysql-server/install/bin/mysqld(print_fatal_signal(int)+0x388) [0x3688593]
3289 /home/lb/mysql-server/install/bin/mysqld(handle_fatal_signal+0x75) [0x3688796]
3290 /lib64/libpthread.so.0(+0xf630) [0x7f5cbdbc8630]
3291 /lib64/libc.so.6(gsignal+0x37) [0x7f5cbc66e387]
3292 /lib64/libc.so.6(abort+0x148) [0x7f5cbc66fa78]
3293 /lib64/libc.so.6(+0x2f1a6) [0x7f5cbc6671a6]
3294 /lib64/libc.so.6(+0x2f252) [0x7f5cbc667252]
3295 /home/lb/mysql-server/install/bin/mysqld(bool dd::cache::Dictionary_client::acquire<dd::Primary_id_key, dd::Tablespace>(dd::Primary_id_key const&, dd::Tablespace const**, bool*, bool*)+0x572) [0x4892f54]
3296 /home/lb/mysql-server/install/bin/mysqld(bool dd::cache::Dictionary_client::acquire<dd::Tablespace>(unsigned long long, dd::Tablespace const**)+0xae) [0x4871b54]
3297 /home/lb/mysql-server/install/bin/mysqld(int create_table_info_t::create_table_update_global_dd<dd::Table>(dd::Table*)+0x323) [0x4b4fd57]
3298 /home/lb/mysql-server/install/bin/mysqld(int innobase_basic_ddl::create_impl<dd::Table>(THD*, char const*, TABLE*, HA_CREATE_INFO*, dd::Table*, bool, bool, bool, unsigned int, unsigned int, dd::Table const*)+0x340) [0x4b50964]
3299 /home/lb/mysql-server/install/bin/mysqld(innobase_truncate<dd::Table>::truncate()+0x4da) [0x4b5e960]
3300 /home/lb/mysql-server/install/bin/mysqld(innobase_truncate<dd::Table>::exec()+0x34) [0x4b52fee]
3301 /home/lb/mysql-server/install/bin/mysqld(ha_innobase::truncate_impl(char const*, TABLE*, dd::Table*)+0x245) [0x4b29233]
3302 /home/lb/mysql-server/install/bin/mysqld(ha_innobase::create(char const*, TABLE*, HA_CREATE_INFO*, dd::Table*)+0x5b) [0x4b28869]
3303 /home/lb/mysql-server/install/bin/mysqld(handler::ha_create(char const*, TABLE*, HA_CREATE_INFO*, dd::Table*)+0x8c) [0x3828e2c]
3304 /home/lb/mysql-server/install/bin/mysqld(ha_create_table(THD*, char const*, char const*, char const*, HA_CREATE_INFO*, bool, bool, dd::Table*)+0x26e) [0x382949d]
3305 /home/lb/mysql-server/install/bin/mysqld(Sql_cmd_truncate_table::truncate_base(THD*, Table_ref*)+0x761) [0x3ba947d]
3306 /home/lb/mysql-server/install/bin/mysqld(Sql_cmd_truncate_table::execute(THD*)+0xab) [0x3ba9f51]
3307 /home/lb/mysql-server/install/bin/mysqld(mysql_execute_command(THD*, bool)+0x5504) [0x345e8a1]
3308 /home/lb/mysql-server/install/bin/mysqld(dispatch_sql_command(THD*, Parser_state*)+0x79b) [0x3460b40]
3309 /home/lb/mysql-server/install/bin/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x16e6) [0x34568a5]
3310 /home/lb/mysql-server/install/bin/mysqld(do_command(THD*)+0x5bd) [0x34547fb]
3311 /home/lb/mysql-server/install/bin/mysqld() [0x3673644]
3312 /home/lb/mysql-server/install/bin/mysqld() [0x565b354]
3313 /lib64/libpthread.so.0(+0x7ea5) [0x7f5cbdbc0ea5]
3314 /lib64/libc.so.6(clone+0x6d) [0x7f5cbc736b0d]
3315
3316 Trying to get some variables.
3317 Some pointers may be invalid and cause the dump to abort.
3318 Query (7f5af0107480): TRUNCATE TABLE t1
3319 Connection ID (thread ID): 7
3320 Status: NOT_KILLED
3321
3322 The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
3323 information that should help you find out what is causing the crash.         

How to repeat:
In MySQL's debug build.

create database ts;
create tablespace ts;
use ts;
CREATE TABLE t1(a INT) tablespace=ts;
CREATE VIEW ts.v1 AS SELECT * FROM t1;
LOCK TABLE ts.v1 WRITE;
TRUNCATE TABLE t1;

Suggested fix:
in Sql_cmd_truncate_table::lock_table, mysqld should acquire tablespace's read lock in locked_tables_mode.
[23 Apr 8:05] biao li
fix typo.
[23 Apr 8:31] MySQL Verification Team
Hello biao li,

Thank you for the report and test case.
Observed that 8.0.36 debug build is affected.

regards,
Umesh