Bug #115767 The prepared transaction is rollback if sql_log_bin = off
Submitted: 5 Aug 2024 9:35 Modified: 5 Aug 2024 10:21
Reporter: Zhang JiYang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: XA transactions Severity:S2 (Serious)
Version:8.0.39 OS:Any
Assigned to: CPU Architecture:Any

[5 Aug 2024 9:35] Zhang JiYang
Description:
When binlog is the Transaction Coordinator and sql_log_bin is set as false for some reasons, the prepared transaction will be rollbacked after restarting.

I think that the state of such a prepared transaction is "TRX_UNDO_PREPARED" instead of "TRX_UNDO_PREPARED_IN_TC" because trx_set_prepared_in_tc is not called. And also, the "XA PREPARE"  event is not written. So recovery will rollback such a transaction.

How to repeat:
file mysql-test/demo_test-master.opt
--log-bin=binlog

file mysql-test/demo_test.test
create table t1 (id int);

set sql_log_bin = 0;
xa start '1';
insert into t1 values (1);
xa end '1';
xa prepare '1';

xa recover;
--let $reocver = query_get_value(xa recover, formatID, 1)
--let $assert_text= The prepare state should not be lost after XA PREPARE succeeds
--let $assert_cond= "$reocver" = 1
--source include/assert.inc

--source include/kill_and_restart_mysqld.inc
xa recover;
--let $reocver = query_get_value(xa recover, formatID, 1)
--let $assert_text= The prepare state should not be lost after XA PREPARE succeeds
--let $assert_cond= "$reocver" = 1
--source include/assert.inc
[5 Aug 2024 10:21] MySQL Verification Team
Hello zanye zjy,

Thank you for the report and test case.

regards,
Umesh