mariadb/mysql-test/main/read_only_innodb.test

252 lines
5.6 KiB
Text
Raw Normal View History

# should work with embedded server after mysqltest is fixed
-- source include/not_embedded.inc
-- source include/have_innodb.inc
#
# BUG#11733: COMMITs should not happen if read-only is set
#
--disable_warnings
DROP TABLE IF EXISTS table_11733 ;
--enable_warnings
# READ_ONLY does nothing to SUPER users
# so we use a non-SUPER one:
create user test@localhost;
grant CREATE, SELECT, DROP on *.* to test@localhost;
connect (con1,localhost,test,,test);
connection default;
set global read_only=0;
# Any transactional engine will do
create table table_11733 (a int) engine=InnoDb;
connection con1;
BEGIN;
insert into table_11733 values(11733);
connection default;
Backport of: ------------------------------------------------------------ revno: 2617.68.10 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-next-bg46673 timestamp: Tue 2009-09-01 19:57:05 +0400 message: Fix for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". Deadlocks occured when one concurrently executed transactions with several statements modifying data and FLUSH TABLES WITH READ LOCK statement or SET READ_ONLY=1 statement. These deadlocks were introduced by the patch for WL 4284: "Transactional DDL locking"/Bug 989: "If DROP TABLE while there's an active transaction, wrong binlog order" which has changed FLUSH TABLES WITH READ LOCK/SET READ_ONLY=1 to wait for pending transactions. What happened was that FLUSH TABLES WITH READ LOCK blocked all further statements changing tables by setting global_read_lock global variable and has started waiting for all pending transactions to complete. Then one of those transactions tried to executed DML, detected that global_read_lock non-zero and tried to wait until global read lock will be released (i.e. global_read_lock becomes 0), indeed, this led to a deadlock. Proper solution for this problem should probably involve full integration of global read lock with metadata locking subsystem (which will allow to implement waiting for pending transactions without blocking DML in them). But since it requires significant changes another, short-term solution for the problem is implemented in this patch. Basically, this patch restores behavior of FLUSH TABLES WITH READ LOCK/ SET READ_ONLY=1 before the patch for WL 4284/bug 989. By ensuring that extra references to TABLE_SHARE are not stored for active metadata locks it changes these statements not to wait for pending transactions. As result deadlock is eliminated. Note that this does not change the fact that active FLUSH TABLES WITH READ LOCK lock or SET READ_ONLY=1 prevent modifications to tables as they also block transaction commits. mysql-test/r/flush_block_commit.result: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/r/mdl_sync.result: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/r/read_only_innodb.result: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. mysql-test/t/flush_block_commit.test: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/t/mdl_sync.test: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/t/read_only_innodb.test: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. sql/sql_base.cc: Disable caching of pointers to TABLE_SHARE objects in MDL subsystem. This means that transactions holding metadata lock on the table will no longer have extra reference to the TABLE_SHARE (due to this lock) and will no longer block concurrent FLUSH TABLES/FLUSH TABLES WITH READ LOCK. Note that this does not change the fact that FLUSH TABLES WITH READ LOCK prevents concurrent transactions from modifying data as it also blocks all commits.
2009-12-09 16:56:34 +01:00
set global read_only=1;
connection con1;
select @@global.read_only;
select * from table_11733 ;
Backport of: ------------------------------------------------------------ revno: 2617.68.10 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-next-bg46673 timestamp: Tue 2009-09-01 19:57:05 +0400 message: Fix for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". Deadlocks occured when one concurrently executed transactions with several statements modifying data and FLUSH TABLES WITH READ LOCK statement or SET READ_ONLY=1 statement. These deadlocks were introduced by the patch for WL 4284: "Transactional DDL locking"/Bug 989: "If DROP TABLE while there's an active transaction, wrong binlog order" which has changed FLUSH TABLES WITH READ LOCK/SET READ_ONLY=1 to wait for pending transactions. What happened was that FLUSH TABLES WITH READ LOCK blocked all further statements changing tables by setting global_read_lock global variable and has started waiting for all pending transactions to complete. Then one of those transactions tried to executed DML, detected that global_read_lock non-zero and tried to wait until global read lock will be released (i.e. global_read_lock becomes 0), indeed, this led to a deadlock. Proper solution for this problem should probably involve full integration of global read lock with metadata locking subsystem (which will allow to implement waiting for pending transactions without blocking DML in them). But since it requires significant changes another, short-term solution for the problem is implemented in this patch. Basically, this patch restores behavior of FLUSH TABLES WITH READ LOCK/ SET READ_ONLY=1 before the patch for WL 4284/bug 989. By ensuring that extra references to TABLE_SHARE are not stored for active metadata locks it changes these statements not to wait for pending transactions. As result deadlock is eliminated. Note that this does not change the fact that active FLUSH TABLES WITH READ LOCK lock or SET READ_ONLY=1 prevent modifications to tables as they also block transaction commits. mysql-test/r/flush_block_commit.result: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/r/mdl_sync.result: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/r/read_only_innodb.result: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. mysql-test/t/flush_block_commit.test: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/t/mdl_sync.test: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/t/read_only_innodb.test: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. sql/sql_base.cc: Disable caching of pointers to TABLE_SHARE objects in MDL subsystem. This means that transactions holding metadata lock on the table will no longer have extra reference to the TABLE_SHARE (due to this lock) and will no longer block concurrent FLUSH TABLES/FLUSH TABLES WITH READ LOCK. Note that this does not change the fact that FLUSH TABLES WITH READ LOCK prevents concurrent transactions from modifying data as it also blocks all commits.
2009-12-09 16:56:34 +01:00
--error ER_OPTION_PREVENTS_STATEMENT
COMMIT;
connection default;
set global read_only=0;
drop table table_11733 ;
drop user test@localhost;
disconnect con1;
#
# Bug #35732: read-only blocks SELECT statements in InnoDB
#
# Test 1: read only mode
create user test@localhost;
GRANT CREATE, SELECT, DROP ON *.* TO test@localhost;
connect(con1, localhost, test, , test);
connection default;
CREATE TABLE t1(a INT) ENGINE=INNODB;
INSERT INTO t1 VALUES (0), (1);
SET GLOBAL read_only=1;
connection con1;
SELECT * FROM t1;
BEGIN;
SELECT * FROM t1;
COMMIT;
connection default;
SET GLOBAL read_only=0;
#
# Test 2: global read lock
#
FLUSH TABLES WITH READ LOCK;
connection con1;
SELECT * FROM t1;
BEGIN;
SELECT * FROM t1;
COMMIT;
#
# Tests that LOCK TABLE doesn't block the SET READ_ONLY=1 for the InnoDB tables
#
connection default;
UNLOCK TABLES;
connection con1;
lock table t1 read;
connection default;
set global read_only=1;
connection con1;
unlock tables;
connection default;
SET GLOBAL read_only=0;
UNLOCK TABLES;
DROP TABLE t1;
DROP USER test@localhost;
disconnect con1;
--echo echo End of 5.1 tests
--echo #
--echo # Bug#33669: Transactional temporary tables do not work under --read-only
--echo #
--disable_warnings
DROP DATABASE IF EXISTS db1;
--enable_warnings
--echo # Setup user and tables
CREATE USER bug33669@localhost;
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT) ENGINE=INNODB;
CREATE TABLE db1.t2 (a INT) ENGINE=INNODB;
INSERT INTO db1.t1 VALUES (1);
INSERT INTO db1.t2 VALUES (2);
GRANT CREATE TEMPORARY TABLES, DROP, INSERT, DELETE, UPDATE,
SELECT, LOCK TABLES ON db1.* TO bug33669@localhost;
SET GLOBAL READ_ONLY = ON;
connect(con1,localhost,bug33669,,db1);
--echo
--echo # Create, insert and drop temporary table:
--echo
CREATE TEMPORARY TABLE temp (a INT) ENGINE=INNODB;
INSERT INTO temp VALUES (1);
DROP TABLE temp;
--echo
--echo # Lock base tables and use temporary table:
--echo
CREATE TEMPORARY TABLE temp (a INT) ENGINE=INNODB;
LOCK TABLES t1 READ, t2 READ;
SELECT * FROM t1;
INSERT INTO temp values (1);
SELECT * FROM t2;
UNLOCK TABLES;
DROP TABLE temp;
--echo
--echo # Transaction
--echo
BEGIN;
SELECT * FROM t1;
CREATE TEMPORARY TABLE temp (a INT) ENGINE=INNODB;
--error ER_OPTION_PREVENTS_STATEMENT
INSERT INTO t1 VALUES (1);
INSERT INTO temp VALUES (1);
SELECT * FROM t2;
ROLLBACK;
SELECT * FROM temp;
DROP TABLE temp;
--echo
--echo # Lock base table as READ and temporary table as WRITE:
--echo
CREATE TEMPORARY TABLE temp (a INT) ENGINE=INNODB;
LOCK TABLES t1 READ, temp WRITE;
SELECT * FROM t1;
SELECT * FROM temp;
--error ER_OPTION_PREVENTS_STATEMENT
INSERT INTO t1 VALUES (1);
INSERT INTO temp VALUES (1);
DROP TABLE temp;
UNLOCK TABLES;
--echo
--echo # Lock temporary table that shadows a base table:
--echo
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=INNODB;
LOCK TABLES t1 WRITE;
DROP TABLE t1;
--error ER_TABLE_NOT_LOCKED
SELECT * FROM t1;
--echo
--echo # INSERT SELECT from base table into temporary table:
--echo
CREATE TEMPORARY TABLE temp1 (a INT) ENGINE=INNODB;
CREATE TEMPORARY TABLE temp2 LIKE temp1;
BEGIN;
INSERT INTO temp1 VALUES (10);
INSERT INTO temp2 VALUES (10);
INSERT INTO temp1 SELECT * FROM t1;
INSERT INTO temp2 SELECT * FROM t2;
SELECT * FROM temp1 ORDER BY a;
SELECT * FROM temp2 ORDER BY a;
ROLLBACK;
SELECT * FROM temp1,temp2;
LOCK TABLES t1 READ, t2 READ;
INSERT INTO temp1 VALUES (10);
INSERT INTO temp2 VALUES (10);
INSERT INTO temp1 SELECT * FROM t1;
INSERT INTO temp2 SELECT * FROM t2;
SELECT * FROM temp1 ORDER BY a;
SELECT * FROM temp2 ORDER BY a;
UNLOCK TABLES;
DELETE temp1, temp2 FROM temp1, temp2;
INSERT INTO temp1 VALUES (10);
INSERT INTO temp2 VALUES (10);
INSERT INTO temp1 SELECT * FROM t1;
INSERT INTO temp2 SELECT * FROM t2;
SELECT * FROM temp1 ORDER BY a;
SELECT * FROM temp2 ORDER BY a;
DROP TABLE temp1, temp2;
--echo
--echo # INSERT and INSERT SELECT that uses subqueries:
CREATE TEMPORARY TABLE temp1 (a INT) ENGINE=INNODB;
CREATE TEMPORARY TABLE temp2 LIKE temp1;
INSERT INTO temp1 (a) VALUES ((SELECT MAX(a) FROM t1));
LOCK TABLES t2 READ;
INSERT INTO temp2 (a) VALUES ((SELECT MAX(a) FROM t2));
UNLOCK TABLES;
LOCK TABLES t1 READ, t2 READ;
INSERT INTO temp1 SELECT * FROM t1 WHERE a < (SELECT MAX(a) FROM t2);
INSERT INTO temp2 SELECT * FROM t2 WHERE a > (SELECT MAX(a) FROM t1);
UNLOCK TABLES;
INSERT INTO temp1 SELECT * FROM t1 WHERE a < (SELECT MAX(a) FROM t2);
INSERT INTO temp2 SELECT * FROM t2 WHERE a > (SELECT MAX(a) FROM t1);
SELECT * FROM temp1 ORDER BY a;
SELECT * FROM temp2 ORDER BY a;
DROP TABLE temp1, temp2;
--echo
--echo # Multiple table update:
--echo
CREATE TEMPORARY TABLE temp1 (a INT) ENGINE=INNODB;
CREATE TEMPORARY TABLE temp2 LIKE temp1;
INSERT INTO temp1 VALUES (1),(2);
INSERT INTO temp2 VALUES (3),(4);
UPDATE temp1,temp2 SET temp1.a = 5, temp2.a = 10;
SELECT * FROM temp1, temp2;
DROP TABLE temp1, temp2;
--echo
--echo # Disconnect and cleanup
--echo
disconnect con1;
connection default;
SET GLOBAL READ_ONLY = OFF;
DROP USER bug33669@localhost;
DROP DATABASE db1;