two phase commit

来源:互联网 发布:js中的confirm 编辑:程序博客网 时间:2024/05/23 00:59

两步提交机制(two-phase commit mechanism)可以保证所有参与分布式事务(distributed transaction)的数据库或者同时提交(commit),或者同时撤销(undo)事务中 SQL 语句的操作。两步提交机制还确保了由完整性约束(integrity constraint),远程过程调用(remote procedure call),及触发器(trigger)执行的隐式 DML 操作正常工作。

Oracle 两步提交机制(two-phase commit mechanism)对于提交分布式事务(distributed transaction)的用户来说完全透明。用户甚至无需知道其事务是分布式的。当事务由一个 COMMIT 语句标志结束后会自动地触发两步式提交机制来提交此事务。数据库应用程序中无需使用任何代码或复杂的 SQL 语法就能处理分布式事务。

In transaction processing, databases, and computer networking, the two-phase commit protocol (2PC) is a type of an atomic commitment protocol. It is a distributed algorithm that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (roll back) the transaction (it is a specialized type of consensus protocol). The protocol achieves its goal even in many cases of temporary system failure (involving either process, network node, communication, etc. failures), and is thus widely utilized.[1][2] However, it is not resilient to all possible failure configurations, and in rare cases user intervention is needed to remedy outcome.

The two phases of the algorithm are the commit-request phase, in which a coordinator process attempts to prepare all the transaction's participating processes (named participants, cohorts, or workers) to take the necessary steps for either committing or aborting the transaction, and the commit phase, in which, based on voting (either "Yes," commit, or "No," abort) of the cohorts, the coordinator decides whether to commit (only if all vote "Yes") or abort the transaction (otherwise), and notifies the result to the cohorts. The cohorts then follow with the needed actions (commit or abort) with their transactional resources and their respective portions in the transaction's output (if applicable).

Note that the two-phase commit (2PC) protocol should not be confused with the two-phase locking (2PL) protocol, a concurrency control protocol.

原创粉丝点击