Bug #47029 | Server crash when reorganizing two partitions into one with same name as the 2nd | ||
---|---|---|---|
Submitted: | 31 Aug 2009 19:42 | Modified: | 2 Dec 2009 7:35 |
Reporter: | Keyur Joshi | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Partitions | Severity: | S1 (Critical) |
Version: | 5.1.37-1/5.4.4 | OS: | Linux (32-bit Ubuntu 9.04 (kernel: 2.6.28-11-generic)) |
Assigned to: | Assigned Account | CPU Architecture: | Any |
[31 Aug 2009 19:42]
Keyur Joshi
[31 Aug 2009 20:03]
MySQL Verification Team
iguel@luz:~/dbs/mysql-next$ bin/mysql -uroot test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.4.4-alpha-debug Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create table TestTable ( -> id smallint(6) not null default 0, -> timestamp datetime not null, -> primary key (id, timestamp) -> ) engine = InnoDB -> partition by range (to_days(timestamp)) -> subpartition by hash(id) -> subpartitions 2 -> ( -> partition p1 values less than (to_days('2009-01-01')), -> partition p2 values less than (to_days('2009-02-01')), -> partition p3 values less than (to_days('2009-03-01')), -> partition max values less than maxvalue -> ); Query OK, 0 rows affected (0.14 sec) mysql> mysql> alter table TestTable reorganize partition p2,p3 into ( partition p3 values less than -> (to_days('2009-03-01'))); ERROR 2013 (HY000): Lost connection to MySQL server during query mysql>
[31 Aug 2009 20:15]
MySQL Verification Team
backtrace
Attachment: 47029_backtrace.txt (text/plain), 4.78 KiB.
[31 Aug 2009 20:16]
MySQL Verification Team
Thank you for the bug report.
[4 Sep 2009 14:14]
Mikael Ronström
I found that there are two problems: 1) A deleted table which have been removed from the internal InnoDB table SYS_TABLES still exists when the table is to be renamed. 2) The rename_table function returns Duplicate key error which later gets a crash when MySQL calls print_error on the handler and this in turn calls get_dup_key which soon enough crashes MySQL since InnoDB assumes rightly that the handler is open when this is called. So should use a different error code from rename_table.
[4 Sep 2009 20:56]
Jimmy Yang
The problem is due to the counter "j" in ha_partition::rename_partitions() is not reset in a double loop, causing code exits earlier, and does not delete all the temp tables it supposes to. Thus later a dup insert of the same (name) temp table into innodb system table trigger the whole problem: ha_partition::rename_partitions() { 677 unint j = 0; 702 do 703 { <================= j did not get reset when re-enter 708 do{ ...... 717 file->ha_delete_table(norm_name_buff) ...... 723 } while (++j < no_subparts); ..... 739 } while (++i < temp_partitions); ..... } (gdb) print temp_partitions $4 = 2 (gdb) print no_subparts $5 = 2 In this case, ha_delete_table() got called 3 times intead of 4 times. 3 Temp Table got deleted: /test/TestTable#P#p2#SP#p2sp0, /test/TestTable#P#p2#SP#p2sp1, /test/TestTable#P#p3#SP#p3sp0 However /test/TestTable#P#p3#SP#p3sp1 did not get deleted. It is later causing dup key error in innodb, row/row0ins.c:1847 (row_ins_duplicate_error_in_clust). The error: InnoDB: 2) table `test1`.090831 15:36:12 [ERROR] Invalid (old?) table or database name 'TestTable#P#p3#SP#p3sp1' `#mysql50#TestTable#P#p3#SP#p3sp1` exists in the InnoDB internal data call stack shows it comes from a table rename: #0 row_ins_duplicate_error_in_clust (cursor=0x45c27e90, entry=0x2aaaaada54b8, thr=0x2aaaaada74f0, mtr=0x45c279c0) at row/row0ins.c:1847 #1 0x000000000089f3fb in row_ins_index_entry_low (mode=2, index=0x2aaaaad814b8, entry=0x2aaaaada54b8, ext_vec=0x2aaaaada9df8, n_ext_vec=0, thr=0x2aaaaada74f0) at row/row0ins.c:2039 ... #12 0x000000000083f1df in ha_innobase::rename_table (this=0x174ccc70, from=0x45c298c0 "./test/TestTable#P#p3#SP#p3sp1#TMP#", to=0x45c296c0 "./test/TestTable#P#p3#SP#p3sp1") Fix will be reset the counter j in the double loop: 702 do 703 { + j = 0; <===================== 708 do{ 717 file->ha_delete_table(norm_name_buff) 723 } while (++j < no_subparts); 739 } while (++i < temp_partitions); Thanks Jimmy
[7 Sep 2009 8:31]
Mikael Ronström
The bug was found to have 2 bugs in it. One in the MySQL partitioning code and one in the InnoDB error handling code. Reassigned the bug to myself for fixing the MySQL part of the bug. Fix was found by Jimmy Yang and was a simple matter of not initialising the j variable in the second loop of dropping partitions that have been reorganised.
[7 Sep 2009 8:33]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/82556 3105 Mikael Ronstrom 2009-09-07 Fix to ensure that all subpartitions gets deleted before renaming starts, BUG#47029 modified: mysql-test/r/partition_innodb.result mysql-test/t/partition_innodb.test sql/ha_partition.cc
[7 Sep 2009 8:41]
Mattias Jonsson
Bug#45808 is waiting on this bug to analyze if it is the same problem.
[14 Sep 2009 16:03]
Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (version source revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (merge vers: 5.4.4-alpha) (pib:11)
[16 Sep 2009 9:05]
Jon Stephens
Hi Mikael, You say there are actually 2 issues in this bug report. However, it appears that only 1 of them is fixed. Should I go ahead and document/close this bug report? Is there a separate bug report for the InnoDB problem, or is that (also) no longer an issue due to this fix? Thanks!
[16 Sep 2009 13:15]
Mattias Jonsson
The fix Mikael did and is pushed within the scope of this bug fixed the crash. The other issue Mikael found will be handled in bug#45961. So please go ahead and document/close this bug.
[16 Sep 2009 15:03]
Jon Stephens
Documented bugfix in the 5.4.4 changelog as follows: When reorganizing partitions, not all affected subpartitions were removed prior to renaming. One way in which the issue was visible was that attempting to reorganize two partitions into a single partition having the same name as one of the originasl partitions could lead to a crash of the server. Set Status = Documenting; waiting for 5.1 push.
[18 Sep 2009 8:22]
Mattias Jonsson
Mikael pushed this to 51-bugteam 2009-09-07 12:23.
[18 Sep 2009 9:57]
Jon Stephens
Set back to NDI, waiting for 5.1 version info to close.
[2 Oct 2009 1:43]
Paul DuBois
Moved 5.4 changelog entry from 5.4.4 to 5.4.3.
[6 Oct 2009 8:59]
Bugs System
Pushed into 5.1.40 (revid:joro@sun.com-20091006073316-lea2cpijh9r6on7c) (version source revid:mikael@mysql.com-20090907083754-w12rtyvcwy6j3k1o) (merge vers: 5.1.39) (pib:11)
[6 Oct 2009 9:39]
Jon Stephens
Fix also documented in the 5.1.40 changelog. Closed.
[18 Dec 2009 10:30]
Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:46]
Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 11:01]
Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:15]
Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)