MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:May 28 2007 8:07pm
Subject:bk commit into 5.0 tree (evgen:1.2500) BUG#24989
View as plain text  
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-29 00:07:22+04:00, evgen@stripped +5 -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.
  Now the dispatch_command() function rolls back the main transaction if
  the DEADLOCK error occur during statement execution.

  mysql-test/r/innodb_mysql.result@stripped, 2007-05-29 00:03:37+04:00, evgen@stripped +33 -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-29 00:03:34+04:00, evgen@stripped +48 -0
    Added a test case for the bug#24989: The DEADLOCK error is improperly handled by InnoDB.

  sql/ha_innodb.cc@stripped, 2007-05-29 00:03:53+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-29 00:03:52+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.

  sql/sql_parse.cc@stripped, 2007-05-29 00:06:26+04:00, evgen@stripped +4 -0
    Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
    Now the dispatch_command() function rolls back the main transaction if
    the DEADLOCK error occur during statement execution.

# 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.621/sql/sql_parse.cc	2007-05-15 13:56:04 +04:00
+++ 1.622/sql/sql_parse.cc	2007-05-29 00:06:26 +04:00
@@ -2155,7 +2155,11 @@ bool dispatch_command(enum enum_server_c
   if (thd->killed_errno() && !thd->net.report_error)
     thd->send_kill_message();
   if (thd->net.report_error)
+  {
+    if (thd->net.last_errno == ER_LOCK_DEADLOCK)
+      ha_rollback(thd);
     net_send_error(thd);
+  }
 
   log_slow_statement(thd);
 

--- 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-29 00:03:37 +04:00
@@ -617,4 +617,37 @@ 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);
+start transaction;
+insert into t2 values(123);
+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
+select * from t2;
+f2
+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-29 00:03:34 +04:00
@@ -597,4 +597,52 @@ 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;
+start transaction;
+insert into t2 values(123);
+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;
+# check that the whole transaction was rolled back
+select * from t2;
+
+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-29 00:03:53 +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-29 00:03:52 +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;
Thread
bk commit into 5.0 tree (evgen:1.2500) BUG#24989eugene28 May