Is 2-Phase commit safe or not

360 views Asked by At

I find many readings that say 2PC is safe, which means it will either commit a transaction or rollback. More specifically, [If one commits, no one aborts; If one aborts, no one commits]. (http://www0.cs.ucl.ac.uk/staff/B.Karp/gz03/f2010/gz03-lecture6-2PC.pdf)

From Wikipedia, I know in commit phase, all processes will do the following things:

  1. The coordinator sends a commit message to all the participants.
  2. Each participant completes the operation and releases all the locks and resources held during the transaction.
  3. Each participant sends an acknowledgment to the coordinator.
  4. The coordinator completes the transaction when all acknowledgments have been received.

I wonder if in stage 1, the coordinator fails after it sent a message to several participants, which means some participants will receive the commit message while others will not. Then those who received will commit while others will still be blocked. So I think 2PC does not ensure safety here?

1

There are 1 answers

0
Alexander Ushakov On BEST ANSWER

As the article from Wikipedia says:

If the coordinator fails permanently, some participants will never resolve their transactions: After a participant has sent an agreement message to the coordinator, it will block until a commit or rollback is received.

Key word here is “permanently”. In your first link 2PC algorithm is also marked safe only for controller restarts not permanent dead.

So 2PC is safe while its components can interact (even with restarts, connection losses and other temporary problems).