Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 of 7
  1. 1. Half of a transfer
  2. 2. Prepare, then commit
  3. 3. Crash a coordinator and count the locks
  4. 4. The coordinator that does not come back
  5. 5. Which timeout is safe
  6. 6. Three phases, and why teams skip them
  7. 7. Votes, blocking and timeouts

Topic 2

Prepare, then commit

4 min read

Phase one: prepare

The coordinator sends a prepare request to every participant. Each participant does the work of the transaction short of committing. It writes its changes and a prepare record to its log, forces the log to disk, and keeps its locks. Then it replies.

A yes vote is a promise. The participant is saying that it can commit and will do so if told, even if it crashes and restarts first. A no vote is a refusal. A participant that votes no can abort at once.

Phase two: decide

If every vote was yes, the coordinator writes a commit record to its own log. If any vote was no, or one did not arrive, it writes an abort record. That write is the moment the transaction is decided. After it, the outcome cannot change.

The coordinator sends the decision. Each participant applies it, writes it to its log, releases its locks and acknowledges. When every acknowledgement is in, the coordinator can forget the transaction.

What it costs when nothing fails

Two round trips, and a forced log write at every participant and at the coordinator. A healthy transaction holds its locks for about 2 roundsmeasured: one to prepare and one to decide. The locks are what make the protocol expensive. They are held while the network is busy with someone else’s message.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms