1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00
Files
mariadb/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.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

184 lines
4.3 KiB
Plaintext

# The test verifies execution and binary logging of user XA that produce empty
# XA-PREPARE group of events.
--source include/have_binlog_format_mixed.inc
--source include/have_innodb.inc
--source include/count_sessions.inc
RESET MASTER; # clear binlogs
# MDEV-22420 DDL on temporary object is prohibited when XA is in prepare state
# Temporary sequence may not be created within a transaction
CREATE TEMPORARY SEQUENCE seq_1;
XA START '3';
CREATE TEMPORARY TABLE tmp_1(c INT);
XA END '3';
XA PREPARE '3';
--error ER_XAER_RMFAIL
DROP TEMPORARY TABLE tmp_1;
--error ER_XAER_RMFAIL
ALTER TABLE tmp_1 DROP COLUMN c;
--error ER_XAER_RMFAIL
DROP TEMPORARY SEQUENCE seq_1;
--error ER_XAER_RMFAIL
ALTER SEQUENCE seq_1 INCREMENT BY 1;
--error ER_XAER_RMFAIL
CREATE TEMPORARY TABLE tmp_2(c INT);
--error ER_XAER_RMFAIL
CREATE TEMPORARY SEQUENCE seq_2;
# Cleanup
XA ROLLBACK '3';
DROP SEQUENCE seq_1;
DROP TABLE tmp_1;
--echo # Proof of correct logging incl empty XA-PREPARE
--source include/show_binlog_events.inc
SET @@binlog_format="statement";
RESET MASTER; # clear binlogs
# MDEV-22420 DDL on temporary object is prohibited when XA is in prepare state
# Temporary sequnce may not be created within a transaction
CREATE TEMPORARY SEQUENCE seq_1;
XA START '3';
CREATE TEMPORARY TABLE tmp_1(c INT);
XA END '3';
XA PREPARE '3';
--error ER_XAER_RMFAIL
DROP TEMPORARY TABLE tmp_1;
--error ER_XAER_RMFAIL
ALTER TABLE tmp_1 DROP COLUMN c;
--error ER_XAER_RMFAIL
DROP TEMPORARY SEQUENCE seq_1;
--error ER_XAER_RMFAIL
ALTER SEQUENCE seq_1 INCREMENT BY 1;
--error ER_XAER_RMFAIL
CREATE TEMPORARY TABLE tmp_2(c INT);
--error ER_XAER_RMFAIL
CREATE TEMPORARY SEQUENCE seq_2;
# Cleanup
XA ROLLBACK '3';
SET @@binlog_format="mixed";
--echo # Proof of correct logging incl empty XA-PREPARE
--source include/show_binlog_events.inc
# The test verifies execution and binary logging of user XA that produce empty
# XA-PREPARE group of events.
#
# MDEV-22757 Assertion `!binlog || exist_hton_without_prepare'
# in MYSQL_BIN_LOG::unlog_xa_prepare
RESET MASTER;
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
CREATE TABLE t2 (id INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
INSERT INTO t2 VALUES (1),(2);
XA START '1';
REPLACE INTO t1 SELECT * FROM t1;
REPLACE INTO t2 SELECT * FROM t2;
XA END '1';
XA PREPARE '1';
# Cleanup
XA ROLLBACK '1';
DROP TABLE t1, t2;
--echo # Proof of correct logging incl empty XA-PREPARE
--source include/show_binlog_events.inc
# MDEV-22430 Assertion ... in MYSQL_BIN_LOG::unlog_xa_prepare
RESET MASTER;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
CREATE SEQUENCE s ENGINE=InnoDB;
XA START '2';
--disable_ps2_protocol
SELECT NEXT VALUE FOR s;
--enable_ps2_protocol
REPLACE INTO t1 SELECT * FROM t1;
XA END '2';
XA PREPARE '2';
# Cleanup
XA ROLLBACK '2';
DROP SEQUENCE s;
DROP TABLE t1;
--echo # Proof of correct logging incl empty XA-PREPARE
--source include/show_binlog_events.inc
# MDEV-25616 Binlog event for XA COMMIT is generated without matching XA START
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
--connect(con1,localhost,root,,)
XA START '1';
--error ER_DUP_ENTRY
INSERT INTO t1 VALUES (2),(1);
SELECT * FROM t1 WHERE a = 2;
XA END '1';
XA PREPARE '1';
--disconnect con1
--connection default
--source include/wait_until_count_sessions.inc
XA RECOVER;
--error ER_XA_RBROLLBACK
XA COMMIT '1';
--echo Must be no XA PREPARE group nor XA completion one:
--source include/show_binlog_events.inc
DROP TABLE t1;
--connect(con2,localhost,root,,)
CREATE TABLE tm (a INT PRIMARY KEY) ENGINE=MyISAM;
XA START '1';
--error ER_DUP_ENTRY
INSERT INTO tm VALUES (1),(1);
SELECT * FROM tm WHERE a = 2;
XA END '1';
XA PREPARE '1';
--disconnect con2
--connection default
--source include/wait_until_count_sessions.inc
XA RECOVER;
--error ER_XA_RBROLLBACK
XA ROLLBACK '1';
--echo Must be no XA PREPARE group nor XA completion one:
--source include/show_binlog_events.inc
DROP TABLE tm;
# MDEV-32257 dangling XA-rollback in binlog from emtpy XA
--connection default
--let $binlog_start = query_get_value(SHOW MASTER STATUS, Position, 1)
--let $binlog_file = query_get_value(SHOW MASTER STATUS, File, 1)
SET pseudo_slave_mode=1;
XA START 'a';
XA END 'a';
XA PREPARE 'a';
--error ER_XA_RBROLLBACK
XA ROLLBACK 'a';
--source include/show_binlog_events.inc