mariadb/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.test
Andrei 388296a1e6 MDEV-32257 dangling XA-rollback in binlog from emtpy XA in pseudo_slave_mode
In `pseudo_slave_mode=1` aka "psedo-slave" mode any prepared XA
transaction disconnects from the user session, as if the user
connection drops. The xid of such transaction remains in the server,
and should the prepared transaction be read-only, it is marked.
The marking makes sure that the following termination of the
read-only transaction  ends up with ER_XA_RBROLLBACK.
This did not take place actually for  `pseudo_slave_mode=1` read-only.

Fixed with checking the read-only status of a prepared transaction
at time it disconnects from the `pseudo_slave_mode=1` session, to mark
its xid when that's the case.
2023-09-29 15:54:09 +03:00

148 lines
3.5 KiB
Text

# 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
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';
--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);
--source include/count_sessions.inc
--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;
--source include/count_sessions.inc
--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