Commit daf0e6b7 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#53676: Unexpected errors and possible table

           corruption on ADD PARTITION and LOCK TABLE
Bug#53770: Server crash at handler.cc:2076 on
           LOAD DATA after timed out COALESCE PARTITION

5.5 fix for:
Bug#51042: REORGANIZE PARTITION can leave table in an
           inconsistent state in case of crash
Needs to be back-ported to 5.1

5.5 fix for:
Bug#50418: DROP PARTITION does not interact with
           transactions

Main problem was non-persistent operations done
before meta-data lock was taken (53770+53676).
And 53676 needed to keep the table/partitions opened and locked
while copying the data to the new partitions.

Also added thorough tests to spot some additional bugs
in the ddl_log code, which could result in bad state
between the .frm and partitions.

Collapsed patch, includes all fixes required from the reviewers.

mysql-test/r/partition_innodb.result:
  updated result with new test
mysql-test/suite/parts/inc/partition_crash.inc:
  crash test include file
mysql-test/suite/parts/inc/partition_crash_add.inc:
  test all states in fast_alter_partition_table
  ADD PARTITION branch
mysql-test/suite/parts/inc/partition_crash_change.inc:
  test all states in fast_alter_partition_table
  CHANGE PARTITION branch
mysql-test/suite/parts/inc/partition_crash_drop.inc:
  test all states in fast_alter_partition_table
  DROP PARTITION branch
mysql-test/suite/parts/inc/partition_fail.inc:
  recovery test including injecting errors
mysql-test/suite/parts/inc/partition_fail_add.inc:
  test all states in fast_alter_partition_table
  ADD PARTITION branch
mysql-test/suite/parts/inc/partition_fail_change.inc:
  test all states in fast_alter_partition_table
  CHANGE PARTITION branch
mysql-test/suite/parts/inc/partition_fail_drop.inc:
  test all states in fast_alter_partition_table
  DROP PARTITION branch
mysql-test/suite/parts/inc/partition_mgm_crash.inc:
  include file that runs all crash and failure injection tests.
mysql-test/suite/parts/r/partition_debug_innodb.result:
  new test result file
mysql-test/suite/parts/r/partition_debug_myisam.result:
  new test result file
mysql-test/suite/parts/r/partition_special_innodb.result:
  updated result
mysql-test/suite/parts/r/partition_special_myisam.result:
  updated result
mysql-test/suite/parts/t/partition_debug_innodb-master.opt:
  opt file for using with crashing tests of partitioned innodb
mysql-test/suite/parts/t/partition_debug_innodb.test:
  partitioned innodb test that require debug builds
mysql-test/suite/parts/t/partition_debug_myisam-master.opt:
  opt file for using with crashing tests of partitioned myisam
mysql-test/suite/parts/t/partition_debug_myisam.test:
  partitioned myisam test that require debug builds
mysql-test/suite/parts/t/partition_special_innodb-master.opt:
  added innodb-file-per-table to easier verify partition status on disk
mysql-test/suite/parts/t/partition_special_innodb.test:
  added test case
mysql-test/suite/parts/t/partition_special_myisam.test:
  added test case
mysql-test/t/partition_innodb.test:
  added test case
sql/sql_base.cc:
  Moved alter_close_tables to sql_partition.cc
sql/sql_base.h:
  removed some non existing and duplicated functions.
sql/sql_partition.cc:
  fast_alter_partition_table:
  Spletted abort_and_upgrad_lock_and_close_table
  to its parts (wait_while_table_is_used and
  alter_close_tables) and always have
  wait_while_table_is_used before any persistent
  operations (including logs, which will be executed
  on failure) and alter_close_tables after
  create/read/write operations and before
  drop operations.
  
  moved alter_close_tables here from sql_base.cc
  
  Added error injections for better test coverage.
  
  write_log_final_change_partition:
  fixed a log_entry linking bug (delete_frm was not
  linked to change/drop partition)
  and drop partition must be executed before
  change partition (change partition can rename a
  partition to an old name, like REORG p1 INTO (p1,p2).
  
  write_log_add_change_partition:
  need to use drop_frm first, and relinking that entry
  and reusing its execute entry.
sql/sql_table.cc:
  added initialization of next_active_log_entry.
sql/table.h:
  removed a duplicate declaration.
parent 69091c49
drop table if exists t1, t2;
#
# Bug#50418: DROP PARTITION does not interact with transactions
#
CREATE TABLE t1 (
id INT AUTO_INCREMENT NOT NULL,
name CHAR(50) NOT NULL,
myDate DATE NOT NULL,
PRIMARY KEY (id, myDate),
INDEX idx_date (myDate)
) ENGINE=InnoDB
PARTITION BY RANGE ( TO_DAYS(myDate) ) (
PARTITION p0 VALUES LESS THAN (734028),
PARTITION p1 VALUES LESS THAN (734029),
PARTITION p2 VALUES LESS THAN (734030),
PARTITION p3 VALUES LESS THAN MAXVALUE
) ;
INSERT INTO t1 VALUES
(NULL, 'Lachlan', '2009-09-13'),
(NULL, 'Clint', '2009-09-13'),
(NULL, 'John', '2009-09-14'),
(NULL, 'Dave', '2009-09-14'),
(NULL, 'Jeremy', '2009-09-15'),
(NULL, 'Scott', '2009-09-15'),
(NULL, 'Jeff', '2009-09-16'),
(NULL, 'Joe', '2009-09-16');
SET AUTOCOMMIT=0;
SELECT * FROM t1 FOR UPDATE;
id name myDate
1 Lachlan 2009-09-13
2 Clint 2009-09-13
3 John 2009-09-14
4 Dave 2009-09-14
5 Jeremy 2009-09-15
6 Scott 2009-09-15
7 Jeff 2009-09-16
8 Joe 2009-09-16
UPDATE t1 SET name = 'Mattias' WHERE id = 7;
SELECT * FROM t1 WHERE id = 7;
id name myDate
7 Mattias 2009-09-16
# Connection con1
SET lock_wait_timeout = 1;
# After the patch it will wait and fail on timeout.
ALTER TABLE t1 DROP PARTITION p3;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SHOW WARNINGS;
Level Code Message
Error 1205 Lock wait timeout exceeded; try restarting transaction
# Connection default
SELECT * FROM t1;
id name myDate
1 Lachlan 2009-09-13
2 Clint 2009-09-13
3 John 2009-09-14
4 Dave 2009-09-14
5 Jeremy 2009-09-15
6 Scott 2009-09-15
7 Mattias 2009-09-16
8 Joe 2009-09-16
# No changes.
COMMIT;
DROP TABLE t1;
#
# Bug#51830: Incorrect partition pruning on range partition (regression)
#
CREATE TABLE t1 (a INT NOT NULL)
......
# Include file to decrease test code duplication
--eval $create_statement
--eval $insert_statement
--echo # State before crash
--replace_result #p# #P#
--list_files $DATADIR/test
SHOW CREATE TABLE t1;
--sorted_result
SELECT * FROM t1;
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--disable_reconnect
# CR_SERVER_LOST
--error 2013
--eval $crash_statement
--echo # State after crash (before recovery)
--replace_regex /sqlx.*\./sqlx-nnnn_nnnn./ /#p#/#P#/
--list_files $DATADIR/test
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--enable_reconnect
--source include/wait_until_connected_again.inc
--echo # State after crash recovery
--replace_result #p# #P#
--list_files $DATADIR/test
SHOW CREATE TABLE t1;
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
# To be used with partition mgm commands like
# ALTER TABLE t1 ADD PARTITION (LIST/RANGE PARTITIONING).
--echo # Crash testing ADD PARTITION
SET SESSION debug="+d,crash_add_partition_1";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_1";
SET SESSION debug="+d,crash_add_partition_2";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_2";
SET SESSION debug="+d,crash_add_partition_3";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_3";
SET SESSION debug="+d,crash_add_partition_4";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_4";
SET SESSION debug="+d,crash_add_partition_5";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_5";
SET SESSION debug="+d,crash_add_partition_6";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_6";
SET SESSION debug="+d,crash_add_partition_7";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_7";
SET SESSION debug="+d,crash_add_partition_8";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_8";
SET SESSION debug="+d,crash_add_partition_9";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_9";
SET SESSION debug="+d,crash_add_partition_10";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_add_partition_10";
# To be used with partition mgm commands like
# ALTER TABLE t1 COALESCE/REBUILD/REORGANIZE PARTITION.
--echo # Test change partition (REORGANIZE/REBUILD/COALESCE
--echo # or ADD HASH PARTITION).
SET SESSION debug="+d,crash_change_partition_1";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_1";
SET SESSION debug="+d,crash_change_partition_2";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_2";
SET SESSION debug="+d,crash_change_partition_3";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_3";
SET SESSION debug="+d,crash_change_partition_4";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_4";
SET SESSION debug="+d,crash_change_partition_5";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_5";
SET SESSION debug="+d,crash_change_partition_6";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_6";
SET SESSION debug="+d,crash_change_partition_7";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_7";
SET SESSION debug="+d,crash_change_partition_8";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_8";
SET SESSION debug="+d,crash_change_partition_9";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_9";
SET SESSION debug="+d,crash_change_partition_10";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_10";
SET SESSION debug="+d,crash_change_partition_11";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_11";
SET SESSION debug="+d,crash_change_partition_12";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_change_partition_12";
# To be used with partition mgm commands like
# ALTER TABLE t1 DROP PARTITION.
--echo # Test DROP PARTITION
SET SESSION debug="+d,crash_drop_partition_1";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_1";
SET SESSION debug="+d,crash_drop_partition_2";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_2";
SET SESSION debug="+d,crash_drop_partition_3";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_3";
SET SESSION debug="+d,crash_drop_partition_4";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_4";
SET SESSION debug="+d,crash_drop_partition_5";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_5";
SET SESSION debug="+d,crash_drop_partition_6";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_6";
SET SESSION debug="+d,crash_drop_partition_7";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_7";
SET SESSION debug="+d,crash_drop_partition_8";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_8";
SET SESSION debug="+d,crash_drop_partition_9";
--source suite/parts/inc/partition_crash.inc
SET SESSION debug="-d,crash_drop_partition_9";
# Include file to decrease test code duplication
--eval $create_statement
--eval $insert_statement
--echo # State before failure
--list_files $DATADIR/test
SHOW CREATE TABLE t1;
--sorted_result
SELECT * FROM t1;
--disable_abort_on_error
--eval $fail_statement
--enable_abort_on_error
--echo # State after failure
--list_files $DATADIR/test
SHOW CREATE TABLE t1;
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
# To be used with partition mgm commands like
# ALTER TABLE t1 ADD PARTITION (LIST/RANGE PARTITIONING).
--echo # Error recovery testing ADD PARTITION
SET SESSION debug="+d,fail_add_partition_1";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_1";
SET SESSION debug="+d,fail_add_partition_2";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_2";
SET SESSION debug="+d,fail_add_partition_3";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_3";
SET SESSION debug="+d,fail_add_partition_4";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_4";
SET SESSION debug="+d,fail_add_partition_5";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_5";
SET SESSION debug="+d,fail_add_partition_6";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_6";
SET SESSION debug="+d,fail_add_partition_7";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_7";
SET SESSION debug="+d,fail_add_partition_8";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_8";
SET SESSION debug="+d,fail_add_partition_9";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_9";
SET SESSION debug="+d,fail_add_partition_10";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_add_partition_10";
# To be used with partition mgm commands like
# ALTER TABLE t1 COALESCE/REBUILD/REORGANIZE PARTITION.
--echo # Error recovery change partition (REORGANIZE/REBUILD/COALESCE
--echo # or ADD HASH PARTITION).
SET SESSION debug="+d,fail_change_partition_1";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_1";
SET SESSION debug="+d,fail_change_partition_2";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_2";
SET SESSION debug="+d,fail_change_partition_3";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_3";
SET SESSION debug="+d,fail_change_partition_4";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_4";
SET SESSION debug="+d,fail_change_partition_5";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_5";
SET SESSION debug="+d,fail_change_partition_6";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_6";
SET SESSION debug="+d,fail_change_partition_7";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_7";
SET SESSION debug="+d,fail_change_partition_8";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_8";
SET SESSION debug="+d,fail_change_partition_9";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_9";
SET SESSION debug="+d,fail_change_partition_10";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_10";
SET SESSION debug="+d,fail_change_partition_11";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_11";
SET SESSION debug="+d,fail_change_partition_12";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_change_partition_12";
# To be used with partition mgm commands like
# ALTER TABLE t1 DROP PARTITION.
--echo # Error recovery DROP PARTITION
SET SESSION debug="+d,fail_drop_partition_1";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_1";
SET SESSION debug="+d,fail_drop_partition_2";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_2";
SET SESSION debug="+d,fail_drop_partition_3";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_3";
SET SESSION debug="+d,fail_drop_partition_4";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_4";
SET SESSION debug="+d,fail_drop_partition_5";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_5";
SET SESSION debug="+d,fail_drop_partition_6";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_6";
SET SESSION debug="+d,fail_drop_partition_7";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_7";
SET SESSION debug="+d,fail_drop_partition_8";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_8";
SET SESSION debug="+d,fail_drop_partition_9";
--source suite/parts/inc/partition_fail.inc
SET SESSION debug="-d,fail_drop_partition_9";
# collection of tests which crashes the server and checks recovery.
# also using error injection to test recovery of failures.
# uses $DATADIR and $engine
--echo #
--echo # Bug#53676: Unexpected errors and possible table corruption on
--echo # ADD PARTITION and LOCK TABLE
--echo # Bug#53770: Server crash at handler.cc:2076 on LOAD DATA
--echo # after timed out COALESCE PARTITION
--echo # Extended crash recovery testing of fast_alter_partition_table.
call mtr.add_suppression("Attempting backtrace. You can use the following information to find out");
let $create_statement= CREATE TABLE t1 (a INT, b VARCHAR(64))
ENGINE = $engine
PARTITION BY LIST (a)
(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
let $insert_statement= INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
let $crash_statement= ALTER TABLE t1 ADD PARTITION
(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
--source suite/parts/inc/partition_crash_add.inc
let $fail_statement= $crash_statement;
--source suite/parts/inc/partition_fail_add.inc
let $crash_statement= ALTER TABLE t1 DROP PARTITION p10;
--source suite/parts/inc/partition_crash_drop.inc
let $fail_statement= $crash_statement;
--source suite/parts/inc/partition_fail_drop.inc
let $crash_statement= ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
--source suite/parts/inc/partition_crash_change.inc
let $fail_statement= $crash_statement;
--source suite/parts/inc/partition_fail_change.inc
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -216,3 +216,71 @@ SET SESSION lock_wait_timeout= 1;
ALTER TABLE t1 AUTO_INCREMENT = 10;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
DROP TABLE t1;
#
# Bug#53676: Unexpected errors and possible table corruption on
# ADD PARTITION and LOCK TABLE
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
SET lock_wait_timeout = 2;
#Connection 1 locks the table
LOCK TABLE t1 READ;
# Connection 2 tries to add partitions:
# First attempt: lock wait timeout (as expected)
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Second attempt: says that partition already exists
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Connection 1 unlocks the table and locks it again:
UNLOCK TABLES;
LOCK TABLE t1 READ;
# Connection 2 tries again to add partitions:
# Third attempt: says that the table does not exist
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Check table returns the same
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check Error Lock wait timeout exceeded; try restarting transaction
test.t1 check error Corrupt
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t2 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
SET lock_wait_timeout = 2;
LOCK TABLE t2 READ;
ALTER TABLE t2 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
ALTER TABLE t2 ADD PARTITION PARTITIONS 2;
UNLOCK TABLES;
CHECK TABLE t2;
Table Op Msg_type Msg_text
test.t2 check status OK
SELECT * FROM t2;
i f
DROP TABLE t2;
CREATE TABLE t3 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
SET lock_wait_timeout = 2;
# Connection 1 locks the table
LOCK TABLE t3 READ;
# Connection 2 tries to add partitions (timeout):
ALTER TABLE t3 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SET lock_wait_timeout = 2;
# Connection 3 tries to add partitions (partition already exists):
ALTER TABLE t3 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Connection 4 tries to rename the table:
RENAME TABLE t3 TO t4;
# Connection 1 unlocks the table:
UNLOCK TABLES;
# Connection 4 gets error on rename:
# SHOW TABLES returns the table (not renamed):
SHOW TABLES;
Tables_in_test
t4
# Connection 5 attempts to read from the table (table does not exist):
SELECT * FROM t3;
ERROR 42S02: Table 'test.t3' doesn't exist
DROP TABLE t4;
......@@ -200,3 +200,22 @@ a b c d e f g h a1 b1 c1 d1 e1 f1 g1 h1 a2 b2 c2 d2 e2 f2 g2 h2 a3 b3 c3 d3 e3 f
1983-12-31 cdef srtbvsr w 45634 13452.56 3452346456 127 1983-12-31 cdef srtbvsr w 45634 13452.56 3452346456 127 1983-12-31 cdef srtbvsr w 45634 13452.56 3452346456 127 1983-12-31 cdef srtbvsr w 45634 13452.56 3452346456 127 liuugbzvdmrlti b itiortudirtfgtibm dfi
1975-01-01 abcde abcde m 1234 123.45 32412341234 113 1975-01-01 abcde abcde m 1234 123.45 32412341234 113 1975-01-01 abcde abcde m 1234 123.45 32412341234 113 1975-01-01 abcde abcde m 1234 123.45 32412341234 113 tbhth nrzh ztfghgfh fzh ftzhj fztjh
drop table t1;
#
# Bug#53770: Server crash at handler.cc:2076 on LOAD DATA
# after timed out COALESCE PARTITION
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = MyISAM PARTITION BY HASH(i) PARTITIONS 3;
# Connection 1 starts transaction and gets lock
START TRANSACTION;
SELECT * FROM t1;
i f
SET lock_wait_timeout = 2;
# Connection 2 tries to coalesce partitions (timeout):
ALTER TABLE t1 COALESCE PARTITION 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Connection 3 tries to load into the table:
LOAD DATA LOCAL INFILE '/tmp/load.in' INTO TABLE t1 (f);
# Connection 1 commits the transaction
COMMIT;
# Connection 3...
DROP TABLE t1;
--innodb-file-format-check --innodb-file-per-table=1 --skip-stack-trace --skip-core-file
# Partitioning test that require debug features
# including crashing tests.
--source include/have_debug.inc
--source include/have_innodb.inc
--source include/have_partition.inc
--source include/not_valgrind.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $DATADIR= `SELECT @@datadir;`
# Checking with #innodb what this is...
call mtr.add_suppression("InnoDB: Warning: allocated tablespace .*, old maximum was");
# If there is a crash or failure between the ddl_log is written and the
# operation is completed, mysql will try to drop a not yet created partition
call mtr.add_suppression("InnoDB: Error: table .* does not exist in the InnoDB internal");
call mtr.add_suppression("InnoDB: Warning: MySQL is trying to drop table ");
let $engine= 'InnoDB';
--echo # Test crash and failure recovery in fast_alter_partition_table.
--source suite/parts/inc/partition_mgm_crash.inc
# Partitioning test that require debug features
# including crashing tests.
--source include/have_debug.inc
--source include/have_partition.inc
--source include/not_valgrind.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $DATADIR= `SELECT @@datadir;`
let $engine= 'MyISAM';
--echo # Test crash and failure recovery in fast_alter_partition_table.
--source suite/parts/inc/partition_mgm_crash.inc
--innodb_lock_wait_timeout=2
--innodb_lock_wait_timeout=2 --innodb-file-per-table=1
......@@ -76,3 +76,132 @@ ALTER TABLE t1 AUTO_INCREMENT = 10;
--disconnect con1
--connection default
DROP TABLE t1;
--echo #
--echo # Bug#53676: Unexpected errors and possible table corruption on
--echo # ADD PARTITION and LOCK TABLE
--connect (con1,localhost,root,,)
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
--connect (con2,localhost,root,,)
SET lock_wait_timeout = 2;
--connection con1
--echo #Connection 1 locks the table
LOCK TABLE t1 READ;
--connection con2
--echo # Connection 2 tries to add partitions:
--echo # First attempt: lock wait timeout (as expected)
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--echo # Second attempt: says that partition already exists
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--connection con1
--echo # Connection 1 unlocks the table and locks it again:
UNLOCK TABLES;
--real_sleep 1
LOCK TABLE t1 READ;
--connection con2
--echo # Connection 2 tries again to add partitions:
--echo # Third attempt: says that the table does not exist
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--echo # Check table returns the same
CHECK TABLE t1;
--connection con1
UNLOCK TABLES;
--connection con2
DROP TABLE t1;
# End of Test1
# Test2
--connection con1
CREATE TABLE t2 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
--connection con2
SET lock_wait_timeout = 2;
--connection con1
LOCK TABLE t2 READ;
--connection con2
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t2 ADD PARTITION PARTITIONS 2;
send ALTER TABLE t2 ADD PARTITION PARTITIONS 2;
--connection con1
UNLOCK TABLES;
--connection con2
--reap
--connect (con3,localhost,root,,)
CHECK TABLE t2;
SELECT * FROM t2;
DROP TABLE t2;
# End of Test2
# Test #3
--connection con1
CREATE TABLE t3 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
--connection con2
SET lock_wait_timeout = 2;
--connection con1
--echo # Connection 1 locks the table
LOCK TABLE t3 READ;
--connection con2
--echo # Connection 2 tries to add partitions (timeout):
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t3 ADD PARTITION PARTITIONS 2;
--connection con3
SET lock_wait_timeout = 2;
--echo # Connection 3 tries to add partitions (partition already exists):
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t3 ADD PARTITION PARTITIONS 2;
--connect (con4,localhost,root,,)
--echo # Connection 4 tries to rename the table:
send RENAME TABLE t3 TO t4;
--connection con1
--real_sleep 1
--echo # Connection 1 unlocks the table:
UNLOCK TABLES;
--connection con4
--echo # Connection 4 gets error on rename:
--reap
--connect (con5,localhost,root,,)
--echo # SHOW TABLES returns the table (not renamed):
SHOW TABLES;
--echo # Connection 5 attempts to read from the table (table does not exist):
--error ER_NO_SUCH_TABLE
SELECT * FROM t3;
DROP TABLE t4;
--disconnect con5
--disconnect con4
--disconnect con3
--disconnect con2
--disconnect con1
--connection default
# End of Test #3
......@@ -43,3 +43,43 @@ let $engine= 'MyISAM';
--source suite/parts/inc/partition_key_8col.inc
--source suite/parts/inc/partition_key_16col.inc
--source suite/parts/inc/partition_key_32col.inc
--echo #
--echo # Bug#53770: Server crash at handler.cc:2076 on LOAD DATA
--echo # after timed out COALESCE PARTITION
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = MyISAM PARTITION BY HASH(i) PARTITIONS 3;
--echo # Connection 1 starts transaction and gets lock
START TRANSACTION;
SELECT * FROM t1;
--connect (con2,localhost,root,,)
SET lock_wait_timeout = 2;
--echo # Connection 2 tries to coalesce partitions (timeout):
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 COALESCE PARTITION 2;
--connect (con3,localhost,root,,)
perl;
open( LD, ">" . "/tmp/load.in" ) || die "Could not open file for writing " . $ENV{'MYSQLTEST_DATADIR'} . "/test/load.in";
print LD "1\n2\n3\n";
close( LD );
EOF
--echo # Connection 3 tries to load into the table:
send LOAD DATA LOCAL INFILE '/tmp/load.in' INTO TABLE t1 (f);
--connection default
--real_sleep 1
--echo # Connection 1 commits the transaction
COMMIT;
--connection con3
--echo # Connection 3...
--reap
DROP TABLE t1;
--disconnect con3
--disconnect con2
--connection default
......@@ -8,6 +8,50 @@ drop table if exists t1, t2;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--echo #
--echo # Bug#50418: DROP PARTITION does not interact with transactions
--echo #
CREATE TABLE t1 (
id INT AUTO_INCREMENT NOT NULL,
name CHAR(50) NOT NULL,
myDate DATE NOT NULL,
PRIMARY KEY (id, myDate),
INDEX idx_date (myDate)
) ENGINE=InnoDB
PARTITION BY RANGE ( TO_DAYS(myDate) ) (
PARTITION p0 VALUES LESS THAN (734028),
PARTITION p1 VALUES LESS THAN (734029),
PARTITION p2 VALUES LESS THAN (734030),
PARTITION p3 VALUES LESS THAN MAXVALUE
) ;
INSERT INTO t1 VALUES
(NULL, 'Lachlan', '2009-09-13'),
(NULL, 'Clint', '2009-09-13'),
(NULL, 'John', '2009-09-14'),
(NULL, 'Dave', '2009-09-14'),
(NULL, 'Jeremy', '2009-09-15'),
(NULL, 'Scott', '2009-09-15'),
(NULL, 'Jeff', '2009-09-16'),
(NULL, 'Joe', '2009-09-16');
SET AUTOCOMMIT=0;
SELECT * FROM t1 FOR UPDATE;
UPDATE t1 SET name = 'Mattias' WHERE id = 7;
SELECT * FROM t1 WHERE id = 7;
--connect (con1, localhost, root,,)
--echo # Connection con1
SET lock_wait_timeout = 1;
--echo # After the patch it will wait and fail on timeout.
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 DROP PARTITION p3;
SHOW WARNINGS;
--disconnect con1
--connection default
--echo # Connection default
SELECT * FROM t1;
--echo # No changes.
COMMIT;
DROP TABLE t1;
--echo #
--echo # Bug#51830: Incorrect partition pruning on range partition (regression)
--echo #
......
......@@ -8889,87 +8889,6 @@ bool is_equal(const LEX_STRING *a, const LEX_STRING *b)
}
/*
Unlock and close table before renaming and dropping partitions
SYNOPSIS
alter_close_tables()
lpt Struct carrying parameters
RETURN VALUES
0
*/
static int alter_close_tables(ALTER_PARTITION_PARAM_TYPE *lpt)
{
TABLE_SHARE *share= lpt->table->s;
THD *thd= lpt->thd;
TABLE *table;
DBUG_ENTER("alter_close_tables");
/*
We must keep LOCK_open while manipulating with thd->open_tables.
Another thread may be working on it.
*/
mysql_mutex_lock(&LOCK_open);
/*
We can safely remove locks for all tables with the same name:
later they will all be closed anyway in
alter_partition_lock_handling().
*/
for (table= thd->open_tables; table ; table= table->next)
{
if (!strcmp(table->s->table_name.str, share->table_name.str) &&
!strcmp(table->s->db.str, share->db.str))
{
mysql_lock_remove(thd, thd->lock, table);
table->file->close();
table->db_stat= 0; // Mark file closed
/*
Ensure that we won't end up with a crippled table instance
in the table cache if an error occurs before we reach
alter_partition_lock_handling() and the table is closed
by close_thread_tables() instead.
*/
tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
table->s->db.str,
table->s->table_name.str);
}
}
mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0);
}
/*
SYNOPSIS
abort_and_upgrade_lock_and_close_table()
lpt Parameter passing struct
All parameters passed through the ALTER_PARTITION_PARAM_TYPE object
RETURN VALUE
0
DESCRIPTION
Remember old lock level (for possible downgrade later on), abort all
waiting threads and ensure that all keeping locks currently are
completed such that we own the lock exclusively and no other interaction
is ongoing. Close the table and hold the name lock.
thd Thread object
table Table object
db Database name
table_name Table name
old_lock_level Old lock level
*/
int abort_and_upgrade_lock_and_close_table(ALTER_PARTITION_PARAM_TYPE *lpt)
{
DBUG_ENTER("abort_and_upgrade_lock_and_close_table");
if (wait_while_table_is_used(lpt->thd, lpt->table, HA_EXTRA_FORCE_REOPEN))
DBUG_RETURN(1);
if (alter_close_tables(lpt))
DBUG_RETURN(1);
DBUG_RETURN(0);
}
/*
Tells if two (or more) tables have auto_increment columns and we want to
lock those tables with a write lock.
......
......@@ -103,15 +103,10 @@ bool reopen_table(TABLE *table);
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
void close_data_files_and_morph_locks(THD *thd, const char *db,
const char *table_name);
void close_handle_and_leave_table_as_lock(TABLE *table);
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam, TABLE_LIST *table_desc,
MEM_ROOT *mem_root);
bool wait_for_tables(THD *thd);
bool table_is_used(TABLE *table, bool wait_for_name_lock);
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
bool get_key_map_from_key_list(key_map *map, TABLE *table,
List<String> *index_list);
......@@ -218,7 +213,6 @@ TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
thr_lock_type lock_type, uint flags);
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags);
int abort_and_upgrade_lock_and_close_table(ALTER_PARTITION_PARAM_TYPE *lpt);
int decide_logging_format(THD *thd, TABLE_LIST *tables);
void free_io_cache(TABLE *entry);
void intern_close_table(TABLE *entry);
......@@ -254,8 +248,6 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
LEX_STRING *connect_string,
bool have_lock = FALSE);
void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
bool remove_from_locked_tables);
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
uint flags);
......
This diff is collapsed.
......@@ -1086,6 +1086,7 @@ static bool get_free_ddl_log_entry(DDL_LOG_MEMORY_ENTRY **active_entry,
*/
used_entry->next_log_entry= first_used;
used_entry->prev_log_entry= NULL;
used_entry->next_active_log_entry= NULL;
global_ddl_log.first_used= used_entry;
if (first_used)
first_used->prev_log_entry= used_entry;
......
......@@ -43,7 +43,6 @@ class Security_context;
struct TABLE_LIST;
class ACL_internal_schema_access;
class ACL_internal_table_access;
struct TABLE_LIST;
class Field;
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment