[MDEV-18078] Assertion `trnman_has_locked_tables(trn) > 0' failed in ha_maria::external_lock upon concurrent ALTER TABLE and BACKUP STAGE BLOCK_COMMIT Created: 2018-12-25  Updated: 2019-06-18  Resolved: 2019-06-18

Status: Closed
Project: MariaDB Server
Component/s: Locking, Storage Engine - Aria
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.2.26, 10.3.17, 10.4.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Michael Widenius
Resolution: Fixed Votes: 0
Labels: None


 Description   

See also MDEV-18291, the test case there is remarkably similar.

Run with --repeat=N with a big enough N (luckily the test case is fast). It usually fails within ~100 attempts for me.

CREATE TABLE t1 ( 
  f1 YEAR NOT NULL DEFAULT '1970',
  f2 TINYINT NOT NULL DEFAULT 0,
  f3 INT(11) ZEROFILL AS (f2),
  f4 TIME NOT NULL DEFAULT '00:00:00',
  f5 SET('','a','b','c','d','e','f','foo','bar') NOT NULL DEFAULT '',
  f6 DATE NOT NULL DEFAULT '1900-01-01'
) ENGINE=Aria;
 
--connect (con1,localhost,root,,test)
--error ER_NO_SUCH_TABLE
ALTER TABLE unknown_table;
 
BACKUP STAGE START;
BACKUP STAGE BLOCK_COMMIT;
BACKUP STAGE END;
CREATE USER foo;
BACKUP STAGE START;
--send
  BACKUP STAGE BLOCK_COMMIT;
 
--connection default
--error 0,ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 NOWAIT DROP CONSTRAINT IF EXISTS f;
 
--connection con1
--reap
--disconnect con1
--connection default
DROP TABLE t1;
DROP USER foo;

10.4 4edb29380c

mysqld: /data/src/10.4-bug/storage/maria/ha_maria.cc:2836: virtual int ha_maria::external_lock(THD*, int): Assertion `trnman_has_locked_tables(trn) > 0' failed.
190121  0:16:45 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f52e725dee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x00005591c3e6b584 in ha_maria::external_lock (this=0x7f52d0083dd8, thd=0x7f52d0000b00, lock_type=2) at /data/src/10.4-bug/storage/maria/ha_maria.cc:2836
#9  0x00005591c3c5b25c in handler::ha_external_lock (this=0x7f52d0083dd8, thd=0x7f52d0000b00, lock_type=2) at /data/src/10.4-bug/sql/handler.cc:6198
#10 0x00005591c3d7ddad in unlock_external (thd=0x7f52d0000b00, table=0x7f52d0017160, count=1) at /data/src/10.4-bug/sql/lock.cc:714
#11 0x00005591c3d7d28b in mysql_unlock_tables (thd=0x7f52d0000b00, sql_lock=0x7f52d0017130, free_lock=false) at /data/src/10.4-bug/sql/lock.cc:435
#12 0x00005591c3d7d1e3 in mysql_unlock_tables (thd=0x7f52d0000b00, sql_lock=0x7f52d0017130) at /data/src/10.4-bug/sql/lock.cc:421
#13 0x00005591c38a1f10 in close_thread_tables (thd=0x7f52d0000b00) at /data/src/10.4-bug/sql/sql_base.cc:957
#14 0x00005591c394405b in mysql_execute_command (thd=0x7f52d0000b00) at /data/src/10.4-bug/sql/sql_parse.cc:6400
#15 0x00005591c3948c16 in mysql_parse (thd=0x7f52d0000b00, rawbuf=0x7f52d0014fb8 "ALTER TABLE t1 NOWAIT DROP CONSTRAINT IF EXISTS f", length=49, parser_state=0x7f52e13d7600, is_com_multi=false, is_next_command=false) at /data/src/10.4-bug/sql/sql_parse.cc:8116
#16 0x00005591c3935db3 in dispatch_command (command=COM_QUERY, thd=0x7f52d0000b00, packet=0x7f52d000b441 "ALTER TABLE t1 NOWAIT DROP CONSTRAINT IF EXISTS f", packet_length=49, is_com_multi=false, is_next_command=false) at /data/src/10.4-bug/sql/sql_parse.cc:1852
#17 0x00005591c39347d7 in do_command (thd=0x7f52d0000b00) at /data/src/10.4-bug/sql/sql_parse.cc:1397
#18 0x00005591c3aa0a92 in do_handle_one_connection (connect=0x5591c6599550) at /data/src/10.4-bug/sql/sql_connect.cc:1402
#19 0x00005591c3aa0816 in handle_one_connection (arg=0x5591c6599550) at /data/src/10.4-bug/sql/sql_connect.cc:1308
#20 0x00005591c3f5fdec in pfs_spawn_thread (arg=0x5591c64dd7f0) at /data/src/10.4-bug/storage/perfschema/pfs.cc:1862
#21 0x00007f52e8f34494 in start_thread (arg=0x7f52e13d8700) at pthread_create.c:333
#22 0x00007f52e731a93f in clone () from /lib/x86_64-linux-gnu/libc.so.6



 Comments   
Comment by Michael Widenius [ 2019-06-18 ]

Problem was that in case of implicit rollback for alter table Aria did try to run commit twice.
Fixed by checking THD if commit has already been done.
10.2 has a one line fix while in 10.4 I added some extra assert() calls and also a test case.

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