Skip to content

Commit

Permalink
MDEV-22283 Server crashes in key_copy or unexpected error 156
Browse files Browse the repository at this point in the history
(The table already existed in the storage engine)

Wrong algorithm of closing partitions on error doesn't close last
partition.
  • Loading branch information
midenok committed May 29, 2020
1 parent d74e3a5 commit 4783494
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
23 changes: 20 additions & 3 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,23 @@ pk f
update t1 set f=pk;
delete from t1;
drop table t1;
# Test cleanup
drop database test;
create database test;
#
# MDEV-22283 Server crashes in key_copy or unexpected error 156: The table already existed in the storage engine
#
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);
Warnings:
Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
t1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Got error 174 "Fatal error during initialization of handler" from storage engine Aria NULL NULL
Warnings:
Warning 1030 Got error 174 "Fatal error during initialization of handler" from storage engine Aria
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);
drop table t1;
24 changes: 20 additions & 4 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ update t1 left join t2 on a > b set b= 2 order by b;
# cleanup
drop table t1, t2;

--source suite/versioning/common_finish.inc
--echo #
--echo # MDEV-17091 Assertion `old_part_id == m_last_part' failed in
--echo # ha_partition::update_row or `part_id == m_last_part' in
Expand All @@ -596,6 +595,23 @@ update t1 set f=pk;
delete from t1;
drop table t1;

--echo # Test cleanup
drop database test;
create database test;
--echo #
--echo # MDEV-22283 Server crashes in key_copy or unexpected error 156: The table already existed in the storage engine
--echo #
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;

--source suite/versioning/common_finish.inc
10 changes: 6 additions & 4 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3657,11 +3657,13 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)

err_handler:
DEBUG_SYNC(ha_thd(), "partition_open_error");
file= &m_file[m_tot_parts - 1];
while (file-- != m_file)
DBUG_ASSERT(m_tot_parts > 0);
for (uint i= m_tot_parts - 1; ; --i)
{
if (bitmap_is_set(&m_opened_partitions, (uint)(file - m_file)))
(*file)->ha_close();
if (bitmap_is_set(&m_opened_partitions, i))
m_file[i]->ha_close();
if (!i)
break;
}
err_alloc:
free_partition_bitmaps();
Expand Down

0 comments on commit 4783494

Please sign in to comment.