[MDEV-31028] Assertion `m_tickets[MDL_STATEMENT].is_empty()' failed in MDL_context::set_transaction_duration_for_all_locks Created: 2023-04-08  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Locking, Storage Engine - Aria
Affects Version/s: 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1
Fix Version/s: 10.6, 10.11, 11.0

Type: Bug Priority: Critical
Reporter: Roel Van de Paar Assignee: Michael Widenius
Resolution: Unresolved Votes: 0
Labels: regression-10.6


 Description   

CREATE TABLE t (c ENUM ('''')) ENGINE=InnoDB;
LOCK TABLE t WRITE;
SET sql_mode=strict_all_tables;
CREATE OR REPLACE TABLE t (a INT) ENGINE=Aria COMMENT=''SELECT'' AS a;

Leads to:

11.1.0 2b61ff8f2221745f0a96855a0feb0825c426f993 (Debug)

mariadbd: /test/11.1_dbg/sql/mdl.cc:3261: void MDL_context::set_transaction_duration_for_all_locks(): Assertion `m_tickets[MDL_STATEMENT].is_empty()' failed.

11.1.0 2b61ff8f2221745f0a96855a0feb0825c426f993 (Debug)

Core was generated by `/test/MD070423-mariadb-11.1.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22428113688128)
    at ./nptl/pthread_kill.c:44
[Current thread is 1 (Thread 0x1465f3bfd640 (LWP 3787284))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22428113688128) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=22428113688128) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=22428113688128, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x000014662cb67476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x000014662cb4d7f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000014662cb4d71b in __assert_fail_base (fmt=0x14662cd02150 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55bd05740338 "m_tickets[MDL_STATEMENT].is_empty()", file=0x55bd0573fd19 "/test/11.1_dbg/sql/mdl.cc", line=3261, function=<optimized out>) at ./assert/assert.c:92
#6  0x000014662cb5ee96 in __GI___assert_fail (assertion=0x55bd05740338 "m_tickets[MDL_STATEMENT].is_empty()", file=0x55bd0573fd19 "/test/11.1_dbg/sql/mdl.cc", line=3261, function=0x55bd05740db8 "void MDL_context::set_transaction_duration_for_all_locks()") at ./assert/assert.c:101
#7  0x000055bd04d6e704 in MDL_context::set_transaction_duration_for_all_locks (this=this@entry=0x1465c0000eb0) at /test/11.1_dbg/sql/mdl.cc:3261
#8  0x000055bd04ba3f60 in THD::leave_locked_tables_mode (this=this@entry=0x1465c0000d58) at /test/11.1_dbg/sql/sql_class.cc:6020
#9  0x000055bd04b84130 in Locked_tables_list::unlock_locked_tables (this=this@entry=0x1465c0004db8, thd=thd@entry=0x1465c0000d58) at /test/11.1_dbg/sql/sql_base.cc:2595
#10 0x000055bd04b842a9 in Locked_tables_list::unlock_locked_table (this=0x1465c0004db8, thd=0x1465c0000d58, mdl_ticket=<optimized out>) at /test/11.1_dbg/sql/sql_base.cc:2643
#11 0x000055bd04bc08f0 in select_create::abort_result_set (this=0x1465c0014a00) at /test/11.1_dbg/sql/sql_insert.cc:5329
#12 0x000055bd04c93044 in handle_select (thd=thd@entry=0x1465c0000d58, lex=lex@entry=0x1465c0004ec8, result=result@entry=0x1465c0014a00, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/11.1_dbg/sql/sql_select.cc:629
#13 0x000055bd04ce2974 in Sql_cmd_create_table_like::execute (this=<optimized out>, thd=0x1465c0000d58) at /test/11.1_dbg/sql/sql_table.cc:12422
#14 0x000055bd04c09604 in mysql_execute_command (thd=thd@entry=0x1465c0000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/11.1_dbg/sql/sql_parse.cc:5760
#15 0x000055bd04c0af05 in mysql_parse (thd=thd@entry=0x1465c0000d58, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1465f3bfc230) at /test/11.1_dbg/sql/sql_parse.cc:7760
#16 0x000055bd04c0d099 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x1465c0000d58, packet=packet@entry=0x1465c000ae49 "CREATE OR REPLACE TABLE t (a INT) ENGINE=Aria COMMENT=''SELECT'' AS a", packet_length=packet_length@entry=69, blocking=blocking@entry=true) at /test/11.1_dbg/sql/sql_class.h:242
#17 0x000055bd04c0eef5 in do_command (thd=0x1465c0000d58, blocking=blocking@entry=true) at /test/11.1_dbg/sql/sql_parse.cc:1405
#18 0x000055bd04d60cfc in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55bd08081e98, put_in_cache=put_in_cache@entry=true) at /test/11.1_dbg/sql/sql_connect.cc:1416
#19 0x000055bd04d60f5b in handle_one_connection (arg=0x55bd08081e98) at /test/11.1_dbg/sql/sql_connect.cc:1318
#20 0x000014662cbb9b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#21 0x000014662cc4ba00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Bug confirmed present in:
MariaDB: 10.6.13 (dbg), 10.7.8 (dbg), 10.8.8 (dbg), 10.9.6 (dbg), 10.10.4 (dbg), 10.11.3 (dbg), 11.0.2 (dbg), 11.1.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.4.29 (dbg), 10.4.29 (opt), 10.5.20 (dbg), 10.5.20 (opt), 10.6.13 (opt), 10.7.8 (opt), 10.8.8 (opt), 10.9.6 (opt), 10.10.4 (opt), 10.11.3 (opt), 11.0.2 (opt), 11.1.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.40 (dbg), 5.7.40 (opt), 8.0.31 (dbg), 8.0.31 (opt)



 Comments   
Comment by Roel Van de Paar [ 2023-04-08 ]

Regression was introduced recently. Git bisect in progress complete: dd5f4b3625def2ee74d8f9a6b55d1368ba597a84 is the first bad commit

commit dd5f4b3625def2ee74d8f9a6b55d1368ba597a84
Author: Monty <monty@mariadb.org>
Date:   Thu Dec 8 12:10:58 2022 +0200
 
    Fixed bug in Aria when used with enterprise mariadb-backup
    
    If the backup finished in the middle of a Aria bulk load insert,
    which could happen with LOAD DATA INFILE, CREATE ... SELECT etc)
    there was a chance that Aria recovery would fail on the backup.
    
    Fixed by ensuring that bulk load operations for Aria are not allowed
    under BACKUP LOCK.
    I also changed so that the table TRN is updated just before truncate
    which ensures that old redo's for the table are ignored.
    I also enabled Aria redo for DDL's to be able to repeat REPAIR commands.
    Without this change recovery would not work on repaired tables.
    
    Notes:
    - We take the backup lock protection at the end of bulk insert (as we
      don't want to keep the lock over a very long running insert).
      If mariadb-backup keeps the backup lock too long,  this may fail with
      a lock timeout. In this case the batch insert will fail and the table
      will be truncated (set to it's original state).

Comment by Roel Van de Paar [ 2023-04-08 ]

MTR Testcase

--source include/have_innodb.inc
CREATE TABLE t (c ENUM ('''')) ENGINE=InnoDB;
LOCK TABLE t WRITE;
SET sql_mode=strict_all_tables;
CREATE OR REPLACE TABLE t (a INT) ENGINE=Aria COMMENT=''SELECT'' AS a;

Generated at Thu Feb 08 10:20:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.