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/xa_prepare_unlock_unmodified.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

97 lines
3.2 KiB
Plaintext

--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_sequence.inc
SET @old_innodb_enable_xap_unlock_unmodified_for_primary_debug=
@@GLOBAL.innodb_enable_xap_unlock_unmodified_for_primary_debug;
SET GLOBAL innodb_enable_xap_unlock_unmodified_for_primary_debug= 1;
# Make sure there is no dynamic memory allocation during getting offsets for
# 32 columns of secondary index with 32 columns of primary index in
# lock_rec_unlock_unmodified().
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE c TEXT DEFAULT(
SELECT CONCAT(
'CREATE TABLE t1(pk',
GROUP_CONCAT(seq SEPARATOR ' INT, pk'), ' INT, a',
GROUP_CONCAT(seq SEPARATOR ' INT, a'), ' INT, b',
GROUP_CONCAT(seq SEPARATOR ' INT, b'), ' INT, c INT, PRIMARY KEY(pk',
GROUP_CONCAT(seq SEPARATOR ', pk'), '), INDEX i1(a',
GROUP_CONCAT(seq SEPARATOR ', a'), '), INDEX i2(b',
GROUP_CONCAT(seq SEPARATOR ', b'), ')) ENGINE=InnoDB;')
FROM seq_1_to_32);
EXECUTE IMMEDIATE c;
END;
$$
BEGIN NOT ATOMIC
DECLARE c TEXT DEFAULT(
SELECT CONCAT(
'INSERT INTO t1 VALUES (',
GROUP_CONCAT('1' SEPARATOR ','), ',',
GROUP_CONCAT('1' SEPARATOR ','), ',',
GROUP_CONCAT('1' SEPARATOR ','), ',0), (',
GROUP_CONCAT('2' SEPARATOR ','), ',',
GROUP_CONCAT('1' SEPARATOR ','), ',',
GROUP_CONCAT('2' SEPARATOR ','), ',0), (',
GROUP_CONCAT('3' SEPARATOR ','), ',',
GROUP_CONCAT('2' SEPARATOR ','), ',',
GROUP_CONCAT('1' SEPARATOR ','), ',0), (',
GROUP_CONCAT('4' SEPARATOR ','), ',',
GROUP_CONCAT('2' SEPARATOR ','), ',',
GROUP_CONCAT('2' SEPARATOR ','), ',0);')
FROM seq_1_to_32);
EXECUTE IMMEDIATE c;
END;
$$
DELIMITER ;$$
SET @old_timeout= @@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout= 1;
XA START "t1";
UPDATE t1 FORCE INDEX (i2) SET c=c+1 WHERE a1=1 AND b1=1;
XA END "t1";
# If there is dynamic memory allocation during getting offsets for
# 32 columns of secondary index with 32 columns of primary index in
# lock_rec_unlock_unmodified(), the following statement will cause assertion
# failure in debug build.
XA PREPARE "t1";
--connect(con1,localhost,root,,)
# (pk, 2, 1, 0) record is X-locked but not modified in clustered index with the
# above XA transaction, if the bug is not fixed, the following SELECT will be
# blocked by the XA transaction if XA PREPARE does not release the unmodified
# record.
SELECT a1, b1, c FROM t1 FORCE INDEX (i1) WHERE a1=2 AND b1=1 FOR UPDATE;
--disconnect con1
--connection default
XA COMMIT "t1";
SET GLOBAL innodb_enable_xap_unlock_unmodified_for_primary_debug=
@old_innodb_enable_xap_unlock_unmodified_for_primary_debug;
SET GLOBAL innodb_lock_wait_timeout= @old_timeout;
# Check that we can't create secondary index with more than 32 columns.
DELIMITER $$;
--error ER_TOO_MANY_KEY_PARTS
BEGIN NOT ATOMIC
DECLARE c TEXT DEFAULT(
SELECT CONCAT(
'ALTER TABLE t1 ADD COLUMN d',
GROUP_CONCAT(seq SEPARATOR ' INT, ADD COLUMN d'),
' INT, ADD INDEX i3(d',
GROUP_CONCAT(seq SEPARATOR ', d'), ');')
FROM seq_1_to_33);
EXECUTE IMMEDIATE c;
END;
$$
DELIMITER ;$$
DROP TABLE t1;