mirror of
https://github.com/MariaDB/server.git
synced 2025-08-12 13:31:36 +02:00

Remove one of the major sources of race condiitons in mariadb-test. Normally, mariadb_close() sends COM_QUIT to the server and immediately disconnects. In mariadb-test it means the test can switch to another connection and sends queries to the server before the server even started parsing the COM_QUIT packet and these queries can see the connection as fully active, as it didn't reach dispatch_command yet. This is a major source of instability in tests and many - but not all, still less than a half - tests employ workarounds. The correct one is a pair count_sessions.inc/wait_until_count_sessions.inc. Also very popular was wait_until_disconnected.inc, which was completely useless, because it verifies that the connection is closed, and after disconnect it always is, it didn't verify whether the server processed COM_QUIT. Sadly the placebo was as widely used as the real thing. Let's fix this by making mariadb-test `disconnect` command _to wait_ for the server to confirm. This makes almost all workarounds redundant. In some cases count_sessions.inc/wait_until_count_sessions.inc is still needed, though, as only `disconnect` command is changed: * after external tools, like `exec $MYSQL` * after failed `connect` command * replication, after `STOP SLAVE` * Federated/CONNECT/SPIDER/etc after `DROP TABLE` and also in some XA tests, because an XA transaction is dissociated from the THD very late, after the server has closed the client connection. Collateral cleanups: fix comments, remove some redundant statements: * DROP IF EXISTS if nothing is known to exist * DROP table/view before DROP DATABASE * REVOKE privileges before DROP USER etc
421 lines
9.9 KiB
Text
421 lines
9.9 KiB
Text
--source include/have_innodb.inc
|
|
|
|
# Tests will be skipped for the view protocol because the view protocol creates
|
|
# an additional util connection and other statistics data
|
|
-- source include/no_view_protocol.inc
|
|
|
|
# MDEV-254: Server hang with FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT
|
|
FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT;
|
|
UNLOCK TABLES;
|
|
CREATE TABLE t1 ( m MEDIUMTEXT ) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES ( REPEAT('i',65535) );
|
|
|
|
DROP TABLE t1;
|
|
|
|
--echo
|
|
--echo #
|
|
--echo # WL#6168: FLUSH TABLES ... FOR EXPORT -- parser
|
|
--echo #
|
|
--echo
|
|
|
|
--echo # new "EXPORT" keyword is a valid user variable name:
|
|
|
|
SET @export = 10;
|
|
|
|
--echo # new "EXPORT" keyword is a valid SP parameter name:
|
|
|
|
CREATE PROCEDURE p1(export INT) BEGIN END;
|
|
DROP PROCEDURE p1;
|
|
|
|
--echo # new "EXPORT" keyword is a valid local variable name:
|
|
|
|
DELIMITER |;
|
|
CREATE PROCEDURE p1()
|
|
BEGIN
|
|
DECLARE export INT;
|
|
END|
|
|
DELIMITER ;|
|
|
DROP PROCEDURE p1;
|
|
|
|
--echo # new "EXPORT" keyword is a valid SP name:
|
|
|
|
CREATE PROCEDURE export() BEGIN END;
|
|
DROP PROCEDURE export;
|
|
|
|
--echo # new FLUSH TABLES ... FOR EXPORT syntax:
|
|
|
|
--error ER_PARSE_ERROR
|
|
FLUSH TABLES FOR EXPORT;
|
|
--error ER_PARSE_ERROR
|
|
FLUSH TABLES WITH EXPORT;
|
|
|
|
|
|
CREATE TABLE t1 (i INT) engine=InnoDB;
|
|
CREATE TABLE t2 LIKE t1;
|
|
|
|
--error ER_PARSE_ERROR
|
|
FLUSH TABLES t1,t2 WITH EXPORT;
|
|
|
|
FLUSH TABLES t1, t2 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
|
|
--echo # case check
|
|
FLUSH TABLES t1, t2 for ExPoRt;
|
|
UNLOCK TABLES;
|
|
--echo # With LOCAL keyword
|
|
FLUSH LOCAL TABLES t1, t2 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
--echo # Tables with fully qualified names
|
|
FLUSH LOCAL TABLES test.t1, test.t2 for ExPoRt;
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLES t1, t2;
|
|
|
|
--echo # new "EXPORT" keyword is a valid table name:
|
|
|
|
CREATE TABLE export (i INT) engine=InnoDB;
|
|
|
|
--echo # it's ok to lock the "export" table for export:
|
|
|
|
FLUSH TABLE export FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE export;
|
|
|
|
|
|
--echo #
|
|
--echo # WL#6169 FLUSH TABLES ... FOR EXPORT -- runtime
|
|
--echo #
|
|
|
|
--echo # Test 1: Views, temporary tables, non-existent tables
|
|
--echo #
|
|
|
|
CREATE VIEW v1 AS SELECT 1;
|
|
CREATE TEMPORARY TABLE t1 (a INT);
|
|
|
|
FLUSH TABLES v1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
--error ER_NO_SUCH_TABLE
|
|
FLUSH TABLES t1 FOR EXPORT;
|
|
--error ER_NO_SUCH_TABLE
|
|
FLUSH TABLES non_existent FOR EXPORT;
|
|
|
|
DROP TEMPORARY TABLE t1;
|
|
DROP VIEW v1;
|
|
|
|
--echo # Test 2: Blocked by update transactions, blocks updates.
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) engine= InnoDB;
|
|
CREATE TABLE t2 (a INT) engine= InnoDB;
|
|
|
|
--connect (con1, localhost, root)
|
|
START TRANSACTION;
|
|
INSERT INTO t1 VALUES (1, 1);
|
|
|
|
--connection default
|
|
--echo # Should be blocked
|
|
--echo # Sending:
|
|
--send FLUSH TABLES t1 FOR EXPORT
|
|
|
|
--connection con1
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "FLUSH TABLES t1 FOR EXPORT";
|
|
--source include/wait_condition.inc
|
|
COMMIT;
|
|
|
|
--connection default
|
|
--echo # Reaping: FLUSH TABLES t1 FOR EXPORT
|
|
--reap
|
|
|
|
--connection con1
|
|
--echo # Should not be blocked
|
|
INSERT INTO t2 VALUES (1);
|
|
--echo # Should be blocked
|
|
--echo # Sending:
|
|
--send INSERT INTO t1 VALUES (2, 2)
|
|
|
|
--connection default
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "INSERT INTO t1 VALUES (2, 2)";
|
|
--source include/wait_condition.inc
|
|
UNLOCK TABLES;
|
|
|
|
--connection con1
|
|
--echo # Reaping: INSERT INTO t1 VALUES (2, 2);
|
|
--reap
|
|
|
|
--echo # Test 3: Read operations should not be affected.
|
|
--echo #
|
|
|
|
START TRANSACTION;
|
|
SELECT * FROM t1;
|
|
|
|
--connection default
|
|
--echo # Should not be blocked
|
|
FLUSH TABLES t1 FOR EXPORT;
|
|
|
|
--connection con1
|
|
COMMIT;
|
|
--echo # Should not be blocked
|
|
SELECT * FROM t1;
|
|
|
|
--connection default
|
|
UNLOCK TABLES;
|
|
|
|
--echo # Test 4: Blocked by DDL, blocks DDL.
|
|
--echo #
|
|
|
|
START TRANSACTION;
|
|
SELECT * FROM t1;
|
|
|
|
--connect (con2, localhost, root)
|
|
--echo # Sending:
|
|
--send ALTER TABLE t1 ADD INDEX i1(b)
|
|
|
|
--connection con1
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "ALTER TABLE t1 ADD INDEX i1(b)";
|
|
--source include/wait_condition.inc
|
|
--echo # Should be blocked
|
|
--send FLUSH TABLE t1 FOR EXPORT
|
|
|
|
--connection default
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "FLUSH TABLE t1 FOR EXPORT";
|
|
--source include/wait_condition.inc
|
|
COMMIT;
|
|
|
|
--connection con2
|
|
--echo # Reaping ALTER TABLE ...
|
|
--reap
|
|
|
|
--connection con1
|
|
--echo # Reaping FLUSH TABLE t1 FOR EXPORT
|
|
--reap
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
|
|
--connection con2
|
|
--echo # Should be blocked
|
|
--send DROP TABLE t1
|
|
|
|
--connection default
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "DROP TABLE t1";
|
|
--source include/wait_condition.inc
|
|
UNLOCK TABLES;
|
|
|
|
--connection con2
|
|
--echo # Reaping DROP TABLE t1
|
|
--reap
|
|
--disconnect con2
|
|
--connection default
|
|
DROP TABLE t2;
|
|
|
|
--echo # Test 5: Compatibilty with FLUSH TABLES WITH READ LOCK
|
|
--echo #
|
|
|
|
CREATE TABLE t1(a INT) engine= InnoDB;
|
|
FLUSH TABLES WITH READ LOCK;
|
|
|
|
--connection con1
|
|
--echo # This should not block
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
UNLOCK TABLES;
|
|
DROP TABLE t1;
|
|
|
|
--echo # Test 6: Unsupported storage engines.
|
|
--echo #
|
|
|
|
CREATE TABLE t1(a INT) engine= MEMORY;
|
|
--error ER_ILLEGAL_HA
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
DROP TABLE t1;
|
|
|
|
--disconnect con1
|
|
--connection default
|
|
|
|
--echo # Test 7: Check privileges required.
|
|
--echo # in flush-innodb-notembedded.test
|
|
|
|
--echo # Test 8: FLUSH TABLE <table_list> FOR EXPORT is incompatible
|
|
--echo # with itself (to avoid race conditions in metadata
|
|
--echo # file handling).
|
|
--echo #
|
|
|
|
CREATE TABLE t1 (a INT) engine= InnoDB;
|
|
CREATE TABLE t2 (a INT) engine= InnoDB;
|
|
|
|
--connect (con1, localhost, root)
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
|
|
--connection default
|
|
--echo # This should not block
|
|
FLUSH TABLE t2 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
--echo # This should block
|
|
--echo # Sending:
|
|
--send FLUSH TABLE t1 FOR EXPORT
|
|
|
|
--connection con1
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "FLUSH TABLE t1 FOR EXPORT";
|
|
--source include/wait_condition.inc
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
--echo # Reaping: FLUSH TABLE t1 FOR EXPORT
|
|
--reap
|
|
UNLOCK TABLES;
|
|
|
|
--echo # Test 9: LOCK TABLES ... READ is not affected
|
|
--echo #
|
|
|
|
LOCK TABLE t1 READ;
|
|
|
|
--connection con1
|
|
--echo # Should not block
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
UNLOCK TABLES;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
|
|
--connection con1
|
|
--echo # Should not block
|
|
LOCK TABLE t1 READ;
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
UNLOCK TABLES;
|
|
|
|
--disconnect con1
|
|
--connection default
|
|
DROP TABLE t1, t2;
|
|
|
|
--echo # Test 10: Lock is released if transaction is started after doing
|
|
--echo # 'flush table..' in same session
|
|
|
|
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
--echo # error as active locks already exist
|
|
--error ER_LOCK_OR_ACTIVE_TRANSACTION
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
--echo # active locks will be released due to start transaction
|
|
START TRANSACTION;
|
|
--echo # passes as start transaction released ealier locks
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
DROP TABLE t1;
|
|
|
|
--echo # Test 11: Test 'flush table with fully qualified table names
|
|
--echo # and with syntax local/NO_WRITE_TO_BINLOG
|
|
|
|
--connect (con1, localhost, root)
|
|
|
|
--connection default
|
|
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
|
|
INSERT INTO t1 VALUES (100),(200);
|
|
FLUSH LOCAL TABLES test.t1 FOR EXPORT;
|
|
--connection con1
|
|
--echo # Should be blocked
|
|
--echo # Sending:
|
|
--send FLUSH LOCAL TABLES t1 FOR EXPORT
|
|
|
|
--connection default
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "FLUSH LOCAL TABLES t1 FOR EXPORT";
|
|
--source include/wait_condition.inc
|
|
UNLOCK TABLE;
|
|
|
|
--connection con1
|
|
--echo # Reaping: FLUSH LOCAL TABLES t1 FOR EXPORT
|
|
--reap
|
|
SELECT * FROM t1 ORDER BY i;
|
|
|
|
--connection default
|
|
--echo # Should be blocked
|
|
--echo # Sending:
|
|
--send FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT
|
|
|
|
--connection con1
|
|
let $wait_condition=
|
|
SELECT COUNT(*) = 1 FROM information_schema.processlist
|
|
WHERE state = "Waiting for table metadata lock" AND
|
|
info = "FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT";
|
|
--source include/wait_condition.inc
|
|
UNLOCK TABLES;
|
|
|
|
--connection default
|
|
--echo # Reaping: FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT
|
|
--reap
|
|
SELECT * FROM t1 ORDER BY i;
|
|
UNLOCK TABLE;
|
|
DROP TABLE t1;
|
|
|
|
--echo # Test 12: Active transaction get committed if user execute
|
|
--echo # "FLUSH TABLE ... FOR EXPORT" or "LOCK TABLE.."
|
|
|
|
--connection default
|
|
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
|
|
INSERT INTO t1 VALUES (100),(200);
|
|
START TRANSACTION;
|
|
INSERT INTO t1 VALUES (300);
|
|
--echo # 'flush table..' commit active transaction from same session
|
|
FLUSH LOCAL TABLES test.t1 FOR EXPORT;
|
|
ROLLBACK;
|
|
SELECT * FROM t1 ORDER BY i;
|
|
START TRANSACTION;
|
|
INSERT INTO t1 VALUES (400);
|
|
--echo # 'lock table ..' commit active transaction from same session
|
|
LOCK TABLES test.t1 READ;
|
|
ROLLBACK;
|
|
SELECT * FROM t1 ORDER BY i;
|
|
UNLOCK TABLES;
|
|
DROP TABLE t1;
|
|
|
|
--echo # Test 13: Verify "FLUSH TABLE ... FOR EXPORT" and "LOCK TABLE.."
|
|
--echo # in same session
|
|
|
|
--connection default
|
|
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
|
|
--echo # Lock table
|
|
LOCK TABLES test.t1 WRITE;
|
|
--echo # 'lock table ..' completes even if table lock is acquired
|
|
--echo # in same session using 'lock table'. Previous locks are released.
|
|
LOCK TABLES test.t1 READ;
|
|
--echo # 'flush table ..' gives error if table lock is acquired
|
|
--echo # in same session using 'lock table ..'
|
|
--error ER_LOCK_OR_ACTIVE_TRANSACTION
|
|
FLUSH TABLES test.t1 FOR EXPORT;
|
|
--echo # 'lock table ..' completes even if table lock is acquired
|
|
--echo # in same session using 'flush table'. Previous locks are released.
|
|
LOCK TABLES test.t1 WRITE;
|
|
UNLOCK TABLES;
|
|
DROP TABLE t1;
|
|
|
|
--disconnect con1
|
|
--connection default
|
|
|
|
--echo # End of 5.6 tests
|