这里参考的是Oracle对于XA的支持,其他的应该雷同吧。。。

1个分布式事务由多个行为在不同的数据库上执行,1个分布式事务的执行成功意味着相关数据库上的行为执行均成功。“XA协定”(http://www.opengroup.org/public/pubs/catalog/c193.htm)就支持分布式的事务,具备能力,让多个独立的事务资源参加全局的事务。事务资源通常是RDBMSs,不过也可以是其它种类的资源。

一个典型的全局性事务的架构如下,通常来说TM会集成在Application Server(例如weblogic server)中。这种TM也叫做external TM,区别于在MySQL DBMS或者Oracle DBMS中的管理本地事务的TM

 

 

资源管理器(RM):用户提供通向事务的途径。数据库服务器(例如上面的Oracal DBMS)是一个种资源管理器。该管理器必须提交or回滚由RM管理的事务。

事务管理器(TM):用于协调作为一个分布式事务的一部分事务。通常XA的相关操作都在这里进行,而对于Client而言是透明的,TM(或许是个进程)通常是由TPM( transaction processing monitor,Texudo就有这个组件,所以Texudo也就本能地支持了全局事务)提供。

 

对于Client App而言,所有的Global Transaction都应该通过TM进行(在ORACLE中,是名字为TX的一组接口函数),TM再与RM通过XA接口(Oracle有提供这组函数)进行接洽。而所有的普通的针对同一个数据库的事务可以直接通过Native Interface进行。

在Oracle的文档里,一个Global Transaction被分为多个Branch。A branch is a unit of work contained within one RM. In the case of Oracle Database, each branch maps to a local transaction inside the database server.

理解全局性事务的关键是理解两阶段提交:

The Oracle XA library interface follows the two-phase commit protocol. The sequence of events is as follows:

  1. In the prepare phase, the TM asks each RM to guarantee that it can commit any part of the transaction. If this is possible, then the RM records its prepared state and replies affirmatively to the TM. If it is not possible, then the RM may roll back any work, reply negatively to the TM, and forget about the transaction. The protocol allows the application, or any RM, to roll back the transaction unilaterally until the prepare phase completes.
  2. In phase two, the TM records the commit decision and issues a commit or rollback to all RMs participating in the transaction. TM can issue a commit for an RM only if all RMs have replied affirmatively to phase one.

下面的一个例子是从Oracle的JDBC文档里搞出来的。基本上讲清楚了整个过程。特别注意的是,Note that for simplicity, this example combines code that would typically be in a middle tier with code that would typically be in a transaction manager (such as the XA resource method invocations and the creation of transaction IDs).

Oracle XA Code Sample 最底下一段

关于MySQL全局性事务的一些限制,http://jishu.zol.com.cn/4306.html和http://blog.sina.com.cn/s/blog_4673e6030101c7o4.html

一些疑问

对于MySQL的XA支持,如果在XA START/END之间的SQL语句挂了,作为RM的MySQL如何通知TM?提供的方法里只有XA PREPARE,在我的理解里,这个是用于表示第一阶段的提交成功了,于是TM就可以通过查看XA RECOVER看到PREPARE状态了。那么如何表示失败呢?超时总不太靠谱吧?

参考

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_xa.htm#g1017655

http://docs.oracle.com/cd/B10500_01/java.920/a96654/xadistra.htm

http://liuhaodba.blog.51cto.com/6379925/1117647

http://www.iteedu.com/database/mysql/mysqlmanualcn/sql-syntax/xa.php

http://jishu.zol.com.cn/4306.html

http://blog.sina.com.cn/s/blog_4673e6030101c7o4.html

http://blog.csdn.net/mchdba/article/details/13076803

最新文章

  1. 【DP】POJ 2385
  2. Java网络编程之流——readline()方法的bug
  3. Making the Grade(POJ3666)
  4. Android数据持久化技术 — — —文件存储
  5. swith 好久不用都忘记了
  6. NOI2002银河英雄传说
  7. vim纯文本处理插件txtbrowser
  8. vim技巧和坑
  9. CentOS下命令行和桌面模式的切换方法(转载)
  10. Eclips入门教程
  11. 完全卸载删除gitlab
  12. 我的software
  13. quartz.net实现集群部署的笔记
  14. python中import和from-import的区别
  15. 005.KVM日常管理2-virt管理
  16. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)
  17. linux常用C函数目录
  18. 《FontForge常见问题FAQ》字王翻译版
  19. linux下运行jar
  20. struts集合类型封装

热门文章

  1. java中i=i++问题分析
  2. java:jsp: 一个简单的自定义标签 tld
  3. 手动下载 Xcode 文档
  4. KNN cosine 余弦相似度计算
  5. Elasticsearch使用积累
  6. BEC listen and translation exercise 13
  7. bzoj 3992 [SDOI2015]序列统计——NTT(循环卷积&&快速幂)
  8. DIDAO.Common --- 项目中的常用类及其中函数
  9. HDU1695(容斥原理)
  10. bash 中的行处理命令 awk