mysql的XA事务恢复过程详解

时间:2024-01-18 07:44:22 

mysql数据库开机报错
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
100224 12:24:20 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Transaction 0 4497755 was in the XA prepared state.
InnoDB: Transaction 0 4468551 was in the XA prepared state.
InnoDB: Transaction 0 4468140 was in the XA prepared state.
InnoDB: 3 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 0 row operations to undo
InnoDB: Trx id counter is 0 5312768
InnoDB: Starting in background the rollback of uncommitted transactions
100224 12:24:20 InnoDB: Rollback of non-prepared transactions completed
100224 12:24:20 InnoDB: Started; log sequence number 0 3805002509
100224 12:24:20 InnoDB: Starting recovery for XA transactions...
100224 12:24:20 InnoDB: Transaction 0 4497755 in prepared state after recovery
100224 12:24:20 InnoDB: Transaction contains changes to 8 rows
100224 12:24:20 InnoDB: Transaction 0 4468551 in prepared state after recovery
100224 12:24:20 InnoDB: Transaction contains changes to 1 rows
100224 12:24:20 InnoDB: Transaction 0 4468140 in prepared state after recovery
100224 12:24:20 InnoDB: Transaction contains changes to 1 rows
100224 12:24:20 InnoDB: 3 transactions in prepared state after recovery
100224 12:24:20 [Note] Found 3 prepared transaction(s) in InnoDB
100224 12:24:20 [Warning] Found 3 prepared XA transactions
100224 12:24:20 [Note] Event Scheduler: Loaded 0 events
100224 12:24:20 [Note] /opt/mysql/bin/mysqld: ready for connections.
Version: '5.1.39' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
意味着有三个XA的事务没有提交或回滚。
登录到mysql
mysql> xa recover;
+----------+--------------+--------------+------------------------------------------------------------+
| formatID | gtrid_length | bqual_length | data |
+----------+--------------+--------------+------------------------------------------------------------+
| 131075 | 30 | 28 | 1-7f000001:bae5:4b6928eb:f06397f000001:bae5:4b6928eb:f0650 |
| 131075 | 30 | 28 | 1-7f000001:bae5:4b6928eb:fb5c37f000001:bae5:4b6928eb:fb5cd |
| 131075 | 30 | 28 | 1-7f000001:bae5:4b6928eb:f03ea7f000001:bae5:4b6928eb:f0400 |
+----------+--------------+--------------+------------------------------------------------------------+
数据表示信息如下
formatIDis the formatIDpart of the transaction xid
gtrid_lengthis the length in bytes of the gtridpart of the xid
bqual_lengthis the length in bytes of the bqualpart of the xid
datais the concatenation of the gtridand bqualparts of the xid
这是三个XA事务的信息,准备直接回滚。
mysql> xa rollback '1-7f000001:bae5:4b6928eb:fb5c3','7f000001:bae5:4b6928eb:fb5cd',131075;
Query OK, 0 rows affected (0.41 sec)
再启动就正常了。

MySQL XA
I.5. 对XA事务的限制
XA事务支持限于InnoDB存储引擎。
MySQL XA实施是针对外部XA的,其中,MySQL服务器作为资源管理器,而客户端程序作为事务管理器。未实施“内部XA”。这样,就允许MySQL服务器内的单独存储引擎作为RM(资源管理器),而服务器本身作为TM(事务管理器)。处理包含1个以上存储引擎的XA事务时,需要内部XA。内部XA的实施是不完整的,这是因为,它要求存储引擎在表处理程序层面上支持两阶段提交,目前仅对InnoDB实现了该特性。
对于XA START,不支持JOIN和RESUME子句。

对于XA END,不支持SUSPEND [FOR MIGRATE]子句。
在全局事务内,对于每个XA事务,xid值的bqual部分应是不同的,该要求是对当前MySQL XA实施的限制。它不是XA规范的组成部分。

如果XA事务达到PREPARED状态而且MySQL服务器宕机,当服务器重启后,能够继续处理事务。就像原本应当的那样。但是,如果客户端连接中止而服务器继续运行,服务器将回滚任何未完成的XA事务,即使该事务已达到PREPARED状态也同样。它应能提交或回滚PREPARED XA事务,但在不更改二进制日志机制的情况下不能这样。

标签:mysql,xa,事务
0
投稿

猜你喜欢

  • 基于python实现文件加密功能

    2022-02-02 20:28:57
  • Python编程之变量赋值操作实例分析

    2021-09-20 12:12:01
  • 使用python爬取taptap网站游戏截图的步骤

    2021-09-17 07:44:34
  • 9个提高 Python 编程的小技巧

    2022-01-20 16:53:28
  • ASP程序种如何调用DLL文件

    2008-01-15 19:12:00
  • 利用Python批量压缩png方法实例(支持过滤个别文件与文件夹)

    2021-07-16 11:37:24
  • Python面向对象魔法方法和单例模块代码实例

    2023-05-02 19:03:16
  • python-docx修改已存在的Word文档的表格的字体格式方法

    2021-07-20 05:03:07
  • MySQL六种约束的示例详解

    2024-01-16 19:15:38
  • 使用Visual Studio 2022开发前端的详细教程

    2023-07-02 05:30:35
  • 详解Numpy中的数组拼接、合并操作(concatenate, append, stack, hstack, vstack, r_, c_等)

    2021-06-20 01:55:07
  • python 实现定时任务的四种方式

    2023-06-28 14:37:27
  • 微信跳一跳python代码实现

    2021-09-16 05:35:09
  • 基于Python编写一个简单的http服务器

    2022-04-08 21:07:39
  • Golang中异常处理机制详解

    2024-02-17 17:05:50
  • 详解MySQL中的SQRT函数的使用方法

    2024-01-28 03:59:32
  • MySQL七大JOIN的具体使用

    2024-01-28 04:11:31
  • PHP组合模式Composite Pattern优点与实现过程

    2023-05-29 02:10:44
  • JavaScript对象的浅拷贝与深拷贝实例分析

    2024-04-16 09:46:34
  • Python实现发送邮件到自己邮箱

    2023-10-18 17:08:11
  • asp之家 网络编程 m.aspxhome.com