distributed-computingconsensus

In 2PC what happens in case of failure to commit?


In 2PC what happens if coordinator asks 3 participants to commit and the second one fails with no response to the coordinator.

A client arrives asks the second node for the value, the second node has just come up but did not manage to commit so it returns an old value... Is that a fault of 2PC?


Solution

  • The missing part of 2PC - 2PR(2 Phases Read)

    If any of the commit messages lost or doesn't take effect for some reason at some participants, the resource remains at prepared state(which is uncertain), even after a restart, because prepared state must be persisted in non-volatile storage before the coordinator can ever send a commit message.

    Any one tries to read any uncertain resource, must refer to the coordinator to determine the exact state of that resource. Once determined, you can choose the right version of value.

    For your case, the second node returns the new value(with the help of coordinator to find out new value is really committed, and old value is stale).

    ---------- edit --------------

    Some implementations use Exclusive Lock during prepare phase, which means, once prepared, no other can read or write the prepared resource. So, before participant committed, any one tries to read, must wait.