18

I understand that three phase commit was made to solve the problem of "two phase commit" when in the second phase the coordinator and the cohort fails at the same time it is impossible to know if the coordinator had decided on a commit message.

Apparently three phase commit aims to solve this problem by adding an extra phase. But don't you face the exact same problem during the third phase, if the coordinator and a cohort fails?

Ken
  • 365
  • 1
  • 6
  • 16
  • For posterity, here's how wikipedia defines 3 phase commit: http://en.wikipedia.org/wiki/Three-phase_commit_protocol – Gray Jun 26 '12 at 14:28
  • This is the gist of the article: The Three-phase commit protocol eliminates this problem by introducing the Prepared to commit state. If the coordinator fails before sending preCommit messages, the cohort will unanimously agree that the operation was aborted. The coordinator will not send out a doCommit message until all cohort members have ACKed that they are Prepared to commit. This eliminates the possibility that any cohort member actually completed the transaction before all cohort members were aware of the decision to do so – Ken Jun 26 '12 at 14:31
  • I just don't see how adding the extra phase will help with the problem – Ken Jun 26 '12 at 14:32

1 Answers1

13

In 3PC it is possible to figure out failed coordinator decision by querying remaining active cohorts. If any active cohort is in pre-commit state- that means that all of them agreed to commit (otherwise coordinator would not have sent pre-commit). And we need to commit the rest of the cohorts because failed ones might have committed.

If none of the cohorts is in pre-commit state - we can assume that coordinator has not sent 'commit' to any cohort, so no side effects has taken place and we can abort.

Here's good explanation: http://the-paper-trail.org/blog/consensus-protocols-three-phase-commit/

Sergey Zyuzin
  • 3,754
  • 1
  • 24
  • 17
  • "If any active cohort is in pre-commit state - that means that all of them agreed to commit (otherwise coordinator would not have sent pre-commit). And we need to commit the rest of the cohorts because failed ones might have committed." But what if the coordinator never received a yes from the failed cohort (after coordinator sent pre-commit, due to delay) and sent an abort, which the failed cohort received, aborted the transaction and then failed? – user1715122 Aug 14 '15 at 02:41