List:Commits« Previous MessageNext Message »
From:Konstantin Osipov Date:January 27 2010 8:50pm
Subject:bzr commit into mysql-5.6-next-mr branch (kostja:3066)
View as plain text  
#At file:///opt/local/work/next-4284-stage/ based on revid:dlenev@stripped

 3066 Konstantin Osipov	2010-01-27
      (no message)

    modified:
      mysql-test/include/handler.inc
      mysql-test/r/handler_innodb.result
      mysql-test/r/handler_myisam.result
      sql/mdl.cc
=== modified file 'mysql-test/include/handler.inc'
--- a/mysql-test/include/handler.inc	2010-01-26 18:22:10 +0000
+++ b/mysql-test/include/handler.inc	2010-01-27 20:50:22 +0000
@@ -1443,3 +1443,39 @@ unlock tables;
 drop table t1;
 set autocommit=default;
 drop table t2, t3;
+
+--echo # 
+--echo # HANDLER statement and operation-type aware metadata locks.
+--echo # Check that when we clone a ticket for HANDLER we downrade
+--echo # the lock.
+--echo #
+--echo # Establish an auxiliary connection con1.
+connect (con1,localhost,root,,);
+--echo # -> connection default
+connection default;
+create table t1 (a int, b int, key a (a));
+insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
+begin;
+insert into t1 (a, b) values (6, 6);
+handler t1 open;
+handler t1 read a last;
+insert into t1 (a, b) values (7, 7);
+handler t1 read a last;
+commit;
+--echo # -> connection con1
+connection con1;
+--echo # Demonstrate that the HANDLER doesn't hold MDL_SHARED_WRITE.
+lock table t1 write;
+unlock tables;
+--echo # -> connection default
+connection default;
+handler t1 read a prev;
+handler t1 close;
+--echo # Cleanup.
+drop table t1;
+--echo # -> connection con1
+connection con1;
+disconnect con1;
+--source include/wait_until_disconnected.inc
+--echo # -> connection default
+connection default;

=== modified file 'mysql-test/r/handler_innodb.result'
--- a/mysql-test/r/handler_innodb.result	2010-01-26 18:22:10 +0000
+++ b/mysql-test/r/handler_innodb.result	2010-01-27 20:50:22 +0000
@@ -1418,3 +1418,36 @@ unlock tables;
 drop table t1;
 set autocommit=default;
 drop table t2, t3;
+# 
+# HANDLER statement and operation-type aware metadata locks.
+# Check that when we clone a ticket for HANDLER we downrade
+# the lock.
+#
+# Establish an auxiliary connection con1.
+# -> connection default
+create table t1 (a int, b int, key a (a));
+insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
+begin;
+insert into t1 (a, b) values (6, 6);
+handler t1 open;
+handler t1 read a last;
+a	b
+6	6
+insert into t1 (a, b) values (7, 7);
+handler t1 read a last;
+a	b
+7	7
+commit;
+# -> connection con1
+# Demonstrate that the HANDLER doesn't hold MDL_SHARED_WRITE.
+lock table t1 write;
+unlock tables;
+# -> connection default
+handler t1 read a prev;
+a	b
+6	6
+handler t1 close;
+# Cleanup.
+drop table t1;
+# -> connection con1
+# -> connection default

=== modified file 'mysql-test/r/handler_myisam.result'
--- a/mysql-test/r/handler_myisam.result	2010-01-26 18:22:10 +0000
+++ b/mysql-test/r/handler_myisam.result	2010-01-27 20:50:22 +0000
@@ -1415,6 +1415,39 @@ unlock tables;
 drop table t1;
 set autocommit=default;
 drop table t2, t3;
+# 
+# HANDLER statement and operation-type aware metadata locks.
+# Check that when we clone a ticket for HANDLER we downrade
+# the lock.
+#
+# Establish an auxiliary connection con1.
+# -> connection default
+create table t1 (a int, b int, key a (a));
+insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
+begin;
+insert into t1 (a, b) values (6, 6);
+handler t1 open;
+handler t1 read a last;
+a	b
+6	6
+insert into t1 (a, b) values (7, 7);
+handler t1 read a last;
+a	b
+7	7
+commit;
+# -> connection con1
+# Demonstrate that the HANDLER doesn't hold MDL_SHARED_WRITE.
+lock table t1 write;
+unlock tables;
+# -> connection default
+handler t1 read a prev;
+a	b
+6	6
+handler t1 close;
+# Cleanup.
+drop table t1;
+# -> connection con1
+# -> connection default
 #
 # BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash 
 #

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2010-01-27 16:44:35 +0000
+++ b/sql/mdl.cc	2010-01-27 20:50:22 +0000
@@ -1364,10 +1364,10 @@ MDL_context::try_acquire_shared_lock(MDL
 
 
 /**
-  Create a copy of a granted ticket. 
+  Create a copy of a granted ticket.
   This is used to make sure that HANDLER ticket
   is never shared with a ticket that belongs to
-  a transaction, so that when we HANDLER CLOSE, 
+  a transaction, so that when we HANDLER CLOSE,
   we don't release a transactional ticket, and
   vice versa -- when we COMMIT, we don't mistakenly
   release a ticket for an open HANDLER.
@@ -1382,12 +1382,17 @@ MDL_context::clone_ticket(MDL_request *m
   MDL_ticket *ticket;
 
   safe_mutex_assert_not_owner(&LOCK_open);
-  /* Only used for HANDLER. */
-  DBUG_ASSERT(mdl_request->ticket && mdl_request->ticket->is_shared());
-
+  /*
+    By submitting mdl_request->type to MDL_ticket::create()
+    we effectively downgrade the cloned lock to the level of
+    the request.
+  */
   if (!(ticket= MDL_ticket::create(this, mdl_request->type)))
     return TRUE;
 
+  /* clone() is not supposed to be used to get a stronger lock. */
+  DBUG_ASSERT(ticket->m_type <= mdl_request->ticket->m_type);
+
   ticket->m_lock= mdl_request->ticket->m_lock;
   mdl_request->ticket= ticket;
 


Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100127205022-unv60nwmmv71qb3p.bundle
Thread
bzr commit into mysql-5.6-next-mr branch (kostja:3066)Konstantin Osipov27 Jan