diff --git a/mysql-test/r/flush_block_commit.result b/mysql-test/r/flush_block_commit.result index da09d07b813..7062d05c2d7 100644 --- a/mysql-test/r/flush_block_commit.result +++ b/mysql-test/r/flush_block_commit.result @@ -17,9 +17,9 @@ COMMIT; # Verify that 'con1' was blocked and data did not move. SELECT * FROM t1; a -1 UNLOCK TABLES; # Switch to connection con1 +# Reaping COMMIT # Switch to connection con1 BEGIN; SELECT * FROM t1 FOR UPDATE; diff --git a/mysql-test/r/mdl_sync.result b/mysql-test/r/mdl_sync.result index f63179b893a..d409157a70b 100644 --- a/mysql-test/r/mdl_sync.result +++ b/mysql-test/r/mdl_sync.result @@ -173,3 +173,24 @@ drop table t2; # Switching to connection 'default'. # Clean-up. drop table t1; +# +# Test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK +# and DML". +# +drop tables if exists t1; +create table t1 (i int); +# Switching to connection 'con46673'. +begin; +insert into t1 values (1); +# Switching to connection 'default'. +# Statement below should not get blocked. And if after some +# changes to code it is there should not be a deadlock between +# it and transaction from connection 'con46673'. +flush tables with read lock; +unlock tables; +# Switching to connection 'con46673'. +delete from t1 where i = 1; +commit; +# Switching to connection 'default'. +# Clean-up +drop table t1; diff --git a/mysql-test/r/read_only_innodb.result b/mysql-test/r/read_only_innodb.result index 4cba98900a1..690de085bf9 100644 --- a/mysql-test/r/read_only_innodb.result +++ b/mysql-test/r/read_only_innodb.result @@ -7,10 +7,12 @@ insert into table_11733 values(11733); set global read_only=1; select @@global.read_only; @@global.read_only -0 +1 select * from table_11733 ; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +a +11733 COMMIT; +ERROR HY000: The MySQL server is running with the --read-only option so it cannot execute this statement set global read_only=0; drop table table_11733 ; drop user test@localhost; diff --git a/mysql-test/t/flush_block_commit.test b/mysql-test/t/flush_block_commit.test index 98bca8cdad7..0b3bede1684 100644 --- a/mysql-test/t/flush_block_commit.test +++ b/mysql-test/t/flush_block_commit.test @@ -29,26 +29,25 @@ BEGIN; INSERT INTO t1 VALUES(1); --echo # Switch to connection con2 connection con2; ---send FLUSH TABLES WITH READ LOCK +FLUSH TABLES WITH READ LOCK; --echo # Switch to connection con1 connection con1; --echo # Sending: -COMMIT; +--send COMMIT --echo # Switch to connection con2 connection con2; ---reap --echo # Wait until COMMIT gets blocked. -#let $wait_condition= -# select count(*) = 1 from information_schema.processlist -# where state = "Waiting for release of readlock" and info = "COMMIT"; -#--source include/wait_condition.inc +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for release of readlock" and info = "COMMIT"; +--source include/wait_condition.inc --echo # Verify that 'con1' was blocked and data did not move. SELECT * FROM t1; UNLOCK TABLES; --echo # Switch to connection con1 connection con1; -#--echo # Reaping COMMIT -#--reap +--echo # Reaping COMMIT +--reap # No deadlock ? diff --git a/mysql-test/t/mdl_sync.test b/mysql-test/t/mdl_sync.test index cc03cc67f95..d50c056fda3 100644 --- a/mysql-test/t/mdl_sync.test +++ b/mysql-test/t/mdl_sync.test @@ -343,6 +343,43 @@ disconnect con46044; disconnect con46044_2; drop table t1; + +--echo # +--echo # Test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK +--echo # and DML". +--echo # +--disable_warnings +drop tables if exists t1; +--enable_warnings +connect (con46673, localhost, root,,); +connection default; +create table t1 (i int); + +--echo # Switching to connection 'con46673'. +connection con46673; +begin; +insert into t1 values (1); + +--echo # Switching to connection 'default'. +connection default; +--echo # Statement below should not get blocked. And if after some +--echo # changes to code it is there should not be a deadlock between +--echo # it and transaction from connection 'con46673'. +flush tables with read lock; +unlock tables; + +--echo # Switching to connection 'con46673'. +connection con46673; +delete from t1 where i = 1; +commit; + +--echo # Switching to connection 'default'. +connection default; +--echo # Clean-up +disconnect con46673; +drop table t1; + + # Check that all connections opened by test cases in this file are really # gone so execution of other tests won't be affected by their presence. --source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/read_only_innodb.test b/mysql-test/t/read_only_innodb.test index 98e704e25c7..9e001f2b997 100644 --- a/mysql-test/t/read_only_innodb.test +++ b/mysql-test/t/read_only_innodb.test @@ -16,8 +16,6 @@ DROP TABLE IF EXISTS table_11733 ; grant CREATE, SELECT, DROP on *.* to test@localhost; connect (con1,localhost,test,,test); -connect (con2,localhost,root,,); - connection default; set global read_only=0; @@ -30,22 +28,15 @@ BEGIN; insert into table_11733 values(11733); connection default; -send set global read_only=1; - -connection con2; -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Flushing tables" and info = "set global read_only=1"; ---source include/wait_condition.inc +set global read_only=1; connection con1; select @@global.read_only; ---error ER_LOCK_DEADLOCK select * from table_11733 ; +--error ER_OPTION_PREVENTS_STATEMENT COMMIT; connection default; -reap; set global read_only=0; drop table table_11733 ; drop user test@localhost; @@ -90,6 +81,5 @@ DROP TABLE t1; DROP USER test@localhost; disconnect con1; -disconnect con2; --echo echo End of 5.1 tests diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d1ce4aefb1f..ad618eb59fe 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2648,7 +2648,9 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, DBUG_RETURN(FALSE); } +#ifdef DISABLED_UNTIL_GRL_IS_MADE_PART_OF_MDL if (!(share= (TABLE_SHARE *) mdl_ticket->get_cached_object())) +#endif { if (!(share= get_table_share_with_create(thd, table_list, key, key_length, OPEN_VIEW, @@ -2714,13 +2716,16 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, if (table_list->i_s_requested_object & OPEN_VIEW_ONLY) goto err_unlock; +#ifdef DISABLED_UNTIL_GRL_IS_MADE_PART_OF_MDL /* We are going to to store extra reference to the share in MDL-subsystem so we need to increase reference counter; */ reference_table_share(share); mdl_ticket->set_cached_object(share, table_share_release_hook); +#endif } +#ifdef DISABLED_UNTIL_GRL_IS_MADE_PART_OF_MDL else { if (table_list->view) @@ -2741,6 +2746,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, */ reference_table_share(share); } +#endif if (share->version != refresh_version) {