From: Date: May 28 2007 3:45pm Subject: bk commit into 5.0 tree (evgen:1.2500) BUG#24989 List-Archive: http://lists.mysql.com/commits/27471 X-Bug: 24989 Message-Id: <20070528134507.787C122D461@moonbone.moonbone.local> Below is the list of changes that have just been committed into a local 5.0 repository of evgen. When evgen does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-05-28 17:45:02+04:00, evgen@stripped +4 -0 Bug#24989: The DEADLOCK error is improperly handled by InnoDB. When innodb detects a deadlock it calls ha_rollback_trans() to rollback the main transaction. But such action isn't allowed from inside of triggers and functions. When it happen the 'Explicit or implicit commit' error is thrown even if there is no commit/rollback statements in the trigger/function. This leads to the user confusion. Now the convert_error_code_to_mysql() function doesn't call the ha_rollback_trans() function directly but rather returns an error. The sp_rcontext::find_handler() now doesn't allow DEADLOCK errors to be caught by the trigger/function error handlers. mysql-test/r/innodb_mysql.result@stripped, 2007-05-28 17:43:36+04:00, evgen@stripped +29 -0 Added a test case for the bug#24989: The DEADLOCK error is improperly handled by InnoDB. mysql-test/t/innodb_mysql.test@stripped, 2007-05-28 17:43:18+04:00, evgen@stripped +44 -0 Added a test case for the bug#24989: The DEADLOCK error is improperly handled by InnoDB. sql/ha_innodb.cc@stripped, 2007-05-28 17:44:08+04:00, evgen@stripped +0 -5 Bug#24989: The DEADLOCK error is improperly handled by InnoDB. Now the convert_error_code_to_mysql() function doesn't call the ha_rollback_trans() function directly but rather returns an error. sql/sp_rcontext.cc@stripped, 2007-05-28 17:43:50+04:00, evgen@stripped +3 -0 Bug#24989: The DEADLOCK error is improperly handled by InnoDB. The sp_rcontext::find_handler() now doesn't allow DEADLOCK errors to be caught by the trigger/function error handlers. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: evgen # Host: moonbone.local # Root: /mnt/gentoo64/work/24989-bug-5.0-opt-mysql --- 1.21/mysql-test/r/innodb_mysql.result 2007-05-16 00:10:55 +04:00 +++ 1.22/mysql-test/r/innodb_mysql.result 2007-05-28 17:43:36 +04:00 @@ -617,4 +617,33 @@ EXPLAIN SELECT COUNT(*) FROM t2 WHERE st id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx1,idx2 idx1 9 NULL 2 Using where; Using index DROP TABLE t1,t2; +CREATE TABLE t1 (f1 int NOT NULL) ENGINE=InnoDB; +CREATE TABLE t2 (f2 int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +CREATE TRIGGER t1_bi before INSERT +ON t1 FOR EACH ROW +BEGIN +DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @a:= 'deadlock'; +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception'; +INSERT INTO t2 (f2) VALUES (1); +DELETE FROM t2 WHERE f2 = 1; +END;| +start transaction; +select get_lock("lock24989",10); +get_lock("lock24989",10) +1 +insert into t1 values(1); +select get_lock("lock24989",10); +get_lock("lock24989",10) +0 +insert into t1 values(1); +select release_lock("lock24989"); +release_lock("lock24989") +1 +insert into t1 values(1); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +select @a; +@a +NULL +commit; +drop table t1,t2; End of 5.0 tests --- 1.21/mysql-test/t/innodb_mysql.test 2007-05-16 00:10:55 +04:00 +++ 1.22/mysql-test/t/innodb_mysql.test 2007-05-28 17:43:18 +04:00 @@ -597,4 +597,48 @@ EXPLAIN SELECT COUNT(*) FROM t2 WHERE st DROP TABLE t1,t2; +# +# Bug#24989: The DEADLOCK error is improperly handled by InnoDB. +# +CREATE TABLE t1 (f1 int NOT NULL) ENGINE=InnoDB; +CREATE TABLE t2 (f2 int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +DELIMITER |; +CREATE TRIGGER t1_bi before INSERT + ON t1 FOR EACH ROW +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @a:= 'deadlock'; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception'; + INSERT INTO t2 (f2) VALUES (1); + DELETE FROM t2 WHERE f2 = 1; +END;| +DELIMITER ;| + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); + +connection con1; +start transaction; +select get_lock("lock24989",10); +insert into t1 values(1); + +connection con2; +select get_lock("lock24989",10); +send insert into t1 values(1); + +connection con1; +select release_lock("lock24989"); +insert into t1 values(1); + +connection con2; +--error 1213 +reap; +select @a; + +connection con1; +commit; +disconnect con1; +disconnect con2; +connection default; +drop table t1,t2; + --echo End of 5.0 tests --- 1.313/sql/ha_innodb.cc 2007-04-29 17:40:41 +04:00 +++ 1.314/sql/ha_innodb.cc 2007-05-28 17:44:08 +04:00 @@ -454,11 +454,6 @@ convert_error_code_to_mysql( /* Since we rolled back the whole transaction, we must tell it also to MySQL so that MySQL knows to empty the cached binlog for this transaction */ - - if (thd) { - ha_rollback(thd); - } - return(HA_ERR_LOCK_DEADLOCK); } else if (error == (int) DB_LOCK_WAIT_TIMEOUT) { --- 1.44/sql/sp_rcontext.cc 2006-12-23 22:04:26 +03:00 +++ 1.45/sql/sp_rcontext.cc 2007-05-28 17:43:50 +04:00 @@ -196,6 +196,9 @@ sp_rcontext::find_handler(uint sql_errno { if (m_hfound >= 0) return 1; // Already got one + /* Do not allow DEADLOCK errors to be caught. */ + if (sql_errno == ER_LOCK_DEADLOCK) + return FALSE; const char *sqlstate= mysql_errno_to_sqlstate(sql_errno); int i= m_hcount, found= -1;