diff --git a/mysql-test/suite/binlog/r/binlog_empty_xa_prepared.result b/mysql-test/suite/binlog/r/binlog_empty_xa_prepared.result index b11484367b8..4625a6cab21 100644 --- a/mysql-test/suite/binlog/r/binlog_empty_xa_prepared.result +++ b/mysql-test/suite/binlog/r/binlog_empty_xa_prepared.result @@ -217,3 +217,11 @@ master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO tm VALUES (1),(1) master-bin.000001 # Query # # COMMIT DROP TABLE tm; +connection default; +SET pseudo_slave_mode=1; +XA START 'a'; +XA END 'a'; +XA PREPARE 'a'; +XA ROLLBACK 'a'; +ERROR XA100: XA_RBROLLBACK: Transaction branch was rolled back +include/show_binlog_events.inc diff --git a/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.test b/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.test index 52b4ad2037b..501403f46fc 100644 --- a/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.test +++ b/mysql-test/suite/binlog/t/binlog_empty_xa_prepared.test @@ -134,3 +134,15 @@ XA ROLLBACK '1'; --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 diff --git a/sql/xa.cc b/sql/xa.cc index 52b9cf4c857..9df9da7acf1 100644 --- a/sql/xa.cc +++ b/sql/xa.cc @@ -1141,6 +1141,11 @@ static bool slave_applier_reset_xa_trans(THD *thd) ~(SERVER_STATUS_IN_TRANS | SERVER_STATUS_IN_TRANS_READONLY); DBUG_PRINT("info", ("clearing SERVER_STATUS_IN_TRANS")); + if (thd->variables.pseudo_slave_mode && + !thd->transaction->all.is_trx_read_write()) + { + thd->transaction->xid_state.set_error(ER_XA_RBROLLBACK); + } thd->transaction->xid_state.xid_cache_element->acquired_to_recovered(); thd->transaction->xid_state.xid_cache_element= 0;