You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -30,9 +31,11 @@ The Chandy-Lamport algorithm assumes FIFO delivery of all messages — irres
30
31
31
32
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.
32
33
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***.
34
36
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***.
36
39
37
40
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).
38
41
@@ -48,11 +51,17 @@ This was a very simple run of Paxos involving:
48
51
* Three acceptors, and
49
52
* Two learners
50
53
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.
52
56
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.
54
61
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.
56
65
57
66
There are other subtleties involved in this algorithm that we will now go through, including what happens when there is more than one proposer.
58
67
@@ -71,69 +80,82 @@ One thing that was mentioned in the previous lecture was that three specific mil
It is only now that the proposer(s) and the learners ***realise*** that consensus has already been reached
79
89
80
-
81
90
## Paxos: The Full Algorithm (Mostly)
82
91
83
92
A run of the Paxos algorithm involves the following sequence of message exchanges - primarily between the proposer and acceptors:
84
93
85
94
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
+
87
98
* Unique
88
99
* Higher than any previous proposal number used by ***this*** proposer
89
100
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.
91
103
92
104
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.
94
107
95
108
By returning a `promise(n)` message, the acceptor has now committed to ignore all messages with a proposal number smaller than `n`.
96
109
97
110
1.***The Proposer***
98
111
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.
99
112
100
113
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.
102
116
103
117
Up till now, we have assumed that there is only one proposer — but next, we must examine what happens if there are multiple proposers.
104
118
105
119
### What Happens If There Is More Than One Proposer?
106
120
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.
108
123
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.)
110
126
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:
112
129
113
130
* Proposer <code>P<sub>1</sub></code> uses odd proposal numbers, and
114
131
* Proposer <code>P<sub>2</sub></code> uses even proposal numbers
115
132
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.
117
135
118
136
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)`
Ok, that's fine; we seem to have agreed on value `1`.
123
141
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...
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.
129
148
130
149
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>.
131
150
132
151
Proposer <code>P<sub>2</sub></code> is now left hanging.
133
152
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...
135
156
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`).
@@ -144,9 +166,11 @@ But wait a minute, consensus (milestone 2) has ***already*** been reached, so th
144
166
145
167
So, here's where we must address one of the subtleties that we previously glossed over.
146
168
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.
148
171
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.
150
174
151
175
In this case, each acceptor must consider the following situation:
152
176
@@ -155,10 +179,10 @@ In this case, each acceptor must consider the following situation:
155
179
156
180
How the acceptor reacts now depends on what has happened in between receiving the `prepare(n)` message and the `prepare(n+1)` message.
157
181
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.
159
183
160
184
* 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.
162
186
163
187
In the latter case, you can see that the `promise` message needs to carry some extra information.
164
188
@@ -174,7 +198,9 @@ This extra information in the `promise` message effectively means: *"Ok, I'll mo
174
198
175
199
### So, What Should A Proposer Do with Such a Message?
176
200
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?
178
204
179
205
In our example, proposer <code>P<sub>2</sub></code> has received three `promise` messages:
180
206
@@ -187,7 +213,9 @@ In this case, both `promise` messages contain the value `1` that was agreed upon
187
213
188
214
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.
189
215
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...
191
219
192
220
So, now we must revise rule 3 given above. Previously we stated:
193
221
@@ -204,7 +232,8 @@ So now, <code>P<sub>2</sub></code> can only send out the message `accept(6,1)`.
204
232
205
233
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.
206
234
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)`.
@@ -218,11 +247,12 @@ Let's isolate the messages that were exchanged between proposer <code>P<sub>2</s
218
247
* <code>P<sub>2</sub></code> tried again with proposal number `6`
219
248
* <code>A<sub>3</sub></code> went with the highest proposal number (`6`) and subsequently agreed to accept value `1`
220
249
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.
0 commit comments