联系
Knight's Tale » 架构

分布式事务综述

2015-08-21 08:21

I'll present the patterns in reverse order of safety(安全) or reliability(可靠), starting with those with the highest guarantee of data integrity and atomicity under the most general circumstances

从最可靠-》最不可靠

The patterns are also roughly in reverse order of runtime cost (starting with the most expensive)。

从最耗时-》最不耗时

Distributed transactions and atomicity

A distributed transaction is one that involves more than one transactional resource. Examples of transactional resources are the connectors for communicating with relational databases and messaging middleware.

分布式系统可能会同时操作多个数据源。 比如,经常情况下,我们会操作 关系型数据库 和 消息中间件

The first three patterns discussed below are based on the XA protocol.

Full XA with 2PC

两阶段提交可见: http://blog.csdn.net/dbanote/article/details/8981946

http://blog.csdn.net/a837199685/article/details/40979267

XA protocol.

In Java, from the developer's point of view, the protocol is exposed through a JTA UserTransaction.

最大努力单阶段提交模式(Best Efforts 1PC pattern)

基本的想法是尽可能的延迟一个事务中资源操作的提交,这样仅有的失败可能是基础设施出问题(而不是业务处理错误)。依赖于这个模式的系统基本上假定系统基础设施的失败很少会发生,这样他们能为了更高的并发处理量而承担这样的失败风险。如果业务处理服务也同样设计为幂等的,那么在实践中很少犯错。

http://blue2048.iteye.com/blog/2191497

服务模型:可查询的操作

可查询操作 + 定期校对 + 保证消息在事务提交后才发送

适用范围

  • 对业务最终一致性的时间敏感度低
  • 跨企业的业务活动

服务模型: 幂等操作

幂等操作 + 可靠消息

优点

适用范围

  • 对最终一致性时间敏感度较高
  • 降低业务被动方实现成本

典型实现:pikaq https://github.com/knightliao/pikaQ

服务模型: TCC操作

适用范围

  • 强隔离性、严格一致性要求的业务活动
  • 适用于执行时间较短的业务

成本

  • 实现TCC操作的成本
  • 业务活动结束时confirm或cancel操作的执 行成本
  • 业务活动日志成本

服务模型:可补偿操作

适用范围

  • 弱隔离性、弱一致性要求的业务活动
  • 特别适用于执行时间较长的业务,如工作流
本文链接地址:分布式事务综述