mirror of
https://github.com/MariaDB/server.git
synced 2025-07-28 06:04:59 +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
80 lines
2.6 KiB
Text
80 lines
2.6 KiB
Text
--source include/have_innodb.inc
|
|
--source include/have_debug_sync.inc
|
|
|
|
--source include/innodb_stable_estimates.inc
|
|
|
|
--disable_query_log
|
|
call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
|
|
--enable_query_log
|
|
|
|
CREATE TABLE t1 (
|
|
pk INT,
|
|
f1 VARCHAR(10) NOT NULL,
|
|
f2 VARCHAR(10) NULL,
|
|
f3 INT UNSIGNED NULL,
|
|
KEY (f1),
|
|
PRIMARY KEY (pk)
|
|
) ENGINE=InnoDB;
|
|
|
|
CREATE OR REPLACE ALGORITHM=MERGE VIEW v4 AS SELECT * FROM t1;
|
|
INSERT INTO t1 VALUES (1,'k','g',6),(2,'y','r',0),(3,'t','q',1),(4,'a','r',NULL),(5,'z','t',NULL);
|
|
|
|
CREATE TABLE t2 (f VARCHAR(10) NULL) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (NULL),('g'),('e'),('g');
|
|
|
|
CREATE TABLE t3 (
|
|
f1 VARCHAR(10) NOT NULL,
|
|
f2 VARCHAR(10) NULL,
|
|
f3 INT UNSIGNED NULL
|
|
) ENGINE=InnoDB;
|
|
|
|
INSERT INTO t3 VALUES ('k','n',9),('y','b',8),('m','w',6);
|
|
|
|
CREATE TABLE t4 (f INT NULL) ENGINE=InnoDB;
|
|
INSERT INTO t4 VALUES (8),(9);
|
|
UPDATE t1 SET t1.pk = -109 WHERE t1.f1 IN ( SELECT 'a' FROM t4 WHERE f >= 1 );
|
|
SET DEBUG_SYNC='now SIGNAL con1_dml';
|
|
|
|
--connect (con1,localhost,root,,test)
|
|
SET DEBUG_SYNC='now WAIT_FOR con1_dml';
|
|
begin;
|
|
SELECT * FROM t1 for update; # Holds x lock of all records in the table t1
|
|
SET DEBUG_SYNC='now SIGNAL default_dml';
|
|
SET DEBUG_SYNC='now SIGNAL con2_dml';
|
|
|
|
--connection default
|
|
SET DEBUG_SYNC='now WAIT_FOR default_dml';
|
|
--replace_column 9 #
|
|
explain UPDATE t3 AS alias1 LEFT JOIN t3 AS alias2 ON ( alias1.f1 <> alias1.f2 ) SET alias1.f3 = 59 WHERE ( EXISTS ( SELECT t1.f3 FROM t1 IGNORE INDEX (f1) WHERE t1.f1 = alias1.f1 ) ) OR alias2.f1 = 'h';
|
|
--send UPDATE t3 AS alias1 LEFT JOIN t3 AS alias2 ON ( alias1.f1 <> alias1.f2 ) SET alias1.f3 = 59 WHERE ( EXISTS ( SELECT t1.f3 FROM t1 IGNORE INDEX (f1) WHERE t1.f1 = alias1.f1 ) ) OR alias2.f1 = 'h'
|
|
# It holds the lock of all record in t3 and tries to acquire record lock for the table t1.
|
|
|
|
--connect (con2,localhost,root,,test)
|
|
set debug_sync='now WAIT_FOR con2_dml';
|
|
let $wait_condition=
|
|
select count(*) > 0 from information_schema.innodb_lock_waits;
|
|
--source include/wait_condition.inc
|
|
SET DEBUG_SYNC='now SIGNAL con1_dml2';
|
|
disconnect con2;
|
|
|
|
# Cleanup
|
|
--connection con1
|
|
SET DEBUG_SYNC='now WAIT_FOR con1_dml2';
|
|
--replace_column 9 #
|
|
explain UPDATE v4, t1 SET t1.pk = 76 WHERE t1.f2 IN ( SELECT t2.f FROM t2 INNER JOIN t3 );
|
|
UPDATE v4, t1 SET t1.pk = 76 WHERE t1.f2 IN ( SELECT t2.f FROM t2 INNER JOIN t3 );
|
|
# It holds the record lock on table t1 and tries to acquire record lock on t3.
|
|
# leads to deadlock (con1 trx is waiting for default trx and vice versa)
|
|
|
|
--connection default
|
|
--error ER_LOCK_DEADLOCK
|
|
--reap
|
|
|
|
connection con1;
|
|
COMMIT;
|
|
disconnect con1;
|
|
|
|
--connection default
|
|
DROP VIEW v4;
|
|
DROP TABLE t1, t2, t3, t4;
|
|
set debug_sync= reset;
|