mysql的XA事務(wù)恢復(fù)過程詳解
更新時(shí)間:2012年11月13日 10:21:46 作者:
XA事務(wù)支持限于InnoDB存儲(chǔ)引擎,本文將詳細(xì)介紹mysql的XA事務(wù)恢復(fù)過程
mysql數(shù)據(jù)庫開機(jī)報(bào)錯(cuò):
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)
意味著有三個(gè)XA的事務(wù)沒有提交或回滾。
登錄到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 |
+----------+--------------+--------------+------------------------------------------------------------+
數(shù)據(jù)表示信息如下:
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
這是三個(gè)XA事務(wù)的信息,準(zhǔn)備直接回滾。
mysql> xa rollback '1-7f000001:bae5:4b6928eb:fb5c3','7f000001:bae5:4b6928eb:fb5cd',131075;
Query OK, 0 rows affected (0.41 sec)
再啟動(dòng)就正常了。
MySQL XA
I.5. 對(duì)XA事務(wù)的限制
XA事務(wù)支持限于InnoDB存儲(chǔ)引擎。
MySQL XA實(shí)施是針對(duì)外部XA的,其中,MySQL服務(wù)器作為資源管理器,而客戶端程序作為事務(wù)管理器。未實(shí)施“內(nèi)部XA”。這樣,就允許MySQL服務(wù)器內(nèi)的單獨(dú)存儲(chǔ)引擎作為RM(資源管理器),而服務(wù)器本身作為TM(事務(wù)管理器)。處理包含1個(gè)以上存儲(chǔ)引擎的XA事務(wù)時(shí),需要內(nèi)部XA。內(nèi)部XA的實(shí)施是不完整的,這是因?yàn)?,它要求存?chǔ)引擎在表處理程序?qū)用嫔现С謨呻A段提交,目前僅對(duì)InnoDB實(shí)現(xiàn)了該特性。
對(duì)于XA START,不支持JOIN和RESUME子句。
對(duì)于XA END,不支持SUSPEND [FOR MIGRATE]子句。
在全局事務(wù)內(nèi),對(duì)于每個(gè)XA事務(wù),xid值的bqual部分應(yīng)是不同的,該要求是對(duì)當(dāng)前MySQL XA實(shí)施的限制。它不是XA規(guī)范的組成部分。
如果XA事務(wù)達(dá)到PREPARED狀態(tài)而且MySQL服務(wù)器宕機(jī),當(dāng)服務(wù)器重啟后,能夠繼續(xù)處理事務(wù)。就像原本應(yīng)當(dāng)?shù)哪菢?。但是,如果客戶端連接中止而服務(wù)器繼續(xù)運(yùn)行,服務(wù)器將回滾任何未完成的XA事務(wù),即使該事務(wù)已達(dá)到PREPARED狀態(tài)也同樣。它應(yīng)能提交或回滾PREPARED XA事務(wù),但在不更改二進(jìn)制日志機(jī)制的情況下不能這樣。
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)
意味著有三個(gè)XA的事務(wù)沒有提交或回滾。
登錄到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 |
+----------+--------------+--------------+------------------------------------------------------------+
數(shù)據(jù)表示信息如下:
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
這是三個(gè)XA事務(wù)的信息,準(zhǔn)備直接回滾。
mysql> xa rollback '1-7f000001:bae5:4b6928eb:fb5c3','7f000001:bae5:4b6928eb:fb5cd',131075;
Query OK, 0 rows affected (0.41 sec)
再啟動(dòng)就正常了。
MySQL XA
I.5. 對(duì)XA事務(wù)的限制
XA事務(wù)支持限于InnoDB存儲(chǔ)引擎。
MySQL XA實(shí)施是針對(duì)外部XA的,其中,MySQL服務(wù)器作為資源管理器,而客戶端程序作為事務(wù)管理器。未實(shí)施“內(nèi)部XA”。這樣,就允許MySQL服務(wù)器內(nèi)的單獨(dú)存儲(chǔ)引擎作為RM(資源管理器),而服務(wù)器本身作為TM(事務(wù)管理器)。處理包含1個(gè)以上存儲(chǔ)引擎的XA事務(wù)時(shí),需要內(nèi)部XA。內(nèi)部XA的實(shí)施是不完整的,這是因?yàn)?,它要求存?chǔ)引擎在表處理程序?qū)用嫔现С謨呻A段提交,目前僅對(duì)InnoDB實(shí)現(xiàn)了該特性。
對(duì)于XA START,不支持JOIN和RESUME子句。
對(duì)于XA END,不支持SUSPEND [FOR MIGRATE]子句。
在全局事務(wù)內(nèi),對(duì)于每個(gè)XA事務(wù),xid值的bqual部分應(yīng)是不同的,該要求是對(duì)當(dāng)前MySQL XA實(shí)施的限制。它不是XA規(guī)范的組成部分。
如果XA事務(wù)達(dá)到PREPARED狀態(tài)而且MySQL服務(wù)器宕機(jī),當(dāng)服務(wù)器重啟后,能夠繼續(xù)處理事務(wù)。就像原本應(yīng)當(dāng)?shù)哪菢?。但是,如果客戶端連接中止而服務(wù)器繼續(xù)運(yùn)行,服務(wù)器將回滾任何未完成的XA事務(wù),即使該事務(wù)已達(dá)到PREPARED狀態(tài)也同樣。它應(yīng)能提交或回滾PREPARED XA事務(wù),但在不更改二進(jìn)制日志機(jī)制的情況下不能這樣。
您可能感興趣的文章:
- mysql跨庫事務(wù)XA操作示例
- MySQL存儲(chǔ)表情時(shí)報(bào)錯(cuò):java.sql.SQLException: Incorrect string value:‘\xF0\x9F\x92\xA9\x0D\x0A...’的解決方法
- 如何修改Xampp服務(wù)器上的mysql密碼(圖解)
- 在mac上如何使用終端打開XAMPP自帶的MySQL
- xampp修改mysql默認(rèn)密碼的方法
- ThinkPHP框架搭建及常見問題(XAMPP安裝失敗、Apache/MySQL啟動(dòng)失?。?/a>
- xampp中修改mysql默認(rèn)空密碼(root密碼)的方法分享
- 解決xampp自啟動(dòng)和mysql.sock問題
- MySQL數(shù)據(jù)庫是如何實(shí)現(xiàn)XA規(guī)范的
相關(guān)文章
navicat?連接Ubuntu虛擬機(jī)的mysql的操作方法
這篇文章主要介紹了navicat?連接Ubuntu虛擬機(jī)的mysql的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04MySQL遞歸查詢樹狀表的子節(jié)點(diǎn)、父節(jié)點(diǎn)具體實(shí)現(xiàn)
本程序?qū)懥藘蓚€(gè)sql存儲(chǔ)過程,子節(jié)點(diǎn)查詢算是照搬了,父節(jié)點(diǎn)查詢是逆思維弄的2014-03-03MySQL數(shù)據(jù)庫InnoDB引擎下服務(wù)器斷電數(shù)據(jù)恢復(fù)方法
這篇文章主要介紹了MySQL數(shù)據(jù)庫InnoDB引擎下服務(wù)器斷電數(shù)據(jù)恢復(fù)方法,需要的朋友可以參考下2016-04-04安裝rpm包時(shí)提示錯(cuò)誤:依賴檢測失敗的解決方法
今天在虛擬機(jī)中裝MySQL的時(shí)候,突然出現(xiàn)了這個(gè)依賴檢測錯(cuò)誤,下面這篇文章主要給大家介紹了關(guān)于安裝rpm包時(shí)提示錯(cuò)誤:依賴檢測失敗的解決方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09MySQL建立數(shù)據(jù)庫時(shí)字符集與排序規(guī)則的選擇詳解
當(dāng)數(shù)據(jù)庫需要適應(yīng)不同的語言就需要有不同的字符集,下面這篇文章主要給大家介紹了關(guān)于MySQL建立數(shù)據(jù)庫時(shí)字符集與排序規(guī)則的選擇的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06