Three-phase commit

A non-blocking commit protocol is one in where the failure of a single process does not prevent the other processes from deciding whether the transaction is committed or aborted. One way of enabling this behavior is by splitting the Commit phase into two:

  • 2.a  Pre-commit phase: After receiving PREPARED messages from the executors, P0 enters a prepare-to-commit phase. P0 sends preCommit messages to all executors. During this phase, the executors stage the change (maybe get locks), but don't actually commit.
  • 2.b  Commit phase: If P0 receives YES from all executors during the prepare-to-commit phase, it then sends COMMIT messages to all executors, thereby finishing the transaction. If any executors replies with NO or fails to reply during the prepare-to-commit phase, the transaction is aborted.

This is described in the following diagram:

Courtesy of Wikipedia, here the Coordinator and Cohorts are other names for P0 and the Executors, respectively

The pre-commit phase helps the algorithm to recover from the cases of process failure. Processes can now have timeouts, and if the executors don't hear back from P0, they can elect a new coordinator that can drive the transaction to completion. The new coordinator can query the rest of the executors and check the current state of the transaction; if it's in state 2.b  Commit, then it knows that some failure occurred but everyone intended to Commit.

On the other hand, if an executor replies to the new coordinator that it did not receive a Prepare-to-Commit message, then the new coordinator can assume that P0 failed before going to the the third phase. Since no other executors have made any changes yet, the transaction can be safely aborted.

This algorithm is not perfect, and is particularly susceptible to network failures.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset