【问题标题】:How to commit a XA transaction after server crashed服务器崩溃后如何提交 XA 事务
【发布时间】:2018-01-14 22:12:24
【问题描述】:

我在 Mint 18 上使用 MySQL 5.7.19-0ubuntu0.16.04.1。我在准备 XA 事务时发现,然后服务器崩溃了。服务重启后,我不能再接触事务了。它仍然锁定了桌子。

mysql> xa start '1';

mysql> xa end '1';

mysq> xa 准备 '1';

sudo killall -9 mysqld

sudo 服务启动 mysqld

mysql> xa commit '1';

ERROR 1399 (XAE07): XAER_RMFAIL: 当全局事务处于 NON-EXISTING 状态时无法执行命令

mysql> xa start '1';

ERROR 1440 (XAE08): XAER_DUPID: XID 已经存在

情况和bug71352差不多,但我的版本差太远了。 我错过了什么?

【问题讨论】:

    标签: mysql transactions linux-mint xa mysql-5.7


    【解决方案1】:

    我无法重现该问题:

    mysql> \! lsb_release --description
    Description:    Linux Mint 18.2 Sonya
    
    mysql> SELECT VERSION();
    +-----------+
    | VERSION() |
    +-----------+
    | 5.7.19    |
    +-----------+
    1 row in set (0.00 sec)
    
    mysql> DROP TABLE IF EXISTS `t`;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> CREATE TABLE IF NOT EXISTS `t` (
        ->   `id` INT
        -> ) ENGINE=InnoDB;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> XA START '1';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> INSERT INTO `t`
        -> VALUES (1);
    Query OK, 1 row affected (0.01 sec)
    
    mysql> XA END '1';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> XA PREPARE '1';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> XA RECOVER;
    +----------+--------------+--------------+------+
    | formatID | gtrid_length | bqual_length | data |
    +----------+--------------+--------------+------+
    |        1 |            1 |            0 | 1    |
    +----------+--------------+--------------+------+
    1 row in set (0.00 sec)
    
    -- Killed mysqld from other session
    
    mysql> \! service mysql status | grep 'Active'
       Active: inactive (dead) since 33s ago
    
    -- Restared mysqld from other session
    
    mysql> \! service mysql status | grep 'Active'
       Active: active (running) since 3s ago
    
    mysql> XA RECOVER;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect...
    Connection id:
    Current database:
    
    +----------+--------------+--------------+------+
    | formatID | gtrid_length | bqual_length | data |
    +----------+--------------+--------------+------+
    |        1 |            1 |            0 | 1    |
    +----------+--------------+--------------+------+
    1 row in set (0.02 sec)
    
    mysql> SELECT `id` FROM `t`;
    Empty set (0.00 sec)
    
    mysql> XA START '1';
    ERROR 1440 (XAE08): XAER_DUPID: The XID already exists
    
    mysql> XA COMMIT '1';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SELECT `id` FROM `t`;
    +------+
    | id   |
    +------+
    |    1 |
    +------+
    1 row in set (0.00 sec)
    

    【讨论】:

      【解决方案2】:

      xa 启动必须失败,这是预期的,这是未决的 XA 事务。您需要先进行 xa 恢复。

      【讨论】:

        猜你喜欢
        • 2014-03-16
        • 1970-01-01
        • 2013-04-11
        • 2021-08-21
        • 1970-01-01
        • 2017-10-28
        • 2016-06-12
        • 2017-07-29
        • 1970-01-01
        相关资源
        最近更新 更多