Commit 8399af81 authored by Monty's avatar Monty

Bug#19784790: ASSERTION `PART_SHARE->PARTITIONS_SHARE_REFS->NUM_PARTS

              >= M_TOT_PARTS' FAILED.

This patch is taken from MySQL, originally written by Mattias Jonsson
Here follows the original commit message:

Problem in handle_alter_part_error(),
result in altered partition_info object was still used
if table was under LOCK TABLES.

Solution was to always close and destroy all table
and table_share instances if exclusive mdl lock was
possible.
If not succeeding in get an exlusive lock (only possible
during rollback of DDL), at least close and destroy this
table instance.

rb#7361.
Approved by Mikael and Aditya.
parent 0126169e
...@@ -236,6 +236,7 @@ DROP TABLE t1; ...@@ -236,6 +236,7 @@ DROP TABLE t1;
connect con1,localhost,root,,; connect con1,localhost,root,,;
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT ) CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2; ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
INSERT INTO t1 VALUES (2, 2), (3, 3), (4, 4), (5, 5);
connect con2,localhost,root,,; connect con2,localhost,root,,;
SET lock_wait_timeout = 2; SET lock_wait_timeout = 2;
connection con1; connection con1;
...@@ -249,6 +250,19 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction ...@@ -249,6 +250,19 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Second attempt: says that partition already exists # Second attempt: says that partition already exists
ALTER TABLE t1 ADD PARTITION PARTITIONS 2; ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction ERROR HY000: Lock wait timeout exceeded; try restarting transaction
# Check that we only can select, not insert/update/delete.
INSERT INTO t1 VALUES (NULL, 6), (NULL, 7), (10, 10), (11, 11);
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
UPDATE t1 SET i = 5 WHERE f = 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
DELETE FROM t1 WHERE i = 10;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SELECT * FROM t1;
i f
2 2
3 3
4 4
5 5
connection con1; connection con1;
# Connection 1 unlocks the table and locks it again: # Connection 1 unlocks the table and locks it again:
UNLOCK TABLES; UNLOCK TABLES;
...@@ -335,3 +349,30 @@ PARTITION BY RANGE(f1) (PARTITION p1 VALUES LESS THAN(10), ...@@ -335,3 +349,30 @@ PARTITION BY RANGE(f1) (PARTITION p1 VALUES LESS THAN(10),
PARTITION p2 VALUES LESS THAN (100)); PARTITION p2 VALUES LESS THAN (100));
ALTER TABLE t1 convert to charset ascii collate ascii_bin, ALGORITHM=INSTANT; ALTER TABLE t1 convert to charset ascii collate ascii_bin, ALGORITHM=INSTANT;
DROP TABLE t1; DROP TABLE t1;
# Test WRITE LOCK.
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;
INSERT INTO t1 VALUES (3, 3), (4, 4);
connect con2,localhost,root,,;
SET lock_wait_timeout = 2;
connection con1;
#Connection 1 locks the table
LOCK TABLE t1 WRITE;
connection con2;
# Check that we still can SELECT, but not insert/update/delete.
# Check that we only can select, not insert/update/delete.
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2), (10, 10), (11, 11);
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
UPDATE t1 SET i = 5 WHERE f = 2;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
DELETE FROM t1 WHERE i = 10;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SELECT * FROM t1;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
connection con1;
UNLOCK TABLES;
connection con2;
DROP TABLE t1;
disconnect con1;
connection default;
...@@ -83,6 +83,7 @@ DROP TABLE t1; ...@@ -83,6 +83,7 @@ DROP TABLE t1;
--connect (con1,localhost,root,,) --connect (con1,localhost,root,,)
CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT ) CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )
ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2; ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 2;
INSERT INTO t1 VALUES (2, 2), (3, 3), (4, 4), (5, 5);
--connect (con2,localhost,root,,) --connect (con2,localhost,root,,)
SET lock_wait_timeout = 2; SET lock_wait_timeout = 2;
...@@ -99,6 +100,15 @@ ALTER TABLE t1 ADD PARTITION PARTITIONS 2; ...@@ -99,6 +100,15 @@ ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--echo # Second attempt: says that partition already exists --echo # Second attempt: says that partition already exists
--error ER_LOCK_WAIT_TIMEOUT --error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 ADD PARTITION PARTITIONS 2; ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--echo # Check that we only can select, not insert/update/delete.
--error ER_LOCK_WAIT_TIMEOUT
INSERT INTO t1 VALUES (NULL, 6), (NULL, 7), (10, 10), (11, 11);
--error ER_LOCK_WAIT_TIMEOUT
UPDATE t1 SET i = 5 WHERE f = 2;
--error ER_LOCK_WAIT_TIMEOUT
DELETE FROM t1 WHERE i = 10;
--sorted_result
SELECT * FROM t1;
--connection con1 --connection con1
--echo # Connection 1 unlocks the table and locks it again: --echo # Connection 1 unlocks the table and locks it again:
...@@ -215,3 +225,37 @@ CREATE TABLE t1( ...@@ -215,3 +225,37 @@ CREATE TABLE t1(
PARTITION p2 VALUES LESS THAN (100)); PARTITION p2 VALUES LESS THAN (100));
ALTER TABLE t1 convert to charset ascii collate ascii_bin, ALGORITHM=INSTANT; ALTER TABLE t1 convert to charset ascii collate ascii_bin, ALGORITHM=INSTANT;
DROP TABLE t1; DROP TABLE t1;
--echo # Test WRITE LOCK.
--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;
INSERT INTO t1 VALUES (3, 3), (4, 4);
--connect (con2,localhost,root,,)
SET lock_wait_timeout = 2;
--connection con1
--echo #Connection 1 locks the table
LOCK TABLE t1 WRITE;
--connection con2
--echo # Check that we still can SELECT, but not insert/update/delete.
--echo # Check that we only can select, not insert/update/delete.
--error ER_LOCK_WAIT_TIMEOUT
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2), (10, 10), (11, 11);
--error ER_LOCK_WAIT_TIMEOUT
UPDATE t1 SET i = 5 WHERE f = 2;
--error ER_LOCK_WAIT_TIMEOUT
DELETE FROM t1 WHERE i = 10;
--error ER_LOCK_WAIT_TIMEOUT
SELECT * FROM t1;
--connection con1
UNLOCK TABLES;
--connection con2
DROP TABLE t1;
--disconnect con1
--connection default
This diff is collapsed.
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