List:Commits« Previous MessageNext Message »
From:Magne Mahre Date:November 30 2009 11:30am
Subject:bzr commit into mysql-5.1-bugteam branch (magne.mahre:3221) Bug#20837
View as plain text  
#At file:///data/z/mysql-5.1-bugteam-20837/ based on revid:satya.bn@stripped

 3221 Magne Mahre	2009-11-30
      Bug #20837 Apparent change of isolation level during transaction
            
      SET TRANSACTION ISOLATION LEVEL is used to temporarily set
      the trans.iso.level for the next transaction.  After the
      transaction, the iso.level is (re-)set to value of the 
      session variable 'tx_isolation'.
      
      The bug is caused by setting the thd->variables.tx_isolation 
      field to the value of the session variable upon each
      statement commit.  It should only be set at the end of the
      full transaction.
      
      The fix has been to remove the setting of the variable in
      ha_autocommit_or_rollback if we're in a transaction, as it 
      will be correctly set in  either ha_rollback or 
      ha_commit_one_phase.  
      
      If, on the other hand, we're in  autocommit mode, tx_isolation 
      will be explicitly set here.
     @ mysql-test/t/innodb_mysql.test
        "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" sets
        the trans.isolation for the next transaction.  We test
        that @@tx_isolation keeps this value during the transaction,
        and is only reset back to the session value at the end
        of the transaction.

    modified:
      mysql-test/r/innodb_mysql.result
      mysql-test/t/innodb_mysql.test
      sql/handler.cc
=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2009-11-04 11:54:28 +0000
+++ b/mysql-test/r/innodb_mysql.result	2009-11-30 11:30:28 +0000
@@ -2273,4 +2273,35 @@ END|
 DROP PROCEDURE p1;
 DROP VIEW v1;
 DROP TABLE t1,t2;
+#
+# Bug #20837 Apparent change of isolation 
+#     level during transaction
+#
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+CREATE TABLE t1 (s1 INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+COMMIT;
+SET @@autocommit = 0;
+COMMIT;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+START TRANSACTION;
+SELECT * FROM t1;
+s1
+1
+2
+Should be READ UNCOMMITTED
+SELECT @@tx_isolation;
+@@tx_isolation
+READ-UNCOMMITTED
+INSERT INTO t1 VALUES (-1);
+Should be READ UNCOMMITTED
+SELECT @@tx_isolation;
+@@tx_isolation
+READ-UNCOMMITTED
+COMMIT;
+Should now be REPEATABLE READ
+SELECT @@tx_isolation;
+@@tx_isolation
+REPEATABLE-READ
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/t/innodb_mysql.test'
--- a/mysql-test/t/innodb_mysql.test	2009-11-04 11:54:28 +0000
+++ b/mysql-test/t/innodb_mysql.test	2009-11-30 11:30:28 +0000
@@ -536,4 +536,30 @@ DROP PROCEDURE p1;
 DROP VIEW v1;
 DROP TABLE t1,t2;
 
+
+--echo #
+--echo # Bug #20837 Apparent change of isolation 
+--echo #     level during transaction
+--echo #
+
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+CREATE TABLE t1 (s1 INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+COMMIT;
+
+SET @@autocommit = 0;
+COMMIT;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+START TRANSACTION;
+SELECT * FROM t1;
+--echo Should be READ UNCOMMITTED
+SELECT @@tx_isolation;
+INSERT INTO t1 VALUES (-1);
+--echo Should be READ UNCOMMITTED
+SELECT @@tx_isolation;
+COMMIT;
+--echo Should now be REPEATABLE READ
+SELECT @@tx_isolation;
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-10-28 15:39:08 +0000
+++ b/sql/handler.cc	2009-11-30 11:30:28 +0000
@@ -1369,8 +1369,14 @@ int ha_autocommit_or_rollback(THD *thd, 
       if (thd->transaction_rollback_request && !thd->in_sub_stmt)
         (void) ha_rollback(thd);
     }
-
-    thd->variables.tx_isolation=thd->session_tx_isolation;
+  } 
+  else if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
+  {
+    /* 
+       If we're in autocommit mode, reset tx_isolation
+       to the default value
+    */
+    thd->variables.tx_isolation= thd->session_tx_isolation;
   }
 #endif
   DBUG_RETURN(error);


Attachment: [text/bzr-bundle] bzr/magne.mahre@sun.com-20091130113028-2jyoo9tn6fiidif4.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (magne.mahre:3221) Bug#20837Magne Mahre30 Nov