1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00
Files
mariadb/mysql-test/suite/innodb/t/innodb_i_s_innodb_trx.test
Sergei Golubchik bead24b7f3 mariadb-test: wait on disconnect
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
2025-07-16 09:14:33 +07:00

92 lines
2.2 KiB
Plaintext

--source include/have_innodb.inc
#
# Test that transaction data is correctly "visualized" in
# INFORMATION_SCHEMA.INNODB_TRX
#
SET @save_timeout=@@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout=100000000;
DESCRIBE INFORMATION_SCHEMA.INNODB_TRX;
CREATE TABLE t1 (
c01 INT,
c02 INT,
PRIMARY KEY (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t1 VALUES
(1,2),(2,4),(3,6),(4,8);
CREATE TABLE t2 (
c01 INT,
c02 INT,
PRIMARY KEY (c01),
FOREIGN KEY fk1 (c02) REFERENCES t1 (c01)
) ENGINE=INNODB STATS_AUTO_RECALC=0;
INSERT INTO t2 VALUES
(1,1),(2,2),(3,3);
-- connect (con_trx,localhost,root,,)
-- connect (con_verify_innodb_trx,localhost,root,,)
-- connection con_trx
SET autocommit=0;
INSERT INTO t1 VALUES (5,10);
SELECT * FROM t1 FOR UPDATE;
let $wait_timeout= 300;
let $wait_condition=
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- connection con_verify_innodb_trx
SELECT trx_state, trx_weight, trx_tables_in_use, trx_tables_locked,
trx_rows_locked, trx_rows_modified, trx_concurrency_tickets,
trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- connection con_trx
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t1 VALUES (6,12);
let $wait_timeout= 300;
let $wait_condition=
SELECT trx_unique_checks = 0 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- connection con_verify_innodb_trx
SELECT trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- connection con_trx
ROLLBACK;
SET FOREIGN_KEY_CHECKS = 1;
SET UNIQUE_CHECKS = 1;
BEGIN;
--error ER_NO_REFERENCED_ROW_2
INSERT INTO t2 VALUES (4,10);
let $wait_timeout= 300;
let $wait_condition=
SELECT trx_unique_checks = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
-- source include/wait_condition.inc
-- disconnect con_trx
-- connection con_verify_innodb_trx
SELECT trx_state, trx_isolation_level, trx_last_foreign_key_error
FROM INFORMATION_SCHEMA.INNODB_TRX;
-- disconnect con_verify_innodb_trx
-- connection default
DROP TABLE t2;
DROP TABLE t1;
SET GLOBAL innodb_lock_wait_timeout=@save_timeout;