« Transaction Processing in Large Database Systems | Main | TP Monitor »

Two-phase commit protocol vs Three-phase commit

1 | 2 | 3 | 4 | 5 | 6 | 7

This article was written by Tanya Puntti for Database Application Development - Central Queensland University.

Two-phase commit protocol

Two-phase commit is a standard protocol in distributed transactions for achieving ACID properties. Each transaction has a coordinator who initiates and coordinates the transaction (Begg & Connolly 2002, p.749).

In the two-phase commit the coordinator sends a prepare message to all participants (nodes) and waits for their answers. The coordinator then sends their answers to all other sites. Every participant waits for these answers from the coordinator before committing to or aborting the transaction. If committing, the coordinator records this into a log and sends a commit message to all participants. If for any reason a participant aborts the process, the coordinator sends a rollback message and the transaction is undone using the log file created earlier. The advantages of this are all participants reach a decision consistently, yet independently (Skeen).

However, the two-phase commit protocol also has limitations in that it is a blocking protocol (Begg & Connolly 2002, p.749). For example, participants will block resource processes while waiting for a message from the coordinator. If for any reason this fails, the participant will continue to wait and may never resolve its transaction. Therefore the resource could be blocked indefinitely. On the other hand, a coordinator will also block resources while waiting for replies from participants. In this case, a coordinator can also block indefinitely if no acknowledgement is received from the participant. Begg and Connolly suggest that the likelihood of a block happening is rare (2002, p. 749). This is most likely the reason why systems still use the two-phase commit protocol.


Three-phase commit protocol

An alternative to the two-phase commit protocol used by many database systems is the three-phase commit. Dale Skeen describes the three-phase commit as a non blocking protocol. He then goes on to say that it was developed to avoid the failures that occur in two-phase commit transactions.

As with the two-phase commit, the three-phase also has a coordinator who initiates and coordinates the transaction (Begg & Connolly 2002, p.750). However, the three-phase protocol introduces a third phase called the pre-commit. The aim of this is to ‘remove the uncertainty period for participants that have committed and are waiting for the global abort or commit message from the coordinator’ (Begg & Connolly 2002, p.750). When receiving a pre-commit message, participants know that all others have voted to commit. If a pre-commit message has not been received the participant will abort and release any blocked resources.

Continue .....


subscribe to Website Design Tips feed Want to learn more about designing a website or improving an existing one? Subscribe to Website Design Tips today for free.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Add this blog to your feed Subscribe to this feed

About

This page contains a single entry from the blog posted on January 8, 2007 5:45 AM.

The previous post in this blog was Transaction Processing in Large Database Systems.

The next post in this blog is TP Monitor.

Many more can be found on the main index page or by looking through the archives.


copyright 2001-2007 © hypergurl.com