Saral Shiksha Yojna
Courses/Distributed Systems

Distributed Systems

CS3.401
Prof. Kishore KothapalliMonsoon 2025-264 credits

ACID + 2PC + 3PC + Blocking & In-Doubt States

NotesStoryCaveman
Unit 8 — Distributed Transactions, 2PC & 3PC

Fire in many caves — all light, or none light

Ugg teach big magic today: move shiny stones between many caves, and never lose one stone.

A distributed transaction — one job that touch stones in many caves at once. Ugg move 100 shiny stones from Cave-A to Cave-B: take from A, add to B. Must BOTH happen, or NEITHER. Only take happen — 100 stones vanish! Only add happen — stones double! Either way, magic broken.

The cave where job start, that cave is the coordinator — the chief. Every other cave holding stones is a participant — a hunter in the job. Chief boss the job; hunters do their part. To force all-or-nothing across caves, tribe use a commit protocol — every cave must vote to commit BEFORE any cave really commit.

Many caves mean new ways to break: a hunter fall down (site failure), a grunt get lost in wind (lost message), the path between caves cave-in (link failure), or a rockslide split tribe into two groups who cannot hear each other (network partition). Nasty part: to each side, the other side look just like it fell down.

ACID — the four tribe laws

Every stone-job must obey ACID:

Atomicity — all-or-nothing, whole hunt or no hunt. Consistency — never break tribe rules; stones counted same before and after. Isolation — two jobs at once no peek at each other half-done mess. Durability — once job done, done forever; even fire in cave no undo it. Across many caves, Atomicity is the HARD law — that is why 2PC and 3PC exist.

Two-Phase Commit — chief count grunts

Two-Phase Commit (2PC) is old reliable way. It trust the fail-stop model: broke caveman just fall and stop — he never lie, never send wrong grunt — maybe wake later. Every cave carve marks on a stone tablet (stable log) that survive fire.

Phase 1 — Prepare / Voting. Chief carve on tablet, force to stone, then howl PREPARE to all hunters. Each hunter think: can I do my part? If yes — carve to stone, grunt READY back. If no — carve , grunt ABORT.

Phase 2 — Decide. If chief hear READY from ALL hunters — carve to stone, howl COMMIT to all. Else — carve , howl ABORT. Every hunter carve the word and do it.

The moment touch chief's tablet is the point of no return:

Once chief carve COMMIT in stone, no fire, no falling-down, no anything take it back.

Reading the tablet after you wake

Hunter fall mid-job, wake, look at his tablet:

  • See redo(T), do the job.
  • See undo(T), take it back.
  • See only, no decision → ask chief. This is the scary in-doubt state.
  • See nothing → he never voted, chief must have aborted → undo(T).

In-doubt is bad. Hunter voted READY, so he still GRIP all the meat and berries (locks) the job touched — no other job may eat them — until he learn the word. Tablet keeps the lock list as so he grab them all back when he wake.

The blocking problem — hunters frozen

Now worst fire. All hunters carved . None got the decision. And the CHIEF FELL DOWN.

Why frozen? Chief maybe carved before falling — then some far hunter maybe already committed, so ALL must commit. OR chief fell before carving — safe to abort. Awake hunters cannot tell which! None can guess safe. So all WAIT — frozen, still gripping meat. That is the blocking problem, the big weakness of 2PC. Same trouble with a rockslide (partition): cut-off caves block, though never a wrong answer — chief just treat missing caves as fell-down and run on his side.

Ugg warn: 2PC also cost extra stone-carving (slow), and chief is single point of break.

Three-Phase Commit — tell more caves first

Three-Phase Commit (3PC) add one step so hunters can decide WITHOUT chief. It need strong luck: no rockslide (no partition), always at least one cave awake, at most caves break.

Phase 1 (PREPARE) — same as 2PC. Phase 2 (PRE-COMMIT) — chief hear all READY, howl PRE-COMMIT, and WAIT for at least hunters to grunt back before going on. Now the "we gonna commit" word carved at caves. Phase 3 (COMMIT) — chief howl final COMMIT (or ABORT); hunters do it.

If chief fall after Phase 2, awake hunters check each other:

Someone hold ? Pick new chief, howl COMMIT — no freeze. Nobody hold it? Word never went out, safe to abort. **3PC no block as long as caves break.**

Why tribe still use 2PC

3PC cost extra round of howling — more grunts, more carving, slower. Worse, it ASSUME no rockslide — but rockslides happen! In a partition, both sides may decide different — magic broken. So real tribes run 2PC plus strong chief-picking magic (Paxos or Raft): caves share the chief job, and when chief fall they vote a new chief fast. 2PC underneath, no single point of break, no need for 3PC's silly luck.

Ugg warn — no do this!

  • No say "2PC handle rockslide." It NO — partition make hunters block.
  • No say "3PC is what everyone use." It NOT — no-partition luck too much; tribes use 2PC + Raft/Paxos.
  • No mix up ("I vote yes," held by hunter) with (chief's final word). Different stones!
  • No forget: both and must be FORCED to stone BEFORE you grunt — else waking hunter lose the memory.

Ugg remember

  • Atomicity across caves is the whole point: commit at ALL caves or abort at ALL caves, never half.
  • 2PC = PREPARE + DECIDE. on chief's stone = point of no return.
  • Wake-up tablet rule: redo / undo / -only ask chief / nothing abort.
  • 2PC blocks when all hunters AND chief crashed — frozen, gripping locks.
  • **3PC = PREPARE + PRE-COMMIT ( acks) + COMMIT.** Pre-commit at caves breaks the block — but assumes no partition, so real tribes run 2PC + Raft/Paxos instead.
End of storyUnit 8 — Distributed Transactions, 2PC & 3PC · ACID + 2PC + 3PC + Blocking & In-Doubt States