diff --git a/mysql-test/r/innodb_mysql_lock.result b/mysql-test/r/innodb_mysql_lock.result new file mode 100644 index 00000000000..147267d5550 --- /dev/null +++ b/mysql-test/r/innodb_mysql_lock.result @@ -0,0 +1,24 @@ +# +# Bug #22876 Four-way deadlock +# +DROP TABLE IF EXISTS t1; +# Connection 1 +set @@autocommit=0; +CREATE TABLE t1(s1 INT UNIQUE) ENGINE=innodb; +INSERT INTO t1 VALUES (1); +# Connection 2 +set @@autocommit=0; +INSERT INTO t1 VALUES (2); +INSERT INTO t1 VALUES (1); +# Connection 3 +set @@autocommit=0; +DROP TABLE t1; +# Connection 1 +# Connection 1 is now holding the lock. +# Issuing insert from connection 1 while connection 2&3 +# is waiting for the lock should give a deadlock error. +INSERT INTO t1 VALUES (2); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +# Cleanup +commit; +commit; diff --git a/mysql-test/r/lock.result b/mysql-test/r/lock.result index 46ce618b99b..afb444f8ae9 100644 --- a/mysql-test/r/lock.result +++ b/mysql-test/r/lock.result @@ -319,5 +319,27 @@ alter table t1 add column j int; unlock tables; drop table t1; # +# Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against +# LOCK TABLE +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a INT); +LOCK TABLE t1 READ; +FLUSH TABLES; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +LOCK TABLE t1 WRITE; +FLUSH TABLES; +# +# If you allow the next combination, you reintroduce bug Bug#45066 +# +LOCK TABLE t1 READ; +FLUSH TABLES WITH READ LOCK; +ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction +LOCK TABLE t1 WRITE; +FLUSH TABLES WITH READ LOCK; +ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction +UNLOCK TABLES; +DROP TABLE t1; +# # End of 6.0 tests. # diff --git a/mysql-test/suite/rpl/r/rpl_innodb.result b/mysql-test/suite/rpl/r/rpl_innodb.result index bf6c3cb8c86..0d83f29d0fb 100644 --- a/mysql-test/suite/rpl/r/rpl_innodb.result +++ b/mysql-test/suite/rpl/r/rpl_innodb.result @@ -82,3 +82,48 @@ FLUSH LOGS; FLUSH LOGS; DROP DATABASE mysqltest1; End of 5.1 tests +# +# Bug#39675 rename tables on innodb tables with pending +# transactions causes slave data issue. +# +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +CREATE TABLE t1 ( +id INT PRIMARY KEY auto_increment, +b INT DEFAULT NULL +) ENGINE=InnoDB; +CREATE TABLE t2 ( +id INT PRIMARY KEY auto_increment, +b INT DEFAULT NULL +) ENGINE=InnoDB; +INSERT INTO t1 (b) VALUES (1),(2),(3); +BEGIN; +INSERT INTO t1(b) VALUES (4); +-------- switch to master1 -------- +RENAME TABLE t1 TO t3, t2 TO t1;; +-------- switch to master -------- +COMMIT; +-------- switch to master1 -------- +-------- switch to master -------- +SELECT * FROM t1; +id b +SELECT * FROM t3; +id b +1 1 +2 2 +3 3 +4 4 +-------- switch to slave -------- +SELECT * FROM t1; +id b +SELECT * FROM t3; +id b +1 1 +2 2 +3 3 +4 4 +-------- switch to master -------- +DROP TABLE t1; +DROP TABLE t3; +End of 6.0 tests diff --git a/mysql-test/suite/rpl/t/rpl_innodb.test b/mysql-test/suite/rpl/t/rpl_innodb.test index 64a85d27c88..7ee65027abc 100644 --- a/mysql-test/suite/rpl/t/rpl_innodb.test +++ b/mysql-test/suite/rpl/t/rpl_innodb.test @@ -120,6 +120,71 @@ connection master; FLUSH LOGS; DROP DATABASE mysqltest1; --- source include/master-slave-end.inc --echo End of 5.1 tests + +--echo # +--echo # Bug#39675 rename tables on innodb tables with pending +--echo # transactions causes slave data issue. +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +--enable_warnings + +CREATE TABLE t1 ( + id INT PRIMARY KEY auto_increment, + b INT DEFAULT NULL +) ENGINE=InnoDB; + +CREATE TABLE t2 ( + id INT PRIMARY KEY auto_increment, + b INT DEFAULT NULL +) ENGINE=InnoDB; + +INSERT INTO t1 (b) VALUES (1),(2),(3); + +BEGIN; +INSERT INTO t1(b) VALUES (4); + +--echo -------- switch to master1 -------- +connection master1; +--send RENAME TABLE t1 TO t3, t2 TO t1; + +--echo -------- switch to master -------- +connection master; +# Need to wait until RENAME is received +let $wait_condition= + SELECT COUNT(*) = 1 FROM information_schema.processlist + WHERE info = "RENAME TABLE t1 TO t3, t2 TO t1" and + state = "Waiting for table"; +--source include/wait_condition.inc + +COMMIT; + +--echo -------- switch to master1 -------- +connection master1; +--reap + +--echo -------- switch to master -------- +connection master; +SELECT * FROM t1; +SELECT * FROM t3; + +sync_slave_with_master; + +--echo -------- switch to slave -------- +connection slave; +SELECT * FROM t1; +SELECT * FROM t3; + +--echo -------- switch to master -------- +connection master; +DROP TABLE t1; +DROP TABLE t3; + +--echo End of 6.0 tests + +--source include/master-slave-end.inc diff --git a/mysql-test/t/innodb_mysql_lock-master.opt b/mysql-test/t/innodb_mysql_lock-master.opt new file mode 100644 index 00000000000..0041949b829 --- /dev/null +++ b/mysql-test/t/innodb_mysql_lock-master.opt @@ -0,0 +1 @@ +--innodb_lock_wait_timeout=300 diff --git a/mysql-test/t/innodb_mysql_lock.test b/mysql-test/t/innodb_mysql_lock.test new file mode 100644 index 00000000000..daee94bedb5 --- /dev/null +++ b/mysql-test/t/innodb_mysql_lock.test @@ -0,0 +1,58 @@ +-- source include/have_innodb.inc + +--echo # +--echo # Bug #22876 Four-way deadlock +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +connect (con3,localhost,root,,); + +--echo # Connection 1 +connection con1; +set @@autocommit=0; +CREATE TABLE t1(s1 INT UNIQUE) ENGINE=innodb; +INSERT INTO t1 VALUES (1); + +--echo # Connection 2 +connection con2; +set @@autocommit=0; +INSERT INTO t1 VALUES (2); +--send INSERT INTO t1 VALUES (1) + +--echo # Connection 3 +connection con3; +set @@autocommit=0; +--send DROP TABLE t1 + +--echo # Connection 1 +connection con1; +let $wait_condition= + SELECT COUNT(*) = 1 FROM information_schema.processlist + WHERE info = "INSERT INTO t1 VALUES (1)" and + state = "update"; +--source include/wait_condition.inc +let $wait_condition= + SELECT COUNT(*) = 1 FROM information_schema.processlist + WHERE info = "DROP TABLE t1" and + state = "Waiting for table"; +--source include/wait_condition.inc +--echo # Connection 1 is now holding the lock. +--echo # Issuing insert from connection 1 while connection 2&3 +--echo # is waiting for the lock should give a deadlock error. +--error ER_LOCK_DEADLOCK +INSERT INTO t1 VALUES (2); + +--echo # Cleanup +connection con2; +--reap +commit; +connection con1; +commit; +connection con3; +--reap +connection default; diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index eaba2693904..4d610559077 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -385,6 +385,38 @@ alter table t1 add column j int; unlock tables; drop table t1; +--echo # +--echo # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against +--echo # LOCK TABLE +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1(a INT); + +LOCK TABLE t1 READ; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +FLUSH TABLES; + +LOCK TABLE t1 WRITE; +FLUSH TABLES; + +--echo # +--echo # If you allow the next combination, you reintroduce bug Bug#45066 +--echo # +LOCK TABLE t1 READ; +--error ER_LOCK_OR_ACTIVE_TRANSACTION +FLUSH TABLES WITH READ LOCK; + +LOCK TABLE t1 WRITE; +--error ER_LOCK_OR_ACTIVE_TRANSACTION +FLUSH TABLES WITH READ LOCK; + +UNLOCK TABLES; +DROP TABLE t1; + --echo # --echo # End of 6.0 tests. --echo #