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
73 lines
2.2 KiB
Text
73 lines
2.2 KiB
Text
--source include/have_innodb.inc
|
|
--source include/have_debug.inc
|
|
|
|
CREATE TABLE t (
|
|
`a` INT NOT NULL,
|
|
`b` INT NOT NULL,
|
|
PRIMARY KEY (`a`)
|
|
) ENGINE=InnoDB;
|
|
|
|
--disable_query_log
|
|
SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
|
|
--enable_query_log
|
|
|
|
SET GLOBAL innodb_limit_optimistic_insert_debug = 3;
|
|
|
|
INSERT INTO t VALUES(10, 0);
|
|
INSERT INTO t VALUES(20, 0);
|
|
INSERT INTO t VALUES(30, 0);
|
|
|
|
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
|
|
XA START '1';
|
|
REPLACE INTO t VALUES(10, 1);
|
|
REPLACE INTO t VALUES(20, 1);
|
|
|
|
# We need the following sync point because mysql_insert() resets
|
|
# trx->duplicates with the following condition:
|
|
#
|
|
# if (duplic == DUP_REPLACE &&
|
|
# (!table->triggers || !table->triggers->has_delete_triggers()))
|
|
# table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
|
|
#
|
|
# and ha_innobase::extra() resets trx_t::duplicates, but we need
|
|
# lock_update_split_right() to be invoked when trx->duplicates is set to
|
|
# repeat the bug. So the transaction will hang just after
|
|
# row_insert_for_mysql() call until another transaction inserts new row and
|
|
# splits the page.
|
|
SET DEBUG_SYNC= 'ib_after_row_insert SIGNAL inserted WAIT_FOR cont';
|
|
--send REPLACE INTO t VALUES(30, 1)
|
|
|
|
connect (con1,localhost,root);
|
|
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
|
|
XA START '2';
|
|
SET DEBUG_SYNC= 'now WAIT_FOR inserted';
|
|
# The following statement will cause page split and (20, ...) will be split
|
|
# record. As the previous REPLACE set non-gap X-lock on it,
|
|
# lock_update_split_right() and lock_rec_inherit_to_gap() will 'inherit' the
|
|
# lock from the very first (20, ...) new right page record to the supremum of
|
|
# the old left page, what should not be for READ COMMITTED isolation level
|
|
INSERT INTO t VALUES(40, 2);
|
|
SET DEBUG_SYNC= 'now SIGNAL cont';
|
|
|
|
--connection default
|
|
--reap
|
|
XA END '1';
|
|
# This will cause the assertion failure, because the supremum of the left page
|
|
# has X-lock.
|
|
XA PREPARE '1';
|
|
--connection default
|
|
XA COMMIT '1';
|
|
|
|
--connection con1
|
|
XA END '2';
|
|
XA PREPARE '2';
|
|
XA COMMIT '2';
|
|
--disconnect con1
|
|
|
|
--connection default
|
|
SET DEBUG_SYNC= "RESET";
|
|
DROP TABLE t;
|
|
|
|
--disable_query_log
|
|
SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug;
|
|
--enable_query_log
|