midenok / mariadb

MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
GNU General Public License v2.0
0 stars 0 forks source link

MDEV-22283 Server crashes in key_copy or unexpected error 156: The table already existed in the storage engine #72

Open midenok opened 4 years ago

midenok commented 4 years ago

Reproduce

--source include/have_partition.inc

create table t1 (a int primary key) engine=aria page_checksum=0
with system versioning
partition by system_time (partition p1 history, partition pn current);

alter table t1 add partition (partition p2 history);
show table status;
drop table t1;

create table t1 (b int) engine=aria row_format=dynamic with system versioning
partition by system_time (partition p1 history, partition pn current);
insert into t1 values (1);
replace into t1 values (1);

# cleanup
drop table t1;

Result

#0  0x00000000007ecea0 in Diagnostics_area::set_error_status (this=0x7f5d50006700, sql_errno=156, message=0x7f5d618c6970 "Aria table 't1#P#pn' is in use (most likely by a MERGE table). Try FLUSH TABLES.", sqlstate=0x169c5b6 "42S01", ucid=..., error_condition=0x0) at /home/midenok/src/mariadb/10.4/src/sql/sql_error.cc:468
#1  0x00000000007c0139 in THD::raise_condition (this=0x7f5d50000d28, sql_errno=156, sqlstate=0x169c5b6 "42S01", level=Sql_state_errno_level::WARN_LEVEL_ERROR, ucid=..., msg=0x7f5d618c6970 "Aria table 't1#P#pn' is in use (most likely by a MERGE table). Try FLUSH TABLES.") at /home/midenok/src/mariadb/10.4/src/sql/sql_class.cc:1099
#2  0x00000000006e33dd in THD::raise_condition (this=0x7f5d50000d28, sql_errno=156, sqlstate=0x0, level=Sql_state_errno_level::WARN_LEVEL_ERROR, msg=0x7f5d618c6970 "Aria table 't1#P#pn' is in use (most likely by a MERGE table). Try FLUSH TABLES.") at /home/midenok/src/mariadb/10.4/src/sql/sql_class.h:4366
#3  0x00000000006d0302 in my_message_sql (error=156, str=0x7f5d618c6970 "Aria table 't1#P#pn' is in use (most likely by a MERGE table). Try FLUSH TABLES.", MyFlags=0) at /home/midenok/src/mariadb/10.4/src/sql/mysqld.cc:3367
#4  0x00000000015c5243 in my_printf_error (error=156, format=0x18c3cbb "Aria table '%s' is in use (most likely by a MERGE table). Try FLUSH TABLES.", MyFlags=0) at /home/midenok/src/mariadb/10.4/src/mysys/my_error.c:154
#5  0x00000000013ab6e8 in maria_create (name=0x7f5d618c9030 "./test/t1#P#pn", datafile_type=DYNAMIC_RECORD, keys=0, keydefs=0x7f5d5004cf78, columns=3, columndef=0x7f5d5004cdb8, uniques=0, uniquedefs=0x0, ci=0x7f5d618c8fd0, flags=34) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_create.c:919
#6  0x00000000013b8d75 in ha_maria::create (this=0x7f5d50087c30, name=0x7f5d618c9620 "./test/t1#P#pn", table_arg=0x7f5d618ca0d8, ha_create_info=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:3191
#7  0x0000000000bed8c1 in handler::ha_create (this=0x7f5d50087c30, name=0x7f5d618c9620 "./test/t1#P#pn", form=0x7f5d618ca0d8, info_arg=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4731
#8  0x000000000156b7ac in ha_partition::create (this=0x7f5d50086c90, name=0x7f5d618cbe10 "./test/t1", table_arg=0x7f5d618ca0d8, create_info=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:763
#9  0x0000000000bed8c1 in handler::ha_create (this=0x7f5d50086c90, name=0x7f5d618cbe10 "./test/t1", form=0x7f5d618ca0d8, info_arg=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4731
#10 0x0000000000bef487 in ha_create_table (thd=0x7f5d50000d28, path=0x7f5d618cbe10 "./test/t1", db=0x7f5d50014930 "test", table_name=0x7f5d50014238 "t1", create_info=0x7f5d618cc428, frm=0x7f5d618cbe00) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:5195
#11 0x00000000009523fd in create_table_impl (thd=0x7f5d50000d28, orig_db=..., orig_table_name=..., db=..., table_name=..., path=0x7f5d618cbe10 "./test/t1", options=..., create_info=0x7f5d618cc428, alter_info=0x7f5d618cc370, create_table_mode=0, is_trans=0x7f5d618cc157, key_info=0x7f5d618cc020, key_count=0x7f5d618cc01c, frm=0x7f5d618cbe00) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5073
#12 0x00000000009515a8 in mysql_create_table_no_lock (thd=0x7f5d50000d28, db=0x7f5d50014288, table_name=0x7f5d50014298, create_info=0x7f5d618cc428, alter_info=0x7f5d618cc370, is_trans=0x7f5d618cc157, create_table_mode=0, table_list=0x7f5d50014270) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5157
#13 0x00000000009529c0 in mysql_create_table (thd=0x7f5d50000d28, create_table=0x7f5d50014270, create_info=0x7f5d618cc428, alter_info=0x7f5d618cc370) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5249
#14 0x0000000000967edf in Sql_cmd_create_table_like::execute (this=0x7f5d50014210, thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:11469
#15 0x0000000000855e0b in mysql_execute_command (thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6101
#16 0x0000000000846330 in mysql_parse (thd=0x7f5d50000d28, rawbuf=0x7f5d50014080 "create table t1 (b int) engine=aria row_format=dynamic with system versioning\npartition by system_time (partition p1 history, partition pn current)", length=147, parser_state=0x7f5d618cf5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

frame 1

(rr) p /s kfilename
$9 = "/home/midenok/src/mariadb/10.4/build/mysql-test/var/mysqld.1/data/test/t1#P#pn.MAI\000\000\000\000\
midenok commented 4 years ago

Good: Aria deletes partition

--source include/have_partition.inc

create table t1 (a int primary key) engine aria with system versioning
partition by system_time (partition p1 history, partition pn current);

drop table t1;
#0  my_delete (name=0x7fc1e5835970 "./test/t1#P#pn.MAI", MyFlags=32784) at /home/midenok/src/mariadb/10.4/src/mysys/my_delete.c:34
#1  0x00000000015d3c17 in my_handler_delete_with_symlink (filename=0x7fc1e5835970 "./test/t1#P#pn.MAI", sync_dir=32784) at /home/midenok/src/mariadb/10.4/src/mysys/my_symlink2.c:188
#2  0x0000000001460bee in inline_mysql_file_delete_with_symlink (key=43, src_file=0x18dc61a "/home/midenok/src/mariadb/10.4/src/storage/maria/ma_delete_table.c", src_line=89, name=0x7fc1e5836480 "./test/t1#P#pn", ext=0x18c3cb6 ".MAI", flags=32784) at /home/midenok/src/mariadb/10.4/src/include/mysql/psi/mysql_file.h:1427
#3  0x00000000014609ba in maria_delete_table_files (name=0x7fc1e5836480 "./test/t1#P#pn", temporary=0 '\000', sync_dir=32768) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_delete_table.c:89
#4  0x000000000146090c in maria_delete_table (name=0x7fc1e5836480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_delete_table.c:81
#5  0x00000000013b75e4 in ha_maria::delete_table (this=0x7fc1d4015998, name=0x7fc1e5836480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:2696
#6  0x0000000000be52c1 in handler::ha_delete_table (this=0x7fc1d4015998, name=0x7fc1e5836480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#7  0x0000000001569e39 in ha_partition::del_ren_table (this=0x7fc1d4014a30, from=0x7fc1e5838370 "./test/t1", to=0x0) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:2399
#8  0x000000000156999c in ha_partition::delete_table (this=0x7fc1d4014a30, name=0x7fc1e5838370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:579
#9  0x0000000000be52c1 in handler::ha_delete_table (this=0x7fc1d4014a30, name=0x7fc1e5838370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#10 0x0000000000be5094 in ha_delete_table (thd=0x7fc1d4000d28, table_type=0x3332588, path=0x7fc1e5838370 "./test/t1", db=0x7fc1e58381d0, alias=0x7fc1d4014160, generate_warning=true) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2588
#11 0x000000000094c865 in mysql_rm_table_no_locks (thd=0x7fc1d4000d28, tables=0x7fc1d4014138, if_exists=false, drop_temporary=false, drop_view=false, drop_sequence=false, dont_log_query=false, dont_free_locks=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2484
#12 0x000000000094b5d2 in mysql_rm_table (thd=0x7fc1d4000d28, tables=0x7fc1d4014138, if_exists=false, drop_temporary=false, drop_sequence=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2121
#13 0x00000000008510af in mysql_execute_command (thd=0x7fc1d4000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:4865
#14 0x0000000000846330 in mysql_parse (thd=0x7fc1d4000d28, rawbuf=0x7fc1d4014080 "drop table t1", length=13, parser_state=0x7fc1e583b5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

Bad: _ma_test_if_reopen() returns true

#0  _ma_test_if_reopen (filename=0x7f5d618c8c30 "/home/midenok/src/mariadb/10.4/build/mysql-test/var/mysqld.1/data/test/t1#P#pn.MAI") at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:68
#1  0x00000000013ab699 in maria_create (name=0x7f5d618c9030 "./test/t1#P#pn", datafile_type=DYNAMIC_RECORD, keys=0, keydefs=0x7f5d5004cf78, columns=3, columndef=0x7f5d5004cdb8, uniques=0, uniquedefs=0x0, ci=0x7f5d618c8fd0, flags=34) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_create.c:917
#2  0x00000000013b8d75 in ha_maria::create (this=0x7f5d50087c30, name=0x7f5d618c9620 "./test/t1#P#pn", table_arg=0x7f5d618ca0d8, ha_create_info=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:3191
#3  0x0000000000bed8c1 in handler::ha_create (this=0x7f5d50087c30, name=0x7f5d618c9620 "./test/t1#P#pn", form=0x7f5d618ca0d8, info_arg=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4731
#4  0x000000000156b7ac in ha_partition::create (this=0x7f5d50086c90, name=0x7f5d618cbe10 "./test/t1", table_arg=0x7f5d618ca0d8, create_info=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:763
#5  0x0000000000bed8c1 in handler::ha_create (this=0x7f5d50086c90, name=0x7f5d618cbe10 "./test/t1", form=0x7f5d618ca0d8, info_arg=0x7f5d618cc428) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4731
#6  0x0000000000bef487 in ha_create_table (thd=0x7f5d50000d28, path=0x7f5d618cbe10 "./test/t1", db=0x7f5d50014930 "test", table_name=0x7f5d50014238 "t1", create_info=0x7f5d618cc428, frm=0x7f5d618cbe00) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:5195
61      MARIA_HA *_ma_test_if_reopen(const char *filename)
62      {
63        LIST *pos;
64
65        for (pos=maria_open_list ; pos ; pos=pos->next)
66        {
67          MARIA_HA *info=(MARIA_HA*) pos->data;
68          MARIA_SHARE *share= info->s;
69          if (!strcmp(share->unique_file_name.str,filename) && share->last_version)
70            return info;
71        }
72        return 0;
73      }
(rr) p maria_open_list
$30 = (LIST *) 0x7f5d5007f978
(rr) p maria_open_list->next->next->next->next->next
$34 = (struct st_list *) 0x4735568
(rr) p share->data_file_name
$56 = {
  str = 0x7f5d500749b8 "./test/t1#P#pn.MAD",
  length = 18
}
(rr) p share
$57 = (MARIA_SHARE *) 0x7f5d500739c8

Cause

maria_open_list was not cleared.

midenok commented 4 years ago

maria_open_list cleared

#0  maria_close (info=0x7f5d50086c78) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_close.c:85
#1  0x00000000014607e7 in maria_delete_table (name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_delete_table.c:55
#2  0x00000000013b75e4 in ha_maria::delete_table (this=0x7f5d500160f8, name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:2696
#3  0x0000000000be52c1 in handler::ha_delete_table (this=0x7f5d500160f8, name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#4  0x0000000001569e39 in ha_partition::del_ren_table (this=0x7f5d50014a30, from=0x7f5d618cc370 "./test/t1", to=0x0) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:2399
#5  0x000000000156999c in ha_partition::delete_table (this=0x7f5d50014a30, name=0x7f5d618cc370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:579
#6  0x0000000000be52c1 in handler::ha_delete_table (this=0x7f5d50014a30, name=0x7f5d618cc370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#7  0x0000000000be5094 in ha_delete_table (thd=0x7f5d50000d28, table_type=0x45c7588, path=0x7f5d618cc370 "./test/t1", db=0x7f5d618cc1d0, alias=0x7f5d50014160, generate_warning=true) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2588
#8  0x000000000094c865 in mysql_rm_table_no_locks (thd=0x7f5d50000d28, tables=0x7f5d50014138, if_exists=false, drop_temporary=false, drop_view=false, drop_sequence=false, dont_log_query=false, dont_free_locks=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2484
#9  0x000000000094b5d2 in mysql_rm_table (thd=0x7f5d50000d28, tables=0x7f5d50014138, if_exists=false, drop_temporary=false, drop_sequence=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2121
#10 0x00000000008510af in mysql_execute_command (thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:4865
#11 0x0000000000846330 in mysql_parse (thd=0x7f5d50000d28, rawbuf=0x7f5d50014080 "drop table t1", length=13, parser_state=0x7f5d618cf5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900
83        if (!internal_table)
84        {
85          maria_open_list=  list_delete(maria_open_list,&info->open_list);
86          share->open_list= list_delete(share->open_list, &info->share_list);
87        }
(rr) p info->s
$60 = (MARIA_SHARE *) 0x7f5d500739c8
(rr) p info->s->data_file_name
$61 = {
  str = 0x7f5d500749b8 "./test/t1#P#pn.MAD",
  length = 18
}
(rr) p ((MARIA_HA *)maria_open_list->data)->s->data_file_name
$84 = {
  str = 0x7f5d500749b8 "./test/t1#P#pn.MAD",
  length = 18
}
(rr) p ((MARIA_HA *)maria_open_list->next->next->next->next->data)->s->data_file_name
$85 = {
  str = 0x7f5d500749b8 "./test/t1#P#pn.MAD",
  length = 18
}

Cause

Duplicate elements in maria_open_list.

midenok commented 4 years ago

1. maria_open_list->next->next->next->next assigned

#0  0x000000000140dca7 in maria_clone_internal (share=0x7f5d500739c8, mode=2, data_file=37, internal_table=0) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:218
#1  0x000000000140a1f7 in maria_open (name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, open_flags=1106) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:1054
#2  0x00000000013b1640 in ha_maria::open (this=0x7f5d50036fe0, name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, test_if_locked=1042) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:1152
#3  0x0000000000be5745 in handler::ha_open (this=0x7f5d50036fe0, table_arg=0x7f5d500628f8, name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, test_if_locked=1042, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2749
#4  0x0000000001576605 in ha_partition::open_read_partitions (this=0x7f5d5004af20, name_buff=0x7f5d618c83a0 "./test/t1#P#pn", name_buff_size=513) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:8509
#5  0x0000000001575d45 in ha_partition::open (this=0x7f5d5004af20, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:3591
#6  0x0000000000be5745 in handler::ha_open (this=0x7f5d5004af20, table_arg=0x7f5d500628f8, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2749
#7  0x00000000009a8523 in open_table_from_share (thd=0x7f5d50000d28, share=0x7f5d5003d650, alias=0x7f5d5002e148, db_stat=33, prgflag=8, ha_open_flags=18, outparam=0x7f5d500628f8, is_create_table=false, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:3949
#8  0x000000000078d374 in open_table (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:2082
#9  0x0000000000792185 in open_and_process_table (thd=0x7f5d50000d28, tables=0x7f5d5002e100, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248, has_prelocking_list=false, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:3850
#10 0x0000000000790b5b in open_tables (thd=0x7f5d50000d28, options=..., start=0x7f5d618c9258, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:4322
#11 0x0000000000795bf5 in open_tables (thd=0x7f5d50000d28, tables=0x7f5d618c9258, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.h:257
#12 0x0000000000795964 in open_normal_and_derived_tables (thd=0x7f5d50000d28, tables=0x7f5d5002e100, flags=1090, dt_phases=35) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:5280
#13 0x0000000000795ca2 in open_tables_only_view_structure (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, can_deadlock=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:5331
#14 0x000000000091590d in fill_schema_table_by_open (thd=0x7f5d50000d28, mem_root=0x7f5d618cb180, is_show_fields_or_keys=false, table=0x7f5d5001f2a0, schema_table=0x1e0dfe0 <schema_tables+2048>, orig_db_name=0x7f5d50019fd8, orig_table_name=0x7f5d5001a060, open_tables_state_backup=0x7f5d618cb1e8, can_deadlock=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:4656
#15 0x00000000009153c6 in get_all_tables (thd=0x7f5d50000d28, tables=0x7f5d50015d68, cond=0x0) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:5294
#16 0x0000000000921ccc in get_schema_tables_result (join=0x7f5d500181c0, executed_place=PROCESSED_BY_JOIN_EXEC) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:8913
#17 0x00000000008c64d3 in JOIN::exec_inner (this=0x7f5d500181c0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4416
#18 0x00000000008c568e in JOIN::exec (this=0x7f5d500181c0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4241
#19 0x0000000000899638 in mysql_select (thd=0x7f5d50000d28, tables=0x7f5d50015d68, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2684619520, result=0x7f5d50018198, unit=0x7f5d50004c40, select_lex=0x7f5d50005438) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4673
#20 0x0000000000898ce1 in handle_select (thd=0x7f5d50000d28, lex=0x7f5d50004b80, result=0x7f5d50018198, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:410
#21 0x0000000000857e3a in execute_sqlcom_select (thd=0x7f5d50000d28, all_tables=0x7f5d50015d68) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6359
#22 0x000000000084d4bd in mysql_execute_command (thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:3898
#23 0x0000000000846330 in mysql_parse (thd=0x7f5d50000d28, rawbuf=0x7f5d50014080 "show table status", length=17, parser_state=0x7f5d618cf5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

2. maria_open_list->data assigned

#0  0x000000000140dca7 in maria_clone_internal (share=0x7f5d500739c8, mode=0, data_file=37, internal_table=0) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:218
#1  0x000000000140a1f7 in maria_open (name=0x7f5d618ca480 "./test/t1#P#pn", mode=0, open_flags=32) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:1054
#2  0x000000000146074b in maria_delete_table (name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_delete_table.c:44
#3  0x00000000013b75e4 in ha_maria::delete_table (this=0x7f5d500160f8, name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:2696
#4  0x0000000000be52c1 in handler::ha_delete_table (this=0x7f5d500160f8, name=0x7f5d618ca480 "./test/t1#P#pn") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#5  0x0000000001569e39 in ha_partition::del_ren_table (this=0x7f5d50014a30, from=0x7f5d618cc370 "./test/t1", to=0x0) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:2399
#6  0x000000000156999c in ha_partition::delete_table (this=0x7f5d50014a30, name=0x7f5d618cc370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:579
#7  0x0000000000be52c1 in handler::ha_delete_table (this=0x7f5d50014a30, name=0x7f5d618cc370 "./test/t1") at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:4697
#8  0x0000000000be5094 in ha_delete_table (thd=0x7f5d50000d28, table_type=0x45c7588, path=0x7f5d618cc370 "./test/t1", db=0x7f5d618cc1d0, alias=0x7f5d50014160, generate_warning=true) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2588
#9  0x000000000094c865 in mysql_rm_table_no_locks (thd=0x7f5d50000d28, tables=0x7f5d50014138, if_exists=false, drop_temporary=false, drop_view=false, drop_sequence=false, dont_log_query=false, dont_free_locks=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2484
#10 0x000000000094b5d2 in mysql_rm_table (thd=0x7f5d50000d28, tables=0x7f5d50014138, if_exists=false, drop_temporary=false, drop_sequence=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2121
#11 0x00000000008510af in mysql_execute_command (thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:4865
#12 0x0000000000846330 in mysql_parse (thd=0x7f5d50000d28, rawbuf=0x7f5d50014080 "drop table t1", length=13, parser_state=0x7f5d618cf5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

Notes

Open is done in different modes.

midenok commented 4 years ago

Good: instance removed on DELETE

#0  maria_close (info=0x7f1ef80338e8) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_close.c:28
#1  0x00000000013b1c72 in ha_maria::close (this=0x7f1ef8024580) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:1236
#2  0x0000000000be62f7 in handler::ha_close (this=0x7f1ef8024580) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2815
#3  0x00000000009a95dd in closefrm (table=0x7f1ef8023788) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:4053
#4  0x0000000000aea7f7 in intern_close_table (table=0x7f1ef8023788) at /home/midenok/src/mariadb/10.4/src/sql/table_cache.cc:221
#5  0x0000000000aee32b in tdc_remove_table (thd=0x7f1ef8000d28, remove_type=TDC_RT_REMOVE_ALL, db=0x7f1ef80147f8 "test", table_name=0x7f1ef8014100 "t1", kill_delayed_threads=false) at /home/midenok/src/mariadb/10.4/src/sql/table_cache.cc:1148
#6  0x000000000094c6eb in mysql_rm_table_no_locks (thd=0x7f1ef8000d28, tables=0x7f1ef8014138, if_exists=false, drop_temporary=false, drop_view=false, drop_sequence=false, dont_log_query=false, dont_free_locks=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2473
#7  0x000000000094b5d2 in mysql_rm_table (thd=0x7f1ef8000d28, tables=0x7f1ef8014138, if_exists=false, drop_temporary=false, drop_sequence=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:2121
#8  0x00000000008510af in mysql_execute_command (thd=0x7f1ef8000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:4865
#9  0x0000000000846330 in mysql_parse (thd=0x7f1ef8000d28, rawbuf=0x7f1ef8014080 "drop table t1", length=13, parser_state=0x7f1f08df65e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

Bad: 1. share acquired

#0  0x0000000000aece05 in tdc_acquire_share (thd=0x7f5d50000d28, tl=0x7f5d5002e100, flags=3, out_table=0x7f5d618c8db8) at /home/midenok/src/mariadb/10.4/src/sql/table_cache.cc:849
#1  0x000000000078cc35 in open_table (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:1944
#2  0x0000000000792185 in open_and_process_table (thd=0x7f5d50000d28, tables=0x7f5d5002e100, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248, has_prelocking_list=false, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:3850
#3  0x0000000000790b5b in open_tables (thd=0x7f5d50000d28, options=..., start=0x7f5d618c9258, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:4322
#4  0x0000000000795bf5 in open_tables (thd=0x7f5d50000d28, tables=0x7f5d618c9258, counter=0x7f5d618c9244, flags=1090, prelocking_strategy=0x7f5d618c9248) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.h:257
#5  0x0000000000795964 in open_normal_and_derived_tables (thd=0x7f5d50000d28, tables=0x7f5d5002e100, flags=1090, dt_phases=35) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:5280
#6  0x0000000000795ca2 in open_tables_only_view_structure (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, can_deadlock=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:5331
#7  0x000000000091590d in fill_schema_table_by_open (thd=0x7f5d50000d28, mem_root=0x7f5d618cb180, is_show_fields_or_keys=false, table=0x7f5d5001f2a0, schema_table=0x1e0dfe0 <schema_tables+2048>, orig_db_name=0x7f5d50019fd8, orig_table_name=0x7f5d5001a060, open_tables_state_backup=0x7f5d618cb1e8, can_deadlock=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:4656
#8  0x00000000009153c6 in get_all_tables (thd=0x7f5d50000d28, tables=0x7f5d50015d68, cond=0x0) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:5294
#9  0x0000000000921ccc in get_schema_tables_result (join=0x7f5d500181c0, executed_place=PROCESSED_BY_JOIN_EXEC) at /home/midenok/src/mariadb/10.4/src/sql/sql_show.cc:8913
#10 0x00000000008c64d3 in JOIN::exec_inner (this=0x7f5d500181c0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4416
#11 0x00000000008c568e in JOIN::exec (this=0x7f5d500181c0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4241
#12 0x0000000000899638 in mysql_select (thd=0x7f5d50000d28, tables=0x7f5d50015d68, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2684619520, result=0x7f5d50018198, unit=0x7f5d50004c40, select_lex=0x7f5d50005438) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:4673
#13 0x0000000000898ce1 in handle_select (thd=0x7f5d50000d28, lex=0x7f5d50004b80, result=0x7f5d50018198, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.4/src/sql/sql_select.cc:410
#14 0x0000000000857e3a in execute_sqlcom_select (thd=0x7f5d50000d28, all_tables=0x7f5d50015d68) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6359
#15 0x000000000084d4bd in mysql_execute_command (thd=0x7f5d50000d28) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:3898
#16 0x0000000000846330 in mysql_parse (thd=0x7f5d50000d28, rawbuf=0x7f5d50014080 "show table status", length=17, parser_state=0x7f5d618cf5e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7900

2. instance added 3 times (for each partition)

#0  maria_clone_internal (share=0x7f5d500739c8, mode=2, data_file=37, internal_table=0) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:219
#1  0x000000000140a1f7 in maria_open (name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, open_flags=1106) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_open.c:1054
#2  0x00000000013b1640 in ha_maria::open (this=0x7f5d50036fe0, name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, test_if_locked=1042) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:1152
#3  0x0000000000be5745 in handler::ha_open (this=0x7f5d50036fe0, table_arg=0x7f5d500628f8, name=0x7f5d618c83a0 "./test/t1#P#pn", mode=2, test_if_locked=1042, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2749
#4  0x0000000001576605 in ha_partition::open_read_partitions (this=0x7f5d5004af20, name_buff=0x7f5d618c83a0 "./test/t1#P#pn", name_buff_size=513) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:8509
#5  0x0000000001575d45 in ha_partition::open (this=0x7f5d5004af20, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:3591
#6  0x0000000000be5745 in handler::ha_open (this=0x7f5d5004af20, table_arg=0x7f5d500628f8, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2749
#7  0x00000000009a8523 in open_table_from_share (thd=0x7f5d50000d28, share=0x7f5d5003d650, alias=0x7f5d5002e148, db_stat=33, prgflag=8, ha_open_flags=18, outparam=0x7f5d500628f8, is_create_table=false, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:3949
#8  0x000000000078d374 in open_table (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:2082

3. instance removed 2 times (except for "./test/t1#P#pn")

#0  maria_close (info=0x7f5d5006e8c8) at /home/midenok/src/mariadb/10.4/src/storage/maria/ma_close.c:28
#1  0x00000000013b1c72 in ha_maria::close (this=0x7f5d50036860) at /home/midenok/src/mariadb/10.4/src/storage/maria/ha_maria.cc:1236
#2  0x0000000000be62f7 in handler::ha_close (this=0x7f5d50036860) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2815
#3  0x0000000001576227 in ha_partition::open (this=0x7f5d5004af20, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18) at /home/midenok/src/mariadb/10.4/src/sql/ha_partition.cc:3664
#4  0x0000000000be5745 in handler::ha_open (this=0x7f5d5004af20, table_arg=0x7f5d500628f8, name=0x7f5d5003dbd8 "./test/t1", mode=2, test_if_locked=18, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/handler.cc:2749
#5  0x00000000009a8523 in open_table_from_share (thd=0x7f5d50000d28, share=0x7f5d5003d650, alias=0x7f5d5002e148, db_stat=33, prgflag=8, ha_open_flags=18, outparam=0x7f5d500628f8, is_create_table=false, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:3949
#6  0x000000000078d374 in open_table (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:2082

Divergence is ha_partition::open() (3591 vs 3664)

4. share released

#0  0x0000000000aeda0d in tdc_release_share (share=0x7f5d5003d650) at /home/midenok/src/mariadb/10.4/src/sql/table_cache.cc:982
#1  0x000000000078da06 in open_table (thd=0x7f5d50000d28, table_list=0x7f5d5002e100, ot_ctx=0x7f5d618c90f8) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:2232

Cause

Wrong algorithm of closing partitions on error doesn't close last partition:

  file= &m_file[m_tot_parts - 1];
  while (file-- != m_file)
  {
    if (bitmap_is_set(&m_opened_partitions, (uint)(file - m_file)))
      (*file)->ha_close();
  }

Tests affected:

parts.partition_recover_myisam parts.partition_repair_myisam