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

LOAD INDEX may cause rollback of prepared XA transaction

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.4(EOL), 10.5, 10.6
    • 10.5
    • XA

    Description

      A statement such as LOAD INDEX INTO may cause a prepared XA to rollback.
      For instance, consider the following case:

      CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) Engine=Innodb;
      SHOW CREATE TABLE t1;
      Table	Create Table
      t1	CREATE TABLE `t1` (
        `f1` int(11) NOT NULL,
        PRIMARY KEY (`f1`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1
      XA START 'a';
      INSERT INTO t1 VALUES (1);
      XA END 'a';
      XA PREPARE 'a';
      LOAD INDEX INTO cache t1 KEY(PRIMARY);
      Table	Op	Msg_type	Msg_text
      test.t1	preload_keys	Error	XAER_RMFAIL: The command cannot be executed when global transaction is in the  PREPARED state
      test.t1	preload_keys	error	Corrupt
      XA COMMIT 'a';
      SELECT COUNT(*) FROM t1;
      COUNT(*)
      0
      

      After XA PREPARE the user attempts to LOAD INDEX, internally, it causes a trans_rollback_implicit(), which will roll back the underlying XA transaction. After XA COMMIT the transaction left no side effects.
      I would expect LOAD INDEX to not rollback the underlying XA transaction, and fail immediately with "XAER_RMFAIL: The command cannot be executed when global transaction is in PREPARED state".

      Attachments

        Issue Links

          Activity

            I believe that trans_rollback_implicit() is missing the following check at the beginning:

            if (trans_check(thd))
              DBUG_RETURN(TRUE);
            

            sciascid Daniele Sciascia added a comment - I believe that trans_rollback_implicit() is missing the following check at the beginning: if (trans_check(thd)) DBUG_RETURN(TRUE);
            alice Alice Sherepa added a comment - - edited

            MariaDB 10.0,10.1,10.4,10.5,10.6 behaves as in description.
            10.2,10.3:

            10.2 5ecaf52d42a1e464c

            MariaDB [test]> CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) Engine=Innodb;
            Query OK, 0 rows affected (0.05 sec)
             
            MariaDB [test]> XA START 'a';
            Query OK, 0 rows affected (0.00 sec)
             
            MariaDB [test]> INSERT INTO t1 VALUES (1);
            Query OK, 1 row affected (0.00 sec)
             
            MariaDB [test]> XA END 'a';
            Query OK, 0 rows affected (0.00 sec)
             
            MariaDB [test]> XA PREPARE 'a';
            Query OK, 0 rows affected (0.01 sec)
             
            MariaDB [test]> XA RECOVER;
            +----------+--------------+--------------+------+
            | formatID | gtrid_length | bqual_length | data |
            +----------+--------------+--------------+------+
            |        1 |            1 |            0 | a    |
            +----------+--------------+--------------+------+
            1 row in set (0.00 sec)
             
            MariaDB [test]> LOAD INDEX INTO cache t1 KEY(PRIMARY);
            +---------+--------------+----------+-----------------------------------------------------------------------------------------------+
            | Table   | Op           | Msg_type | Msg_text                                                                                      |
            +---------+--------------+----------+-----------------------------------------------------------------------------------------------+
            | test.t1 | preload_keys | Error    | XAER_RMFAIL: The command cannot be executed when global transaction is in the  PREPARED state |
            | test.t1 | preload_keys | error    | Corrupt                                                                                       |
            +---------+--------------+----------+-----------------------------------------------------------------------------------------------+
            2 rows in set (0.01 sec)
             
            MariaDB [test]> XA RECOVER;
            +----------+--------------+--------------+------+
            | formatID | gtrid_length | bqual_length | data |
            +----------+--------------+--------------+------+
            |       -1 |            1 |            0 | a    |
            +----------+--------------+--------------+------+
            1 row in set (0.00 sec)
             
            MariaDB [test]> XA COMMIT 'a';
            ERROR 1397 (XAE04): XAER_NOTA: Unknown XID
            MariaDB [test]> SELECT COUNT(*) FROM t1;
            ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the  PREPARED state
            

            alice Alice Sherepa added a comment - - edited MariaDB 10.0,10.1,10.4,10.5,10.6 behaves as in description. 10.2,10.3: 10.2 5ecaf52d42a1e464c MariaDB [test]> CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) Engine=Innodb; Query OK, 0 rows affected (0.05 sec)   MariaDB [test]> XA START 'a'; Query OK, 0 rows affected (0.00 sec)   MariaDB [test]> INSERT INTO t1 VALUES (1); Query OK, 1 row affected (0.00 sec)   MariaDB [test]> XA END 'a'; Query OK, 0 rows affected (0.00 sec)   MariaDB [test]> XA PREPARE 'a'; Query OK, 0 rows affected (0.01 sec)   MariaDB [test]> XA RECOVER; +----------+--------------+--------------+------+ | formatID | gtrid_length | bqual_length | data | +----------+--------------+--------------+------+ | 1 | 1 | 0 | a | +----------+--------------+--------------+------+ 1 row in set (0.00 sec)   MariaDB [test]> LOAD INDEX INTO cache t1 KEY(PRIMARY); +---------+--------------+----------+-----------------------------------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +---------+--------------+----------+-----------------------------------------------------------------------------------------------+ | test.t1 | preload_keys | Error | XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state | | test.t1 | preload_keys | error | Corrupt | +---------+--------------+----------+-----------------------------------------------------------------------------------------------+ 2 rows in set (0.01 sec)   MariaDB [test]> XA RECOVER; +----------+--------------+--------------+------+ | formatID | gtrid_length | bqual_length | data | +----------+--------------+--------------+------+ | -1 | 1 | 0 | a | +----------+--------------+--------------+------+ 1 row in set (0.00 sec)   MariaDB [test]> XA COMMIT 'a'; ERROR 1397 (XAE04): XAER_NOTA: Unknown XID MariaDB [test]> SELECT COUNT(*) FROM t1; ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state

            People

              serg Sergei Golubchik
              sciascid Daniele Sciascia
              Votes:
              0 Vote for this issue
              Watchers:
              6 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.