Bug #98877 Binary log rotate not wait for xa prepare and xa commit to finish
Submitted: 9 Mar 2020 12:34 Modified: 9 Mar 2020 12:49
Reporter: dennis GAO (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: XA transactions Severity:S3 (Non-critical)
Version:5.7.25, 5.7.29, 8.0.19 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[9 Mar 2020 12:34] dennis GAO
Description:
In current mysql code, mysql will not do inc_prep_xids for xa prepare and xa commit, so that the MYSQL_BIN_LOG::new_file_impl will not waiting for xa prepre and xa commit to finish the engine operation.

How to repeat:
Set up a mysql with the following config:

[mysqld]
  gdb 
  port = 5723
  basedir=/home/gaoxiaoxin/mysql-repo/mysql-5.7.25/install_debug/
  datadir=/home/gaoxiaoxin/mysql-repo/mysql-5.7.25/install_debug/data
  socket=/home/gaoxiaoxin/mysql-repo/mysql-5.7.25/install_debug/data/my.sock
  log-bin
  server-id=1
  transaction-isolation = READ-COMMITTED
  gtid-mode              = on    
  enforce-gtid-consistency

Then do the following test steps:

mysql> use test
mysql> create table t1 (c1 int)engine=innodb;
mysql> INSTALL PLUGIN RPL_SEMI_SYNC_MASTER SONAME 'semisync_master.so';
mysql> INSTALL PLUGIN RPL_SEMI_SYNC_SLAVE SONAME 'semisync_slave.so';
mysql> SET GLOBAL RPL_SEMI_SYNC_MASTER_ENABLED = 1;
mysql> set global rpl_semi_sync_master_timeout=100000;
mysql> xa start '1';
mysql> insert into t1 values (1);
mysql> xa end '1';
mysql> xa prepare '1';                 <---------------block due to semi-sync

Then open a new client to login, and execute:
mysql> flush logs;   <--------------------will not be blocked

For xa commit is similar.

Suggested fix:
1. add with_xa_prepare and with_xa_commit flag for binlog_cache_data::flags
2. do inc_prep_xids for with_xa_prepare and with_xa_commit flag

Patch will provide later.
[9 Mar 2020 12:39] dennis GAO
adding the patch as contribution

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: xa_prepare_xa_commit_binlog_rotate-v1.diff (text/x-patch), 2.97 KiB.

[9 Mar 2020 12:49] MySQL Verification Team
Hello dennis GAO,

Thank you for the report and contribution.
Observed with 5.7.29 build with provided test case.

regards,
Umesh
[12 Mar 2020 5:18] dennis GAO
adding the patch as contribution to also fix for xa rollback

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: xa_prepare_xa_commit_xa_rollback_binlog_rotate-v2.diff (text/x-patch), 3.54 KiB.