[MDEV-27600] partition_debug fails with warnings "Table is open on rename new table" Created: 2022-01-24  Updated: 2023-11-23  Resolved: 2022-04-01

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.7.1
Fix Version/s: 10.7.4, 10.8.3

Type: Bug Priority: Major
Reporter: Michael Widenius Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None
Environment:

Debug build, -DEXTRA_DEBUG



 Description   

parts.partition_debug fails with 2 warnings "Table: ./test/t1#P#p2 is open on rename new table2"

This happens only in 10.7 (I could not repeat it with 10.6) when compiled with DBUG
I can repeat it to 100% on my desktop.

parts.partition_debug [ fail ] Found warnings/errors in server log file!
Test ended at 2022-01-24 15:59:58
line
Warning: Table: ./test/t1#P#p2 is open on rename new table2
Warning: Table: ./test/t1#P#p2 is open on rename new table2

A shorter test case, just for debugging:
(The normal test case, parts.partition_debug only needs to be extended with this MDEV number). Note that it is the new code for CONVERT PARTITION that is generating the issue.

As a separate issue, I noticed that the code does try to rename files that does not exists:
error: error: 7 message: 'Error on rename of './test/tp2.MYD' to './test/t1#P#p2.MYD' (Errcode: 2 "No such file or directory")
That code could probably be cleaned up so that we don't generate errors/warnings that are not needed (for example by testing if the file exists or not before doing a rename)

# including crashing tests.
 
--source include/have_debug.inc
--source include/have_partition.inc
# Don't test this under valgrind, memory leaks will occur
--source include/not_valgrind.inc
# Crash tests don't work with embedded
--source include/not_embedded.inc
 
# Make sure system tables are not open, as the test will kill the server
# and it will cause corruption errors in the log
FLUSH TABLES;
 
--echo #
--echo # MDEV-22166 CONVERT PARTITION: move out partition into a table
--echo #
let $create_statement= create or replace table t1 (x int primary key)
  partition by range(x) (
    partition p1 values less than (10),
    partition p2 values less than (20),
    partition p3 values less than (30),
    partition p4 values less than (40),
    partition p5 values less than (50),
    partition pn values less than maxvalue);
 
let $insert_statement= insert into t1 values (2), (12), (22), (32), (42), (52);
let $fail_statement= alter table t1 convert partition p2 to table tp2;
 
set @save_dbug=@@debug_dbug;
set session debug_dbug="+d,fail_convert_partition_5";
--source suite/parts/inc/partition_fail.inc
set session debug_dbug=@save_dbug;
set session debug_dbug="+d,fail_convert_partition_11";
--echo # Already finished DDL logging, so tp2 now exists:
--source suite/parts/inc/partition_fail.inc
set session debug_dbug=@save_dbug;
show create table tp2;
select * from tp2;
drop table tp2;



 Comments   
Comment by Michael Widenius [ 2022-01-24 ]

Comment about this from Marko @ slack:
b7bba721eee42af892178a747fa72a6fc2975c94 and MDEV-22166 could be it. I have nothing to do with it; @midenok has. I see that there have been some follow-up fixes to 10.7 related to that.

Comment by Michael Widenius [ 2022-03-04 ]

Some suggestions of how to fix this:

The error happens because in ddl_log_revert (), which does a rename, the table is still open. This is not allowed and could cause crashes and lost data for some engines.
The reason for the error is this code in sql_partition.cc:
if (mysql_write_frm(lpt, WFRM_WRITE_CONVERTED_TO) ||
ERROR_INJECT("convert_partition_1") ||
write_log_drop_shadow_frm(lpt) ||
ERROR_INJECT("convert_partition_2") ||
mysql_write_frm(lpt, WFRM_WRITE_SHADOW) ||
ERROR_INJECT("convert_partition_3") ||
wait_while_table_is_used(thd, table, HA_EXTRA_NOT_USED) ||
ERROR_INJECT("convert_partition_4") ||
write_log_convert_partition(lpt) ||
ERROR_INJECT("convert_partition_5") ||
alter_close_table(lpt) ||

If we fail at convert_partition_5, then the table will not be closed and we have a request in the
ddl log to do the rename.
Suggested fixes (One of the following):

  • Don't have an error injection after write_log_convert_partition().
  • Set a variable before write_log_convert_partition(lpt) that is cleared after alter_close_table(). In the error handler, call alter_close_table() if the variable is set.
Generated at Thu Feb 08 09:54:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.