[MDEV-28952] Assertion `t->s->tmp_table || thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE ? MDL_SHARED_WRITE : MDL_SHARED_READ)' failed Created: 2022-06-27  Updated: 2022-06-28  Resolved: 2022-06-28

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: 10.10
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Ramesh Sivaraman Assignee: Aleksey Midenkov
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-28956 Locking is broken if CREATE OR REPLAC... Closed
Problem/Incident
is caused by MDEV-25292 Atomic CREATE OR REPLACE TABLE Stalled

 Description   

--source include/have_innodb.inc
--source include/have_sequence.inc
 
CREATE OR REPLACE TABLE t1 (id VARCHAR(64) NOT NULL) ENGINE=InnoDB;
SET autocommit=FALSE;
CREATE TABLE t2 (c CHAR(1)) ENGINE=InnoDB;
LOCK TABLES t1 WRITE,t2 WRITE;
--error 1005
CREATE OR REPLACE TABLE t1 (b INT) ENGINE=SEQUENCE;
--error 1025
ALTER TABLE t1 RENAME mysqltest.t1;
--error 1100
INSERT INTO t1 VALUES (100,100);
FLUSH TABLES;

Leads to

10.10.0 7ac78c5aaf026d46ccecb94e0badd9cab5c28869

mysqld: /test/mtest/10.10/sql/lock.cc:170: int lock_tables_check(THD*, TABLE**, uint, uint): Assertion `t->s->tmp_table || thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE ? MDL_SHARED_WRITE : MDL_SHARED_READ)' failed.

10.10.0 7ac78c5aaf026d46ccecb94e0badd9cab5c28869

Core was generated by `/test/mtest/mariadb-10.10.0-linux-x86_64-ddl_new/bin/mysqld --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x14f4f8111700 (LWP 2895445))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x0000562bc58a88aa in my_write_core (sig=6) at /test/mtest/10.10/mysys/stacktrace.c:424
#2  0x0000562bc4fff117 in handle_fatal_signal (sig=6) at /test/mtest/10.10/sql/signal_handler.cc:345
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#5  0x000014f4fa6be859 in __GI_abort () at abort.c:79
#6  0x000014f4fa6be729 in __assert_fail_base (fmt=0x14f4fa854588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x562bc5c0b288 "t->s->tmp_table || thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE ? MDL_SHARED_WRITE : MDL_SHARED_READ)", file=0x562bc5c0b131 "/test/mtest/10.10/sql/lock.cc", line=170, function=<optimized out>) at assert.c:92
#7  0x000014f4fa6d0006 in __GI___assert_fail (assertion=0x562bc5c0b288 "t->s->tmp_table || thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE ? MDL_SHARED_WRITE : MDL_SHARED_READ)", file=0x562bc5c0b131 "/test/mtest/10.10/sql/lock.cc", line=170, function=0x562bc5c0b198 "int lock_tables_check(THD*, TABLE**, uint, uint)") at assert.c:101
#8  0x0000562bc517ea98 in lock_tables_check (thd=0x14f4b4000db8, tables=0x14f4f810f9c0, count=2, flags=18539) at /test/mtest/10.10/sql/lock.cc:170
#9  0x0000562bc517ed52 in mysql_lock_tables (thd=0x14f4b4000db8, tables=0x14f4f810f9c0, count=2, flags=18539) at /test/mtest/10.10/sql/lock.cc:291
#10 0x0000562bc4b7d347 in Locked_tables_list::reopen_tables (this=0x14f4b4004ff0, thd=0x14f4b4000db8, need_reopen=false) at /test/mtest/10.10/sql/sql_base.cc:2870
#11 0x0000562bc4b77a46 in close_cached_tables (thd=0x14f4b4000db8, tables=0x0, wait_for_refresh=true, timeout=86400) at /test/mtest/10.10/sql/sql_base.cc:403
#12 0x0000562bc4e52435 in reload_acl_and_cache (thd=0x14f4b4000db8, options=4, tables=0x0, write_to_binlog=0x14f4f810feb0) at /test/mtest/10.10/sql/sql_reload.cc:337
#13 0x0000562bc4c39c84 in mysql_execute_command (thd=0x14f4b4000db8, is_called_from_prepared_stmt=false) at /test/mtest/10.10/sql/sql_parse.cc:5463
#14 0x0000562bc4c41f16 in mysql_parse (thd=0x14f4b4000db8, rawbuf=0x14f4b4013f40 "FLUSH TABLES", length=12, parser_state=0x14f4f8110480) at /test/mtest/10.10/sql/sql_parse.cc:8038
#15 0x0000562bc4c2e2ac in dispatch_command (command=COM_QUERY, thd=0x14f4b4000db8, packet=0x14f4b400b9e9 "FLUSH TABLES", packet_length=12, blocking=true) at /test/mtest/10.10/sql/sql_parse.cc:1894
#16 0x0000562bc4c2cc8d in do_command (thd=0x14f4b4000db8, blocking=true) at /test/mtest/10.10/sql/sql_parse.cc:1407
#17 0x0000562bc4e0aebb in do_handle_one_connection (connect=0x562bc912e2c8, put_in_cache=true) at /test/mtest/10.10/sql/sql_connect.cc:1418
#18 0x0000562bc4e0ab4b in handle_one_connection (arg=0x562bc923c5c8) at /test/mtest/10.10/sql/sql_connect.cc:1312
#19 0x0000562bc531f3bf in pfs_spawn_thread (arg=0x562bc9131e78) at /test/mtest/10.10/storage/perfschema/pfs.cc:2201
#20 0x000014f4fabea609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x000014f4fa7bb163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

ramesh@rame



 Comments   
Comment by Aleksey Midenkov [ 2022-06-27 ]

Cannot reproduce:

mysqltest: At line 8: query 'CREATE OR REPLACE TABLE t1 (b INT) ENGINE=SEQUENCE' failed: ER_CANT_CREATE_TABLE (1005): Can't create table `test`.`t1` (errno: 131 "Command not supported by the engine")

The full test:

--source include/have_innodb.inc
--source include/have_sequence.inc
 
CREATE OR REPLACE TABLE t1 (id VARCHAR(64) NOT NULL) ENGINE=InnoDB;
SET autocommit=FALSE;
CREATE TABLE t2 (c CHAR(1)) ENGINE=InnoDB;
LOCK TABLES t1 WRITE,t2 WRITE;
CREATE OR REPLACE TABLE t1 (b INT) ENGINE=SEQUENCE;
ALTER TABLE t1 RENAME mysqltest.t1;
INSERT INTO t1 VALUES (100,100);
FLUSH TABLES;

Comment by Ramesh Sivaraman [ 2022-06-28 ]

midenok CREATE TABLE failure is expected in the test case. Could you please try this test case to reproduce the crash.

--source include/have_innodb.inc
--source include/have_sequence.inc
 
CREATE OR REPLACE TABLE t1 (id VARCHAR(64) NOT NULL) ENGINE=InnoDB;
SET autocommit=FALSE;
CREATE TABLE t2 (c CHAR(1)) ENGINE=InnoDB;
LOCK TABLES t1 WRITE,t2 WRITE;
--error 1005
CREATE OR REPLACE TABLE t1 (b INT) ENGINE=SEQUENCE;
--error 1025
ALTER TABLE t1 RENAME mysqltest.t1;
--error 1100
INSERT INTO t1 VALUES (100,100);
FLUSH TABLES;

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