Bug #38784 Mysql server crash if table is altered with partition changes.
Submitted: 13 Aug 2008 21:49 Modified: 20 Jan 2009 21:13
Reporter: Hema Sridharan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S2 (Serious)
Version:5.1+ OS:Windows
Assigned to: Mattias Jonsson CPU Architecture:Any

[13 Aug 2008 21:49] Hema Sridharan
Description:
1) I create database and table with partitioning.
2) I alter the table by adding new partitions.
3) Mysql server crashes whenever I try to add new partitions to the table. The crash occurs for Myisam, Innodb and Memory storage engines. This behavior is seen only in windows OS.

How to repeat:
CREATE DATABASE partitions;
USE partitions;
CREATE TABLE t1(n1 INT, a CHAR(20))
PARTITION BY LIST (n1)
(
   PARTITION p0 VALUES IN (1,3,5),
   PARTITION p1 VALUES IN (2,4,6)
);
INSERT INTO t1 VALUES(1,'a'),(6,'c'),(5,'j'),(2,'l');
ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES IN (10,20,30));

RESULT
======

=======================================================

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

main.part_bug1                 [ fail ]

mysqltest: At line 10: query 'ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES
IN (10,20,30))' failed: 2013: Lost connection to MySQL server during query

The crash generates the Stack dump every time:

080813 23:37:41 - mysqld got exception 0xc0000005 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=1048576
read_buffer_size=131072
max_used_connections=3
max_threads=151
thread_count=3
connection_count=3
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 59983 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x3a78b58
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
015361E9    mysqld.exe!write_log_dropped_partitions()[sql_partition.cc:5347]
015366BE    mysqld.exe!write_log_add_change_partition()[sql_partition.cc:5628]
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
5A5A5A5A
CCCC5A5A
CCCCCCCC
CCCCCCCC
CCCCCCCC
CCCCCCCC
CCCCCCCC
CCCCCCCC
CCCCCCCC
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 03A84AF0=ALTER TABLE `range` ADD PARTITION (PARTITION p2 VALUES L
SS THAN MAXVALUE)
thd->thread_id=3
thd->killed=NOT_KILLED
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
[14 Aug 2008 3:19] Hema Sridharan
I got this crash from latest tree (pulled on 08/13/08).
I am also able to reproduce this crash when we alter table by Dropping partitions, Rebuild partitions and Coalesce operations for Hash and Key partitions.

Example:
1)
CREATE TABLE t2(
col1 INT,
col2 CHAR(20),
col3 DATE)
PARTITION BY HASH (YEAR(col3))
PARTITIONS 4;
ALTER TABLE t2 COALESCE PARTITION 2;

Result
======
main.part_bug                  [ fail ]

mysqltest: At line 33: query 'ALTER TABLE t2 COALESCE PARTITION 2' faile
d: 2013: Lost connection to MySQL server during query

2) ALTER TABLE t1 DROP PARTITION p1;
3) ALTER TABLE t1 REBUILD PARTITION p0, p1;

Example 2 and 3 also results in Server crash.
[10 Oct 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[10 Nov 2008 11:48] Mattias Jonsson
I got some pointers from Ingo:

Probably only with debug build on windows.
The problem is the use of FN_LEN for buffers that are intended to take paths. FN_REFLEN would be appropriate there.
The problem is that build_table_filename disregards the buffer size argument because it uses unpack_dirname, which does not have a size argument and expects FN_REFLEN.
It seems that multiple write_log_*() functions are affected.
FN_LEN is for a file name (a single element of a file path).
FN_REFLEN is for a full path name.
[11 Nov 2008 18:19] Mattias Jonsson
This also affects 5.1, but is harder to repeat, since it seams to need EXTRA_DEBUG, which is not yet supported in the configure.js and CMakeList.txt files.

I will commit a patch which is against 5.1 and include the addition of EXTRA_DEBUG.

The problem was that some local path variables was too small, changing them from FN_LEN to FN_REFLEN worked.

The bug would probably affect 'release' build too, if one used very long file names or paths.
[12 Nov 2008 12:37] 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/58545

2706 Mattias Jonsson	2008-11-12
      Bug#38784: Mysql server crash if table is altered with partition changes.
      
      Occurred with EXTRA_DEBUG on windows.
      
      Problem was insufficient length of a local variable that stored path names.
      
      Solution was to use the correct length.
[12 Nov 2008 14:35] Mattias Jonsson
Mikael approved it.
[12 Nov 2008 15:06] Ingo Strüwing
Approved.
[8 Dec 2008 15:19] Mattias Jonsson
Pushed into mysql-5.1-bugteam and mysql-6.0-bugteam
[15 Jan 2009 6:41] Bugs System
Pushed into 5.1.31 (revid:joro@sun.com-20090115053147-tx1oapthnzgvs1ro) (version source revid:azundris@mysql.com-20081230114838-cn52tu180wcrvh0h) (merge vers: 5.1.31) (pib:6)
[15 Jan 2009 16:30] Jon Stephens
Documented in the 5.1.31 changelog as follows:

        ALTER TABLE ... ADD PARTITION and ALTER TABLE ... DROP PARTITION
        could cause the MySQL server to crash. This was only known to
        occur on Windows platforms where MySQL had been built with the
        EXTRA_DEBUG option.

Set bug status back to PQ pending merge to 6.0 tree.
[15 Jan 2009 18:30] Jon Stephens
Status should have been set to NDI.
[15 Jan 2009 18:50] Mattias Jonsson
for Doc:

Also note that EXTRA_DEBUG was not available on 5.1 until this fix, so it only affected 6.0! (i.e. with this fix it was made available on 5.1 AND fixed, so in reality the bug never affected 5.1).
[19 Jan 2009 11:26] Bugs System
Pushed into 5.1.31-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090119095303-uwwvxiibtr38djii) (version source revid:tomas.ulin@sun.com-20090115073240-1wanl85vlvw2she1) (merge vers: 5.1.31-ndb-6.2.17) (pib:6)
[19 Jan 2009 13:04] Bugs System
Pushed into 5.1.31-ndb-6.3.21 (revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (version source revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (merge vers: 5.1.31-ndb-6.3.21) (pib:6)
[19 Jan 2009 13:51] Jon Stephens
Commented out 5.1 changelog entry per developer comment.

Set status to NDI pending merge to 6.0 (at which time I'll un-comment and re-tag the changelog entry written originally for 5.1).
[19 Jan 2009 16:10] Bugs System
Pushed into 5.1.31-ndb-6.4.1 (revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (version source revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (merge vers: 5.1.31-ndb-6.4.1) (pib:6)
[19 Jan 2009 17:03] Jon Stephens
Set back to NDI pending merge to 6.0.
[20 Jan 2009 18:56] Bugs System
Pushed into 6.0.10-alpha (revid:joro@sun.com-20090119171328-2hemf2ndc1dxl0et) (version source revid:azundris@mysql.com-20081230114916-c290n83z25wkt6e4) (merge vers: 6.0.9-alpha) (pib:6)
[20 Jan 2009 21:13] Jon Stephens
Fix noted in 6.0.10 changelog; closed.