5
votes

I was reading 3 phase commit protocol on wikipedia (http://en.wikipedia.org/wiki/Three-phase_commit_protocol) and here is a scenario that came to my mind where 3PC will fail:

Assume there are two participants A and B and a Coordinator C:

1)C sent precommit message to A and before it sends precommit message to B both A and C simulataneously fail. 2)The transaction is now restarted and B ends up aborting it because no reply from A. 3)A commits the transaction because its has already got the precommit message.

Wasn't this also the original problem in 2PC that 3PC was supposed to address? How is 3PC solving the problem? What am I missing. Thanks.

3

3 Answers

3
votes

Update:

Do the participants not commit then until they receive the doCommit message from the coordinator?

After receiving the preCommit message, the participants will wait first, and if a timeout happens, they will just go ahead to commit.

if the coordinator fails after sending the precommit message and at least one of the particpant having a precommit message, the rest in the system can just go ahead and commit since they already know the state on the system.

Yes, once the new coordinator sees that their is a participant that has already received the preCommit message, it will resend preCommit messages to other participants.

0
votes

If the co-ordinator should crash at any point, a recovery node can take over the transaction and query the state from any remaining replicas. If a replica that has committed the transaction has crashed, we know that every other replica has received a ‘prepare to commit’ message (otherwise the co-ordinator wouldn’t have moved to the commit phase), and therefore the recovery node will be able to determine that the transaction was able to be committed, and safely shepherd the protocol to its conclusion. If any replica reports to the recovery node that it has not received ‘prepare to commit’, the recovery node will know that the transaction has not been committed at any replica, and will therefore be able either to pessimistically abort or re-run the protocol from the beginning.

--cited from http://the-paper-trail.org/blog/consensus-protocols-three-phase-commit/

So I think the new coordinator will query the cohorts's state, only when all the live cohorts have received pre-commit message, then the new coordinator will send the do-commit message; otherwise, the transaction will be aborted.

0
votes

3PC only tolerate single-point failure, not multi-point failure. Actually, to make sure 3PC works, all of the following three conditions must be met:

  1. no network failure (i.e. no network partition, every message will get to destination before timeout if the dest machine is working (not crashing))

  2. at most one participant can fail (crash). To make it precise, if coordinator fails (crashes), all cohorts must not fail

  3. the participant machine can distinguish between timeout and fails (this is not trivial, consider when it crashes (i.e. electric is cut) right after timeout, where it could not write anything to persistent storage to remind itself that it was a timeout instead of a crash when it recovers)

None of these condition is practical. So I don't think 3PC can be implemented in real world.