[MDEV-18154] Deadlock and assertion upon no-op ALTER under LOCK TABLES Created: 2019-01-06  Updated: 2020-09-17  Resolved: 2019-08-16

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Locking
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.3.18, 10.4.8

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-14410 Assertion `table->pos_in_locked_table... Closed
relates to MDEV-15456 Server crashes upon adding or droppin... Closed
relates to MDEV-17838 AddressSanitizer: heap-use-after-free... Closed
relates to MDEV-17998 Deadlock and eventual Assertion `!tab... Closed
relates to MDEV-18696 Assertion `newtrn->used_instances != ... Closed

 Description   

Assertion `!table->pos_in_locked_tables' failed in tc_release_table or unexpected ER_STATEMENT_TIMEOUT upon altering table under locks

I'm not sure versioning has anything to do with it, but I could only reproduce it so far with ADD PERIOD FOR SYSTEM_TIME

SET max_statement_time= 1;
CREATE TABLE t1 (pk int, i int, primary key (pk)) ENGINE=MyISAM;
CREATE VIEW v1 AS SELECT * FROM t1;
LOCK TABLE v1 READ, t1 WRITE;
--error ER_BAD_FIELD_ERROR
ALTER TABLE t1 CHANGE f1 f2 INT;
ALTER TABLE t1 ADD PERIOD FOR SYSTEM_TIME(s,e);
 
# Cleanup
UNLOCK TABLES;
DROP VIEW v1;
DROP TABLE t1;

10.3 debug build faf206a848

mysqld: /data/src/10.3/sql/table_cache.cc:466: void tc_release_table(TABLE*): Assertion `!table->pos_in_locked_tables' failed.
190106 20:29:08 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f9ad6b03ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000564bc90ea7a8 in tc_release_table (table=0x7f9ac0121ae0) at /data/src/10.3/sql/table_cache.cc:466
#9  0x0000564bc8e317ef in close_thread_table (thd=0x7f9ac0000b00, table_ptr=0x7f9ac0000be0) at /data/src/10.3/sql/sql_base.cc:912
#10 0x0000564bc8e346a7 in Locked_tables_list::unlink_all_closed_tables (this=0x7f9ac00047f8, thd=0x7f9ac0000b00, lock=0x0, reopen_count=0) at /data/src/10.3/sql/sql_base.cc:2429
#11 0x0000564bc8e34a9e in Locked_tables_list::reopen_tables (this=0x7f9ac00047f8, thd=0x7f9ac0000b00, need_reopen=false) at /data/src/10.3/sql/sql_base.cc:2526
#12 0x0000564bc8fa481e in mysql_alter_table (thd=0x7f9ac0000b00, new_db=0x7f9ac00051b8, new_name=0x7f9ac0005578, create_info=0x7f9ad0ca8c80, table_list=0x7f9ac0014de0, alter_info=0x7f9ad0ca8bc0, order_num=0, order=0x0, ignore=false) at /data/src/10.3/sql/sql_table.cc:10053
#13 0x0000564bc902b5ab in Sql_cmd_alter_table::execute (this=0x7f9ac0015440, thd=0x7f9ac0000b00) at /data/src/10.3/sql/sql_alter.cc:497
#14 0x0000564bc8ecce78 in mysql_execute_command (thd=0x7f9ac0000b00) at /data/src/10.3/sql/sql_parse.cc:6285
#15 0x0000564bc8ed1f49 in mysql_parse (thd=0x7f9ac0000b00, rawbuf=0x7f9ac0014cd8 "ALTER TABLE t1 ADD PERIOD FOR SYSTEM_TIME(s,e)", length=46, parser_state=0x7f9ad0caa5f0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:8092
#16 0x0000564bc8ebf0fd in dispatch_command (command=COM_QUERY, thd=0x7f9ac0000b00, packet=0x7f9ac000b1e1 "ALTER TABLE t1 ADD PERIOD FOR SYSTEM_TIME(s,e)", packet_length=46, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1851
#17 0x0000564bc8ebdb21 in do_command (thd=0x7f9ac0000b00) at /data/src/10.3/sql/sql_parse.cc:1396
#18 0x0000564bc9025b36 in do_handle_one_connection (connect=0x564bcd050b30) at /data/src/10.3/sql/sql_connect.cc:1402
#19 0x0000564bc90258ba in handle_one_connection (arg=0x564bcd050b30) at /data/src/10.3/sql/sql_connect.cc:1308
#20 0x0000564bc94c01e1 in pfs_spawn_thread (arg=0x564bcd09d750) at /data/src/10.3/storage/perfschema/pfs.cc:1862
#21 0x00007f9ad85bf494 in start_thread (arg=0x7f9ad0cab700) at pthread_create.c:333
#22 0x00007f9ad6bc093f in clone () from /lib/x86_64-linux-gnu/libc.so.6

10.3 non-debug build faf206a848

mysqltest: At line 7: query 'ALTER TABLE t1 ADD PERIOD FOR SYSTEM_TIME(s,e)' failed: 1969: Query execution was interrupted (max_statement_time exceeded)

Cannot check 10.2, because the test case uses ADD PERIOD.



 Comments   
Comment by Aleksey Midenkov [ 2019-01-23 ]

Research progress

Comment by Aleksey Midenkov [ 2019-02-05 ]

Reproducible without System Versioning:

create or replace table t1 (pk int, i int, primary key (pk)) engine myisam;
create or replace view v1 as select * from t1;
lock table v1 read, t1 write;
alter table t1 change f1 f2 int;
set max_statement_time= 0.01;
alter table t1 add column if not exists i int after pk;
drop table t1;

Comment by Sergei Golubchik [ 2019-08-12 ]

incorrect treatment of table->m_need_reopen in the fix

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