1. 程式人生 > >MySQL XA 事務支援調研

MySQL XA 事務支援調研


3. 使用限制
a. XA事務和本地事務以及鎖表操作是互斥的
開啟了xa事務就無法使用本地事務和鎖表操作
mysql> xa start 't1xa';
Query OK, 0 rows affected (0.04 sec)

mysql> begin;
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the  ACTIVE state

mysql> lock table t1 read;
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the  ACTIVE state

開啟了本地事務就無法使用xa事務
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> xa start 'rrrr';
ERROR 1400 (XAE09): XAER_OUTSIDE: Some work is done outside global transaction

b. xa start 之後必須xa end, 否則不能執行xa commit 和xa rollback
所以如果在執行xa事務過程中有語句出錯了,你也需要先xa end一下,然後才能xarollback。

4. 注意事項

a. mysql只是提供了xa事務的介面,分散式事務中的mysql例項之間是互相獨立的不感知的。 所以使用者必須
自己實現分散式事務的排程器
b. xa事務有一些使用上的bug, 參考http://www.mysqlops.com/2012/02/24/mysql-xa-optimize.html
主要是