Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-36970

Serious binglog replay data inconsistency when using XA with a temporary table

    XMLWordPrintable

Details

    Description

      If we start a server with --log-bin (with MIXED as the default format) and execute the following:

      CREATE TEMPORARY TABLE t(a INT);
      INSERT INTO t VALUES(1);
      CREATE TABLE t2 (a INT);
      INSERT INTO t2 SELECT * FROM t;
      DROP TABLE t;
      

      Stop this instance, and then replay the binlogs on another instance:

      ./bin/mysqlbinlog /test/other_1st_basedir/data/some_binlog-bin.000001 /test/other_1st_basedir/data/some_binlog-bin.000001 | ./bin/mariadb -A -uroot -S./socket.sock --force test
      

      And start a client on the replay instance, we will see that t2 has a "1" row:

      CS 11.4.8 8c6cbb336081a5e1ad781df4a9778b61e3b4d73f (Optimized) Build 06/06/2025

      11.4.8-opt>SELECT * FROM t2\G
      *************************** 1. row ***************************
      a: 1
      1 row in set (0.000 sec)
      

      However, if we wrap the INSERT into XA:

      CREATE TEMPORARY TABLE t(a INT);
      XA START 'a';
      INSERT INTO t VALUES(1);
      XA END 'a';
      XA PREPARE 'a';
      XA COMMIT 'a';
      CREATE TABLE t2 (a INT);
      INSERT INTO t2 SELECT * FROM t;
      DROP TABLE t;
      

      And again replay on a fresh replay instance, we now see:

      CS 11.4.8 8c6cbb336081a5e1ad781df4a9778b61e3b4d73f (Optimized) Build 06/06/2025

      11.4.8-opt>SELECT * FROM t2\G
      Empty set (0.004 sec)
      

      This looks related due to these errors we see on replay of the binlog (these are not present when XA is not used):

      CS 11.4.8 8c6cbb336081a5e1ad781df4a9778b61e3b4d73f (Optimized) Build 06/06/2025

      --------------
      XA COMMIT X'61',X'',1
      --------------
       
      ERROR 1402 (XA100) at line 100: XA_RBROLLBACK: Transaction branch was rolled back
      --------------
      INSERT INTO t2 SELECT * FROM t
      --------------
       
      ERROR 1146 (42S02) at line 118: Table 'test.t' doesn't exist
      --------------
      DROP TEMPORARY TABLE `t`
      --------------
       
      ERROR 1051 (42S02) at line 129: Unknown table 'test.t'
      

      Double confirmed by testing MySQL 5.5.62 with the XA testcase. Outcome:

      MS MySQL5.5.62 bac287c315b1792e7ae33f91add6a60292f9bae8 (Debug) Build 07/01/2023

      5.5.62-dbg>SELECT * FROM t2\G
      *************************** 1. row ***************************
      a: 1
      1 row in set (0.00 sec)
      

      Note: on MySQL there are 4 binlog files to include, and the CLI options are slightly different use something like:

      P1="/test/MS070123-mysql-5.5.62-linux-x86_64-opt/data/"; ./bin/mysqlbinlog ${P1}/qa-roel-2-bin.000001 ${P1}/qa-roel-2-bin.000002 ${P1}/qa-roel-2-bin.000003 ${P1}/qa-roel-2-bin.000004 | ./bin/mysql -A -uroot -S./socket.sock --force test
      

      Also small reminder to set the BINLOG format to MIXED on MySQL first.

      Attachments

        Issue Links

          Activity

            People

              Elkin Andrei Elkin
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.