mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03: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
129 lines
4.0 KiB
Plaintext
129 lines
4.0 KiB
Plaintext
SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
|
|
SET @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index;
|
|
SET @old_innodb_stats_persistent = @@innodb_stats_persistent;
|
|
SET GLOBAL innodb_adaptive_hash_index = false;
|
|
SET GLOBAL innodb_stats_persistent = false;
|
|
connect purge_control,localhost,root,,;
|
|
START TRANSACTION WITH CONSISTENT SNAPSHOT;
|
|
connect con2,localhost,root,,;
|
|
CREATE TABLE t1 (
|
|
a00 CHAR(255) NOT NULL DEFAULT 'a',
|
|
a01 CHAR(255) NOT NULL DEFAULT 'a',
|
|
a02 CHAR(255) NOT NULL DEFAULT 'a',
|
|
b INT NOT NULL DEFAULT 0,
|
|
PRIMARY KEY(a00, a01, a02)
|
|
) charset latin1 ENGINE = InnoDB COMMENT='MERGE_THRESHOLD=45';
|
|
SET GLOBAL innodb_limit_optimistic_insert_debug = 3;
|
|
CREATE PROCEDURE data_load_t1()
|
|
BEGIN
|
|
DECLARE c1 INT DEFAULT 97;
|
|
DECLARE c2 INT DEFAULT 97;
|
|
DECLARE c3 INT DEFAULT 97;
|
|
WHILE c1 < 102 DO
|
|
WHILE c2 < 123 DO
|
|
WHILE c3 < 123 DO
|
|
INSERT INTO t1 (a00) VALUES (CHAR(c1,c2,c3));
|
|
SET c3 = c3 + 1;
|
|
END WHILE;
|
|
SET c3 = 97;
|
|
SET c2 = c2 + 1;
|
|
END WHILE;
|
|
SET c2 = 97;
|
|
SET c1 = c1 + 1;
|
|
END WHILE;
|
|
END |
|
|
call data_load_t1();
|
|
DROP PROCEDURE data_load_t1;
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
|
|
CLUST_INDEX_SIZE
|
|
1792
|
|
connection con2;
|
|
DELETE FROM t1 WHERE a00 = 'cnm';
|
|
COMMIT;
|
|
BEGIN;
|
|
INSERT INTO t1 SET a00 = 'cnm';
|
|
connection purge_control;
|
|
COMMIT;
|
|
connection con2;
|
|
SET GLOBAL innodb_limit_optimistic_insert_debug = 0;
|
|
ROLLBACK;
|
|
# Test start
|
|
connection purge_control;
|
|
START TRANSACTION WITH CONSISTENT SNAPSHOT;
|
|
connection con2;
|
|
DELETE FROM t1 WHERE a00 = 'bii';
|
|
COMMIT;
|
|
BEGIN;
|
|
INSERT INTO t1 SET a00 = 'bii';
|
|
SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2';
|
|
SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume';
|
|
ROLLBACK;
|
|
connection purge_control;
|
|
SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait';
|
|
COMMIT;
|
|
SET DEBUG_SYNC = 'now SIGNAL roll2';
|
|
connect con1,localhost,root,,;
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
|
|
SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait1';
|
|
SELECT a00 FROM t1 WHERE a00 = 'bii';
|
|
connection default;
|
|
SET DEBUG_SYNC = 'now WAIT_FOR lockwait1 TIMEOUT 1';
|
|
SET DEBUG_SYNC = 'now SIGNAL resume';
|
|
connection con1;
|
|
a00
|
|
connection con2;
|
|
connection default;
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
|
|
CLUST_INDEX_SIZE
|
|
1792
|
|
DELETE FROM t1 WHERE a00 = 'dpn';
|
|
COMMIT;
|
|
INSERT INTO t1 SET a00 = 'dpn';
|
|
ROLLBACK;
|
|
ALTER TABLE t1 COMMENT='MERGE_THRESHOLD=35';
|
|
connection purge_control;
|
|
START TRANSACTION WITH CONSISTENT SNAPSHOT;
|
|
connection con2;
|
|
DELETE FROM t1 WHERE a00 = 'cnd';
|
|
COMMIT;
|
|
BEGIN;
|
|
INSERT INTO t1 SET a00 = 'cnd';
|
|
SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2';
|
|
SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume EXECUTE 2';
|
|
ROLLBACK;
|
|
connection purge_control;
|
|
SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait';
|
|
START TRANSACTION WITH CONSISTENT SNAPSHOT;
|
|
SET DEBUG_SYNC = 'now SIGNAL roll2';
|
|
connection con1;
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
|
|
SET DEBUG_SYNC = 'now SIGNAL resume';
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
|
|
disconnect purge_control;
|
|
connection default;
|
|
SET DEBUG_SYNC = 'now SIGNAL resume';
|
|
disconnect con1;
|
|
connection con2;
|
|
disconnect con2;
|
|
connection default;
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
|
|
CLUST_INDEX_SIZE
|
|
1792
|
|
SET DEBUG_SYNC = 'RESET';
|
|
DROP TABLE t1;
|
|
SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug;
|
|
SET GLOBAL innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index;
|
|
SET GLOBAL innodb_stats_persistent = @old_innodb_stats_persistent;
|