CS 186 Exam Prep 12
Consensus
Motivation for Consensus
Consensus Setup
2
6
1
3
2
2
2
2
Paxos System Model
Requirements
Paxos Algorithm
Paxos Intuition
Phase 1 - Elect Leader
Phase 1 - Elect Leader
Phase 2 - Propose Ballot to Be Chosen
Phase 3 - Broadcast Chosen Value
Simple Example
PREPARE(1)
Simple Example
PREPARE(1)
PROMISE(1)
Simple Example
PREPARE(1)
PROMISE(1)
PROPOSE(1, “CS186”)
Simple Example
PREPARE(1)
PROMISE(1)
PROPOSE(1, “CS186”)
ACCEPT(1, “CS186”)
Simple Example
PREPARE(1)
PROMISE(1)
PROPOSE(1, “CS186”)
ACCEPT(1, “CS186”)
COMMIT(1, “CS186”)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROMISE(2)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(1, “CS186”) is ignored by participants!
PROPOSE(2, “CS286”)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
ACCEPT(2, “CS286”)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
ACCEPT(2, “CS286”)
COMMIT(2, “CS286”)
Conflict Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
ACCEPT(2, “CS286”)
COMMIT(2, “CS286”)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROMISE(2)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
PREPARE(3)
PROMISE(3)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
PREPARE(3)
PROMISE(3)
PROPOSE(3, “CS262A”)
Livelock Example
PREPARE(1)
PROMISE(1)
PREPARE(2)
PROPOSE(1, “CS186”)
PROMISE(2)
PROPOSE(2, “CS286”)
PREPARE(3)
PROMISE(3)
PROPOSE(3, “CS262A”)
PREPARE(4)
PROMISE(4)
And so on and so forth…
Fixing Livelock
Paxos Logging
Why Does N >= 2F + 1 Work?
Why Does N >= 2F + 1 Work?
Majority in round that leads to a chosen value
Why Does N >= 2F + 1 Work?
Suppose F=2 nodes crash after consensus has been achieved
Why Does N >= 2F + 1 Work?
In the next round, one node from the previous majority will be in the new majority
This node will respond with PROMISE(ballot_id, (old_ballot_id, v))
Other Ways to Learn Chosen Values
COMMIT Example
PREPARE(1)
PROMISE(1)
PROPOSE(1, “CS186”)
ACCEPT(1, “CS186”)
COMMIT(1, “CS186”)
Broadcast ACCEPT Example
PREPARE(1)
PROMISE(1)
PROPOSE(1, “CS186”)
ACCEPT(1, “CS186”)
Replicated Databases
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
6 | 1 |
7 | 2 |
8 | 3 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
6 | 1 |
7 | 2 |
8 | 3 |
Partition into Tablets
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
6 | 1 |
7 | 2 |
8 | 3 |
Partition into Tablets
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
6 | 1 |
7 | 2 |
8 | 3 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
Replicate Tablet
US-EAST
US-WEST
EU-WEST
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
3 | 0 |
4 | 1 |
5 | 0 |
a | b |
6 | 1 |
7 | 2 |
8 | 3 |
a | b |
6 | 1 |
7 | 2 |
8 | 3 |
a | b |
6 | 1 |
7 | 2 |
8 | 3 |
US-EAST
US-WEST
EU-WEST
Paxos group
Paxos group
Local Reads
A read for a specific tablet’s data can go to the nearest tablet’s replica
Replicated Writes
A write for a specific tablet initiates a Paxos protocol within the tablet’s Paxos replica group
Typically a distinguished leader begins the protocol. Clients send requests to the leader.
Worksheet
Attendance Link