What problem does two-phase commit solve?
Sketch your own answer first, then compare it with the one below.
A strong answer
A transaction may change data on several machines. The danger is that some commit and others do not, and the data is left half changed.
Two-phase commit makes the outcome the same everywhere. A coordinator first asks every participant whether it can commit. Only if all say yes does the coordinator tell them to commit. If any says no, everyone aborts.
The trade-off is that the participants must wait for the coordinator's decision. That waiting is the cost of agreeing.
Sources
- Philip A. Bernstein, Vassos Hadzilacos, Nathan Goodman (1987). Concurrency Control and Recovery in Database Systems.
- C. Mohan, Bruce Lindsay, Ron Obermarck (1986). Transaction management in the R* distributed database management system.