Skip to content

Commit 6ff3591

Browse files
authored
One sentence per line
1 parent 611f6e9 commit 6ff3591

File tree

1 file changed

+58
-28
lines changed

1 file changed

+58
-28
lines changed

Lecture 15.md

+58-28
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Read Amazon's [Dynamo](https://www.allthingsdistributed.com/files/amazon-dynamo-
1818

1919
The following diagram shows a buggy implementation of the Chandy-Lamport snapshot algorithm.
2020

21-
Process `P2` initiates the snapshot, but then something goes wrong. Where's the bug?
21+
Process `P2` initiates the snapshot, but then something goes wrong.
22+
Where's the bug?
2223

2324
![Chandy-Lamport Snapshot Bug](./img/L15%20Chandy-Lamport%20Snapshot%20Bug.png)
2425

@@ -30,9 +31,11 @@ The Chandy-Lamport algorithm assumes FIFO delivery of all messages — irres
3031

3132
The bug is created by the fact that this diagram shows a FIFO anomaly created when the application message from `P2` event `F` ***overtakes*** the snapshot marker message.
3233

33-
As a result, `P1` event `D` is recorded in `P1`'s snapshot, but the event that caused it (`P2` event `F`) is missing from `P2`'s snapshot. Thus, our snapshot is not a ***consistent cut***.
34+
As a result, `P1` event `D` is recorded in `P1`'s snapshot, but the event that caused it (`P2` event `F`) is missing from `P2`'s snapshot.
35+
Thus, our snapshot is not a ***consistent cut***.
3436

35-
Remember that for a cut to be consistent, it must contain ***all*** events that led up to a certain point in time. So, the inclusion of event `D` in `P1`'s snapshot is the problem because this is effectively a ***message from the future***.
37+
Remember that for a cut to be consistent, it must contain ***all*** events that led up to a certain point in time.
38+
So, the inclusion of event `D` in `P1`'s snapshot is the problem because even `D` is the result of delivering a ***message from the future***.
3639

3740
This is an example of a situation in which a FIFO anomaly (out of order message delivery) leads to a causal anomaly (an inconsistent cut).
3841

@@ -48,11 +51,17 @@ This was a very simple run of Paxos involving:
4851
* Three acceptors, and
4952
* Two learners
5053

51-
In this example, the proposer `P` sent out `prepare` messages to a majority of the acceptors, which in this case, was two out of three; however, it would be been equally valid for `P` to have sent `prepare` messages to all the acceptors. In fact, doing so would be quite smart because it mitigates against message loss, because on balance, even if one message is lost, you have still communicated with the majority of acceptors.
54+
In this example, the proposer `P` sent out `prepare` messages to a majority of the acceptors, which in this case, was two out of three; however, it would be been equally valid for `P` to have sent `prepare` messages to all the acceptors.
55+
In fact, doing so would be quite smart because it mitigates against message loss, because on balance, even if one message is lost, you have still communicated with the majority of acceptors.
5256

53-
The same idea applies when the proposer listens for `promise` messages coming back from the acceptors. It only needs to hear from a majority of the acceptors before it can be happy. Exactly who those acceptors are is not important, and if it does hear back from all the acceptors then that's great, but it’s not a requirement. It just needs to hear from a majority.
57+
The same idea applies when the proposer listens for `promise` messages coming back from the acceptors.
58+
It only needs to hear from a majority of the acceptors before it can be happy.
59+
Exactly who those acceptors are is not important, and if it does hear back from all the acceptors then that's great, but it’s not a requirement.
60+
It just needs to hear from a majority.
5461

55-
So, when we speak of a ***majority***, we are speaking of at least the ***minimum*** majority. For instance, if there are five acceptors, then the minimum majority is three: but if we hear back from four or all five, then this is not a problem. The issue is that we must hear back from at least the minimum number of acceptors required to form a majority.
62+
So, when we speak of a ***majority***, we are speaking of at least the ***minimum*** majority.
63+
For instance, if there are five acceptors, then the minimum majority is three: but if we hear back either from four, or even all five, then this is not a problem.
64+
The issue is that we must hear back from at least the minimum number of acceptors required to form a majority.
5665

5766
There are other subtleties involved in this algorithm that we will now go through, including what happens when there is more than one proposer.
5867

@@ -71,69 +80,82 @@ One thing that was mentioned in the previous lecture was that three specific mil
7180
![Paxos Milestone 2](./img/L15%20Paxos%20Milestone%202.png)
7281

7382
Now, even though the other processes participating in the Paxos algorithm do not yet realise it, consensus has in fact been reached.
83+
7484
1. When the proposer(s) and learners receive `accepted(n,val)` messages from a majority of the acceptors.
7585

7686
![Paxos Milestone 3](./img/L15%20Paxos%20Milestone%203.png)
7787

7888
It is only now that the proposer(s) and the learners ***realise*** that consensus has already been reached
7989

80-
8190
## Paxos: The Full Algorithm (Mostly)
8291

8392
A run of the Paxos algorithm involves the following sequence of message exchanges - primarily between the proposer and acceptors:
8493

8594
1. ***The Proposer***
86-
Sends out `propose(n)` messages to at least the minimum number of acceptors needed to form a majority. The proposal number `n` must be:
95+
Sends out `propose(n)` messages to at least the minimum number of acceptors needed to form a majority.
96+
The proposal number `n` must be:
97+
8798
* Unique
8899
* Higher than any previous proposal number used by ***this*** proposer
89100

90-
It’s important to understand that the proposal number rules are applied to proposers ***individually***. Consequently, if there are multiple proposers in the system, there does not need to be any agreement between proposers about what the next proposal number should be.
101+
It’s important to understand that the proposal number rules are applied to proposers ***individually***.
102+
Consequently, if there are multiple proposers in the system, there does not need to be any agreement between proposers about what the next proposal number should be.
91103

92104
1. ***The Acceptor***
93-
When the acceptor receives a `prepare(n)` message, it asks itself *"Have I already agreed to ignore proposals with this proposal number?"*. If the answer is yes, then the message is simply ignored; but if not, it replies to the proposer with a `promise(n)` message.
105+
When the acceptor receives a `prepare(n)` message, it asks itself *"Have I already agreed to ignore proposals with this proposal number?"*.
106+
If the answer is yes, then the message is simply ignored; but if not, it replies to the proposer with a `promise(n)` message.
94107

95108
By returning a `promise(n)` message, the acceptor has now committed to ignore all messages with a proposal number smaller than `n`.
96109

97110
1. ***The Proposer***
98111
When the proposer has received `promise` messages from a majority of acceptors for a particular proposal number `n`, it sends an `accept(n,val)` message to a majority of acceptors containing both the agreed proposal number `n`, and the value `val` that it wishes to propose.
99112

100113
1. ***The Acceptor***
101-
When an acceptor receives an `accept(n,val)` message, it asks the same question as before: *"Have I already agreed to ignore messages with this proposal number?"*. If yes, it ignores the message; but if no, it replies with an `accepted(n,val)` both back to the proposer ***and*** broadcasts this acceptance to all the learners.
114+
When an acceptor receives an `accept(n,val)` message, it asks the same question as before: *"Have I already agreed to ignore messages with this proposal number?"*.
115+
If yes, it ignores the message; but if no, it replies with an `accepted(n,val)` both back to the proposer ***and*** broadcasts this acceptance to all the learners.
102116

103117
Up till now, we have assumed that there is only one proposer — but next, we must examine what happens if there are multiple proposers.
104118

105119
### What Happens If There Is More Than One Proposer?
106120

107-
In this scenario, we will make two changes. We will run the Paxos algorithm with two proposers, and for visual clarity, since learners do not actually take part in the steps needed to reach consensus, we will omit them from the diagram.
121+
In this scenario, we will make two changes.
122+
We will run the Paxos algorithm with two proposers, and for visual clarity, since learners do not actually take part in the steps needed to reach consensus, we will omit them from the diagram.
108123

109-
Let's say we have ***two*** proposers <code>P<sub>1</sub></code> and <code>P<sub>2</sub></code> and as before, three acceptors. (We also have two learners, but we'll ignore them for the time being.)
124+
Let's say we have ***two*** proposers <code>P<sub>1</sub></code> and <code>P<sub>2</sub></code> and as before, three acceptors.
125+
(We also have two learners, but we'll ignore them for the time being.)
110126

111-
Remember we previously stated that in situations where there are multiple proposers, these proposers must have already agreed on how they will ensure the uniqueness of their own proposal numbers. So, in this case, we will assume that:
127+
Remember we previously stated that in situations where there are multiple proposers, these proposers must have already agreed on how they will ensure the uniqueness of their own proposal numbers.
128+
So, in this case, we will assume that:
112129

113130
* Proposer <code>P<sub>1</sub></code> uses odd proposal numbers, and
114131
* Proposer <code>P<sub>2</sub></code> uses even proposal numbers
115132

116-
So, proposer <code>P<sub>1</sub></code> sends out a `prepare(5)` message to a majority of the acceptors. This is the first proposal number these acceptors have seen during this run of the protocol, so they are all happy to accept it and respond with `promise(5)` messages.
133+
So, proposer <code>P<sub>1</sub></code> sends out a `prepare(5)` message to a majority of the acceptors.
134+
This is the first proposal number these acceptors have seen during this run of the protocol, so they are all happy to accept it and respond with `promise(5)` messages.
117135

118136
Proposer <code>P<sub>1</sub></code> is seeking consensus for value `1`, so it now sends out `accept(5,1)` messages and the majority of acceptors respond with `accepted(5,1)`
119137

120138
![Multiple Proposers 1](./img/L15%20Multiple%20Proposers%201.png)
121139

122140
Ok, that's fine; we seem to have agreed on value `1`.
123141

124-
Meanwhile in Gotham City, proposer <code>P<sub>2</sub></code> has no idea what's been going on, and decides to send out a `prepare(4)` message to all the acceptors...
142+
Meanwhile, back in Gotham City, proposer <code>P<sub>2</sub></code> has no idea what's been going on, and decides to send out a `prepare(4)` message to all the acceptors...
125143

126144
![Multiple Proposers 2](./img/L15%20Multiple%20Proposers%202.png)
127145

128-
The `prepare(4)` message arrives at acceptors <code>A<sub>1</sub></code> and <code>A<sub>2</sub></code> ***after*** they have already agreed on proposal number `5`. Since they are now ignoring proposal numbers less than `5`, they simply ignore this message.
146+
The `prepare(4)` message arrives at acceptors <code>A<sub>1</sub></code> and <code>A<sub>2</sub></code> ***after*** they have already agreed on proposal number `5`.
147+
Since they are now ignoring proposal numbers less than `5`, they simply ignore this message.
129148

130149
Acceptor <code>A<sub>3</sub></code> however has not seen proposal number `4` before, so it happily agrees to it and sends back a `promise(4)` message to proposer <code>P<sub>2</sub></code>.
131150

132151
Proposer <code>P<sub>2</sub></code> is now left hanging.
133152

134-
It sent out `prepare` messages to all the acceptors but has only heard back from a minority of them. The rest have simply not answered, and given the way asynchronous communication works, <code>P<sub>2</sub></code> cannot know ***why*** it has not heard back from the other acceptors. They could have crashed, or they might be running slowly, or, as it turns out, the other acceptors have already agreed to <code>P<sub>1</sub></code>'s proposal and are now having his babies...
153+
It sent out `prepare` messages to all the acceptors but has only heard back from a minority of them.
154+
The rest have simply not answered, and given the way asynchronous communication works, <code>P<sub>2</sub></code> cannot know ***why*** it has not heard back from the other acceptors.
155+
They could have crashed, or they might be running slowly, or, as it turns out, the other acceptors have already agreed to <code>P<sub>1</sub></code>'s proposal and are now having his babies...
135156

136-
So, all <code>P<sub>2</sub></code> can do is wait for its timeout period, and if it doesn't hear back within that time, it concludes that proposal number `4` was a bad idea and tries again. This time, <code>P<sub>2</sub></code> shows up in a faster car (proposal number `6`).
157+
So, all <code>P<sub>2</sub></code> can do is wait for its timeout period, and if it doesn't hear back within that time, it concludes that proposal number `4` was a bad idea and tries again.
158+
This time, <code>P<sub>2</sub></code> shows up in a faster car (proposal number `6`).
137159

138160
![Multiple Proposers 3](./img/L15%20Multiple%20Proposers%203.png)
139161

@@ -144,9 +166,11 @@ But wait a minute, consensus (milestone 2) has ***already*** been reached, so th
144166

145167
So, here's where we must address one of the subtleties that we previously glossed over.
146168

147-
Previously, we stated only that if an acceptor receives a `prepare` message with a ***lower*** proposal number, it should simply ignore it. Well, OK, that's fine.
169+
Previously, we stated only that if an acceptor receives a `prepare` message with a ***lower*** proposal number, it should simply ignore it.
170+
Well, OK, that's fine.
148171

149-
But what about the case where we receive a proposal number that is ***higher*** than the last one? Here is where we need to further qualify ***how*** that `prepare` message should be handled.
172+
But what about the case where we receive a proposal number that is ***higher*** than the last one?
173+
Here is where we need to further qualify ***how*** that `prepare` message should be handled.
150174

151175
In this case, each acceptor must consider the following situation:
152176

@@ -155,10 +179,10 @@ In this case, each acceptor must consider the following situation:
155179
156180
How the acceptor reacts now depends on what has happened in between receiving the `prepare(n)` message and the `prepare(n+1)` message.
157181

158-
Either way, the acceptor cannot ignore the higher proposal number, so it is going to send out some sort of `promise` message; but this time, the acceptor must consider whether it has already accepted a value based on some earlier, lower proposal number.
182+
Either way, the acceptor cannot ignore the higher proposal number; so it needs to send out some sort of `promise` message. However, but this time, the acceptor must consider whether it has already accepted a value based on some earlier, lower proposal number.
159183

160184
* If no, then we accept the new proposal number with a `promise(n+1)` message as normal
161-
* If yes, then we accept the new proposal number with a `promise(n+1, ...)` message, but in addition, we are obligated to tell the new proposer that we've already accepted a value using an older proposal number.
185+
* If yes, then we accept the new proposal number with a `promise(n+1, ...)` message, but in addition, we are obligated to tell the new proposer that we've already agreed to go on a date with a proposer using a lower proposal number.
162186

163187
In the latter case, you can see that the `promise` message needs to carry some extra information.
164188

@@ -174,7 +198,9 @@ This extra information in the `promise` message effectively means: *"Ok, I'll mo
174198

175199
### So, What Should A Proposer Do with Such a Message?
176200

177-
Previously, we said that when a proposer receives sufficient `promise(n)` messages, it will then send out `accept(n,val)` messages. But here's where our description of the protocol needs to be refined. What should the proposer do if, instead of receiving a `promise(n)` message, it receives a <code>promise(n,(n<sub>old</sub>,val<sub>old</sub>))</code> message?
201+
Previously, we said that when a proposer receives sufficient `promise(n)` messages, it will then send out `accept(n,val)` messages.
202+
But here's where our description of the protocol needs to be refined.
203+
What should the proposer do if, instead of receiving a `promise(n)` message, it receives a <code>promise(n,(n<sub>old</sub>,val<sub>old</sub>))</code> message?
178204

179205
In our example, proposer <code>P<sub>2</sub></code> has received three `promise` messages:
180206

@@ -187,7 +213,9 @@ In this case, both `promise` messages contain the value `1` that was agreed upon
187213

188214
So, the rule is this: proposer <code>P<sub>2</sub></code> must look at all the older, already agreed upon values, and chose the value corresponding to the most recent, old proposal number.
189215

190-
This is pretty ironic (and amusing) really because proposer <code>P<sub>2</sub></code> now has no choice over what value to propose. It is constrained to propose the one value upon which consensus was most recently reached! So, the fact that it wants to send out its own proposal is somewhat redundant, because the only value it can propose is one upon which consensus has already been reached...
216+
This is pretty ironic (and amusing) really because proposer <code>P<sub>2</sub></code> now has no choice over what value to propose.
217+
It is constrained to propose the one value upon which consensus has most recently been reached!
218+
So, the fact that it wants to send out its own proposal is somewhat redundant, because the only value it can propose is one upon which consensus has already been agreed...
191219

192220
So, now we must revise rule 3 given above. Previously we stated:
193221

@@ -204,7 +232,8 @@ So now, <code>P<sub>2</sub></code> can only send out the message `accept(6,1)`.
204232

205233
Notice that <code>P<sub>2</sub></code> has not had to use the earlier proposal number `5`, but it was constrained to propose the value `1`, because this value has already been agreed upon.
206234

207-
So, what do the acceptors do now? They simply invoke rule 4 above and respond with `accepted(6,1)`.
235+
So, what do the acceptors do now?
236+
They simply invoke rule 4 above and respond with `accepted(6,1)`.
208237

209238
![Multiple Proposers 6](./img/L15%20Multiple%20Proposers%206.png)
210239

@@ -218,11 +247,12 @@ Let's isolate the messages that were exchanged between proposer <code>P<sub>2</s
218247
* <code>P<sub>2</sub></code> tried again with proposal number `6`
219248
* <code>A<sub>3</sub></code> went with the highest proposal number (`6`) and subsequently agreed to accept value `1`
220249

221-
As far as <code>A<sub>3</sub></code> is concerned, it thinks that value `1` was <code>P<sub>2</sub></code>'s idea. It has no clue that <code>P<sub>2</sub></code> was proposing a value already agreed upon by others.
250+
As far as <code>A<sub>3</sub></code> is concerned, it thinks that value `1` was <code>P<sub>2</sub></code>'s idea.
251+
It has no clue that <code>P<sub>2</sub></code> was proposing a value already agreed upon by others.
222252

223253
---
224254

225255
| Previous | Next
226256
|---|---
227257
| [Lecture 14](./Lecture%2014.md) | [Lecture 16](./Lecture%2016.md)
228-
258+

0 commit comments

Comments
 (0)