Encyclopedia  |   World Factbook  |   World Flags  |   Reference Tables  |   List of Lists     
   Academic Disciplines  |   Historical Timeline  |   Themed Timelines  |   Biographies  |   How-Tos     
Sponsor by The Tattoo Collection
Two-phase-commit protocol
Main Page | See live article | Alphabetical index

Two-phase-commit protocol

In computer networking and databases, the two-phase-commit protocol is a distributed algorithm which lets all nodes in a distributed system agree to commit a transaction. The protocol results in either all nodes committing the transaction or aborting, even in the case of network failures or node failures. However, due to the work by Skeen and Stonebraker, the protocol will not handle more than one random site failure at a time. The two phases of the algorithm are the commit-request phase, in which the coordinator attempts to prepare all the cohorts, and the commit phase, in which the coordinator completes the transactions at all cohorts.

Table of contents
1 Assumptions
2 Basic Algorithm
3 Disadvantages


The protocol works in the following manner: one node is designated the coordinator, which is the master site, and the rest of the nodes in the network are designated the cohorts. The protocol assumes that there is stable storage at each node with a write-ahead log, that no node crashes forever, and that any two nodes can communicate with each other. The latter is not a big deal since network communication can typically be rerouted. The former is a much stronger assumption; if a node is totally destroyed then data can be lost.

Basic Algorithm

During the commit-request phase, the coordinator sends a query to commit message to all cohorts. The cohorts carry out the transaction and write an entry to the undo log and an entry to the redo log. Each cohort replies with an agreement message if the transaction succeeded, or an abort message if the transaction failed. The coordinator wait until it has a message from each cohort.

During the commit phase, if the coordinator received an agree message from all cohorts, it writes a commit record into its log and sends a commit message to all the cohorts. If any cohort sent an abort message, the coordinator sends an abort message to all the cohorts. Now the coordinator waits for an acknowledgement from the cohorts. When acknowledgements are received from all cohorts the coordinator writes a completion record to its log. If a cohort receives a commit message, it releases all the locks and resources held during the transaction and sends an acknowledgement to the coordinator. If a cohort receives an abort message, then it undoes the transaction using the undo log and releases the resources and locks held during the transaction. Then it sends an acknowledgement.


The greatest disadvantage of the two phase commit protocol is the fact that it is a blocking protocol. A node will block while it is waiting for a message. This means that other processes competing for resource locks held by the blocked processes will have to wait for the locks to be released. A single node will continue to wait even if all other sites have failed. If the coordinator fails permanently, some cohorts will never resolve their transactions. This has the effect that resources are tied up forever. Another disadvantage is the protocol is conservative. It is biased to the abort case rather than the complete case.

Much research in databases has been carried out on ways to get most the benefits of the two-phase-commit protocol without the costs.