- Asked 2/15
- 2076 Chaitra · 3 marks
- 2071 Shrawan · 4 marks
Short note: Two-phase commit
Short answer
Two-phase commit (2PC) ensures all participants of a distributed transaction either commit or abort. The coordinator sends canCommit? requests; participants reply Yes if prepared, No otherwise. If all votes are Yes, the coordinator sends doCommit, else doAbort. Participants then execute the decision and acknowledge, ensuring atomicity despite failures, though coordinator failure may block.
Write a short note on two phase commit protocol.
The two-phase commit protocol (2PC) makes sure that all servers (participants) of a distributed transaction either all commit or all abort. One server acts as the coordinator (usually the one that the client contacted); others are participants.
Phase 1: voting
- The coordinator sends canCommit? to every participant.
- Each participant replies Yes (it has saved the transaction's changes to permanent storage and is prepared; it can no longer unilaterally abort) or No (it aborts at once).
Phase 2: completion 3. If all votes (including the coordinator's own) are Yes, the coordinator records the decision and sends doCommit; if any vote is No or a timeout occurs, it sends doAbort. 4. Participants carry out the decision and send haveCommitted to the coordinator.
Coordinator Participants
|--- canCommit? ------->|
|<------ Yes / No ------|
| (decide, log) |
|--- doCommit/doAbort ->|
|<---- haveCommitted ---|
Failures
- If a participant crashes before voting, the coordinator times out and aborts.
- A participant that has voted Yes is in the uncertain state; if the coordinator fails it must wait (it blocks) or ask other participants for the decision.
- On recovery, servers use their logs to complete the protocol.
Drawbacks: blocking if the coordinator fails, and extra messages and delays (about 3N messages for N participants).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Distributed deadlock; two-phase commit · Distributed System, chapter 8
- Cascading aborts; atomic commit protocol · Distributed System, chapter 8
- Cascading aborts; three-phase commit · Distributed System, chapter 8
- Short note: Three-phase commit · Distributed System, chapter 8
- Two-phase simplex method max:Z=3x₁−x₂ · Mathematics III, chapter 5 · asked 15×
- Two isotropic sources, equal amplitude, opposite phase · Propagation and Antenna, chapter 2 · asked 3×
- Two isotropic sources, same and opposite phase · Propagation and Antenna, chapter 2 · asked 3×
- 1-phase IM not self-starting; two methods · Electrical Machine, chapter 7 · asked 2×