Jas
Jas

Reputation: 15103

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?

Upvotes: 2

Views: 1175

Answers (2)

ideawu
ideawu

Reputation: 2337

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.

Upvotes: 3

Remus Rusanu
Remus Rusanu

Reputation: 294287

If the coordinator is asking them to commit, then it means that all participants have already answered that they are prepared to commit. Prepared means that the participant is guaranteed to be able to commit. There is no failure. If the node vanished in a meteor strike, then the node is restored from the HA/DR data and the restored mode resumes the transaction and proceeds with the commit.

Participants in 2PC are durable, persisted coordinators capable of backup and restore. In theory in the case when one of the participants cannot be restored, then every participant, and the coordinators, are all restored back in time before the last coordinated transaction. In practice, all coordinators support enforcing cases when a participant is lost and the transaction will be manually forced into one state or another, see Resolve Transactions Manually or Resolving indoubt transactions manually.

Upvotes: 1

Related Questions