Jump to content

Two-phase commit

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 81.225.122.69 (talk) at 22:48, 23 April 2005. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, especially in durability studies, a two phase commit allows data to be written to more than one location and for all operations to be rolled back, if one or more of the operations fails.

The Algorithm

The process is controlled from one of the participants called the Coordinator. The other participants are called Cohorts. The algorithm starts off with . The Cohorts then respond with an "OK" or "NOT OK" depending on success.

  • Phase 1
All participants executing the transaction up to the point where they will be asked to commit.
If successful
respond "OK" to Coordinator
If unsuccessful
either allow a time-out or respond "NOT OK" to Coordinator
  • Phase 2
If all Cohorts respond "OK":
Coordinator instructs participating resource managers to "COMMIT"
Participants complete operation and sent acknowledgement to Coordinator
Coordinator completes transaction when acknowledgements have been received.
Otherwise (some Cohorts responded "NOT OK", or didn't respond at all):
Coordinator instructs participating resource managers to "ROLLBACK"
Participants complete their respective local undos

Disadvantages

The algorithm can block indefinetly in two ways:

When the Coordinator has sent "COMMIT" to the Cohorts, it will block until all Cohorts have acknowledged. Thus, if a Cohort is permanently down, the Coordinator will block indefinetly.
When a Cohort has sent "OK" to the Coordinator, it will block until a "COMMIT" or "ROLLBACK" is received. If the Coordinator is permanently down, the Cohort will block indefinetly.