目录
正在加载目录…
正在阅读专栏 分布式共识系统专栏 第 13 篇 · 共 59 篇 · 22%

MIT 6.5840:Lecture 04 Fault-Tolerant Agreement and Paxos

发布于 2026-09-21 10:05 · 最后编辑于 2026-09-21 18:14 · 版本 v2 · 字数 16,132 · 预计阅读 33 分钟 👁 20 次阅读

MIT 6.5840:Lecture 04 Fault-Tolerant Agreement and Paxos

本篇逐行译注 MIT 6.5840 Spring 2026 Lecture 4,围绕 Paxos 的 quorum、proposal、acceptor 持久化状态、协议安全性和 replicated state machine 展开。

TL;DR

  • Paxos 解决的问题:在服务器崩溃或网络 partition 的情况下,让一组机器对单个 value 达成一致,避免 primary/backup 的 split brain。
  • quorum 是基础:2f+1 台服务器用多数派工作,能够容忍 f 台 failure;任意两个 majority 必然相交。
  • 两阶段协议:proposer 先发送 prepare(n),再发送 accept(n, v);如果多数 acceptors 接受,value 就被 chosen。
  • 安全性关键:后续 proposal 必须复用 prepare 阶段见到的最高编号已接受 value;acceptor 的 n_p、n_a、v_a 必须持久化。
  • Paxos 的边界:单次 Paxos 只决定一个 value;实际系统通常用一串 Paxos instance 决定 log 中的每个 operation。

名词解释

名词含义本讲对应物
Consensus / Agreement多个参与者对同一个 value 达成一致Paxos instance 的目标
Proposer发起 proposal 并推动协议前进的角色选择编号和候选 value
Acceptor保存并接受 proposal 的角色持久化 n_p、n_a、v_a
Proposal numberproposal 的全局唯一且递增编号n,用于淘汰旧 proposal
Quorum能够作出协议决定的多数派3 台机器中的 2 台,或一般的 majority
Chosen某个 n/v 已被多数 acceptors 接受协议必须永久保持该 value
Split brain两个网络分区都以为自己可以独立推进majority intersection 用于避免它
RSMReplicated State Machine用连续 Paxos instance 复制 operation log

目录

章节内容
版本与来源固定 Lecture 4 与 Paxos 论文资料
原文逐行翻译按 l-paxos.txt 原顺序译注
机制小结提炼 quorum、两阶段 proposal 和 RSM 关系
本篇验收源文件、伪代码和图示边界

版本与来源

  • 课程版本:MIT 6.5840 Spring 2026。
  • Lecture 源文件:l-paxos.txt,351 行,SHA-256:9a8a203febfb4febf5a9d00e227df62ea5798341716277308498115b36093ee4。
  • 核心论文:Paxos Made Simple,Leslie Lamport,2001。
  • 课程日程:MIT 6.5840 Spring 2026 Schedule。
  • 翻译边界:英文源行按原顺序保留,随后紧跟中文译文;协议变量、消息名、状态名和伪代码保持原样。
  • 图片结论:源文件没有独立图片;[diagram: ...] 和原文中的状态/消息示意按文字顺序保留。

原文逐行翻译

从 GFS coordinator 到 Paxos

6.5840 2026 Lecture 4: Fault-Tolerant Agreement, Paxos

6.5840 2026 年 Lecture 4:Fault-Tolerant Agreement、Paxos。

From Paxos Made Simple, by Leslie Lamport, 2001

内容来自 Leslie Lamport 于 2001 年撰写的《Paxos Made Simple》。

remember GFS coordinator

回想 GFS coordinator。

what if the coordinator fails?

如果 coordinator failure 了呢?

GFS paper did not have much to say about what happens

GFS paper 对发生这种情况后会怎样没有太多说明。

many services built on GFS, so ought to be automatic and reliable

许多服务都建立在 GFS 之上,因此 coordinator 的恢复应当是 automatic 且 reliable 的。

what to do?

应该怎么办?

good overall goals:

总体上有两个好的目标:

high availability via replication

通过 replication 获得 high availability。

continue even if one server has crashed or can't be contacted

即使一台服务器 crash 或无法联系,也能继续运行。

"no single point of failure"

“no single point of failure”。

strongly consistent

strongly consistent。

look as if a single server

让系统看起来就像只有一台服务器。

为什么 fault-tolerant coordinator 很难

why designing a fault-tolerant coordinator is hard

为什么设计 fault-tolerant coordinator 很难。

suppose we want to use primary/backup replication

假设我们想使用 primary/backup replication。

we want clients to switch to backup if primary fails

我们希望 primary failure 时 clients 能切换到 backup。

a broken scheme:

一种有问题的方案:

[C1, C2, net, S1, S2]

[C1, C2, net, S1, S2](原文 diagram 占位,保留在此处。)

clients ordinarily send all ops to S1

clients 通常把所有 operations 发送给 S1。

S1 replies, and also forwards to S2 (for replication)

S1 回复 client,同时把 operation 转发给 S2(用于 replication)。

S1 is primary, S2 is backup

S1 是 primary,S2 是 backup。

if client gets no response from S1, re-send to S2

如果 client 没有收到 S1 的 response,就把 request 重新发送给 S2。

so the system can tolerate the failure of S1

这样系统就能容忍 S1 的 failure。

problem:

问题在于:

suppose network failure:

假设发生 network failure:

  C1 and S1 can communicate;

C1 和 S1 可以通信;

  C2 and S2 can communicate;

C2 和 S2 可以通信;

  but C1/S1 can't talk to C2/S2

但 C1/S1 无法与 C2/S2 通信。

on both sides, it seems like the other failed

从两边看来,对方似乎都 failure 了。

so both S1 and S2 will independently act as primary

于是 S1 和 S2 都会独立地以 primary 身份行动。

"network partition"

这叫作“network partition”。

"split brain"

这叫作“split brain”。

computers can't distinguish "server crashed" from "network broken"

计算机无法区分“server crashed”和“network broken”。

all they can observe is "no response to my request"

它们能观察到的只有“我的 request 没有 response”。

this comes up again and again in fault-tolerant designs!

这会在 fault-tolerant designs 中一次又一次出现!

for a while automated fault-tolerant fail-over seemed impossible

有一段时间,automated fault-tolerant fail-over 看起来是不可能的。

due to possibility of partition

原因是 partition 可能发生。

special external agent (a human) was used to switch primaries

人们会使用特殊的 external agent(人)来切换 primaries。

but that's a single point of failure

但这就是 single point of failure。

not very scalable for big systems

对于大型系统也不具备很好的 scalability。

Paxos 的目标与 quorum

around 1989 a few solutions appeared -- surprise!

大约在 1989 年,出现了几个解决方案——令人意外!

Paxos is the simplest, easiest to understand

Paxos 是其中最简单、最容易理解的一个。

inspired many widely used schemes

它启发了许多被广泛使用的 schemes。

we'll see Paxos in multiple papers later in the course

在课程后面的多篇论文中,我们会再次看到 Paxos。

incorporates ideas worth knowing

它包含许多值得掌握的 ideas。

Paxos provides fault-tolerant "agreement", "consensus"

Paxos 提供 fault-tolerant 的“agreement”或“consensus”。

to allow a set of computers to agree on a single value

它允许一组计算机就单个 value 达成一致。

for example, who the current primary is

例如,决定当前的 primary 是谁。

if some Paxos participants agree on X,

如果一些 Paxos participants 对 X 达成一致,

no participant will think some other value was agreed

那么无论发生什么,任何 participant 都不会认为另一个 value 被达成了一致。

despite computer or network failures

即使发生 computer 或 network failures。

no split brain even if partition

即使出现 partition,也不会发生 split brain。

Paxos performs just one agreement

一次 Paxos 只执行一次 agreement。

Real systems need a sequence of Paxos agreements

真实系统需要一系列 Paxos agreements。

e.g. a new agreement to recover after each coordinator failure

例如,每次 coordinator failure 后都需要一个新的 agreement 来恢复。

a key idea: quorums

一个关键 idea:quorums。

[diagram: three servers]

[diagram: three servers](原文 diagram 占位,保留在此处。)

an odd number of servers, e.g. 3

服务器数量取奇数,例如 3 台。

responses from a majority are required to do anything -- 2 out of 3

执行任何操作都需要 majority 的 responses——3 台中的 2 台。

if cannot contact a majority, cannot make progress

如果无法联系到 majority,就不能取得 progress。

(quorum idea is much older than Paxos)

(quorum idea 的历史远早于 Paxos。)

a useful property of majorities is that any two intersect

majorities 的一个有用性质是:任意两个 majorities 都相交。

if some information is known by a majority,

如果某个 majority 知道某条 information,

any later majority will contain at least one server that knows

那么之后的任何 majority 至少会包含一台知道这条 information 的服务器。

so each step in a quorum system typically looks like

因此,quorum system 中的每一步通常都像这样:

send message to all participants

向所有 participants 发送 message。

gather a majority of responses (but don't wait for more)

收集 majority 的 responses(但不等待更多 responses)。

  look at responses to find latest state

查看 responses,找到 latest state。

send updated state message to all participants

向所有 participants 发送 updated state message。

nice:

好处是:

tolerates minority of failed or slow servers

能够容忍少数 failed 或 slow servers。

overlap ensures state changes aren't lost

overlap 确保 state changes 不会丢失。

another property of majorities:

majorities 的另一个性质:

at most one network partition can contain a majority of servers

最多只有一个 network partition 能包含 majority 的 servers。

servers in the minority partitions won't get a quorum, won't proceed

minority partitions 中的 servers 无法获得 quorum,也无法继续推进。

so at most one partition will perform operations

因此最多只有一个 partition 会执行 operations。

helps avoid split brain

这有助于避免 split brain。

note: majority is out of all servers, not just out of live ones

注意:majority 是针对所有 servers 计算的,而不只是针对 live servers。

we say 2f+1 servers can tolerate f failed servers

我们说 2f+1 台 servers 可以容忍 f 台 failed servers。

since the remaining f+1 is a majority of 2f+1

因为剩余的 f+1 台是 2f+1 的 majority。

3 servers can tolerate 1 failed server

3 台 servers 可以容忍 1 台 failed server。

5 servers can tolerate 2 failed

5 台 servers 可以容忍 2 台 failed servers。

so you can get more availability (at some expense!)

因此可以获得更高的 availability(当然要付出一些代价!)。

Paxos 提供哪些保证

What properties does Paxos guarantee?

Paxos 保证哪些 properties?

correctness:

correctness:

if agreement reached, all agreeing servers agree on same value

如果达成 agreement,所有达成一致的 servers 都同意同一个 value。

once any agreement reached, never changes its mind

一旦达成任何 agreement,就永远不会改变决定。

fault-tolerance:

fault-tolerance:

can proceed if f+1 of 2f+1 (a majority) can communicate

如果 2f+1 台中的 f+1 台(一个 majority)可以通信,协议就能继续。

  i.e. can tolerate <= f failed servers

也就是说,可以容忍不超过 f 台 failed servers。

no majority -> cannot proceed

没有 majority → 无法继续。

  but will resume correctly once f+1 are again available

但一旦再次有 f+1 台可用,协议就会正确恢复。

  e.g. can survive a site-wide power failure

例如,它可以承受整个站点断电。

liveness:

liveness:

will reach agreement when a majority can communicate for long enough

当 majority 能够持续通信足够长时间时,最终会达成 agreement。

(this is a weak property)

(这是一个较弱的 property。)

Paxos 算法

let's look at the Paxos algorithm

下面看 Paxos algorithm。

this is a pseudo-code version of the paper

这是论文的 pseudo-code 版本。

to cope with failures during agreement protocol,

为了应对 agreement protocol 期间的 failures,

Paxos may go through multiple numbered rounds,

Paxos 可能要经历多个带编号的 rounds,

each driven by a proposer.

每个 round 都由一个 proposer 推动。

any server can propose if it thinks agreement hasn't yet been reached.

如果某台 server 认为 agreement 尚未达成,它就可以 propose。

two message exchanges per round:

每个 round 有两次 message exchanges:

prepare, prepare_ok

prepare、prepare_ok。

accept, accept_ok

accept、accept_ok。

definition: S accepts n/v

定义:S accepts n/v。

S responded accept_ok to accept(n, v)

即 S 对 accept(n, v) 回复了 accept_ok。

definition: n/v is chosen

定义:n/v is chosen。

a majority accepted n/v

即 majority 接受了 n/v。

the crucial property:

关键 property:

if v is chosen, any subsequent choice will also == v

如果 v 被 chosen,之后的任何 choice 也都必须 == v。

protocol will not change its mind

协议不会改变决定。

maybe a different proposer &c, but same value!

proposer 等可能不同,但 value 相同!

tricky b/c "chosen" is system-wide property

这很棘手,因为“chosen”是一个 system-wide property。

e.g. what if majority accepts, then proposer crashes?

例如,majority accepts 之后 proposer crash 了呢?

no server can tell locally that a value was chosen

任何单台 server 都无法仅根据本地状态判断某个 value 已经 chosen。

Proposer 与 acceptor 伪代码

proposer(v):

proposer(v):

choose n, unique and higher than any n seen so far

选择 n;它必须 unique,并且高于目前见过的任何 n。

send prepare(n) to all servers including self

向包括自己在内的所有 servers 发送 prepare(n)。

if prepare_ok(n, n_a, v_a) from majority:

如果从 majority 收到 prepare_ok(n, n_a, v_a):

v' = v_a with highest n_a; choose own v otherwise

令 v' 为具有最高 n_a 的 v_a;如果没有这样的 value,就选择自己的 v。

send accept(n, v') to all

向所有 servers 发送 accept(n, v')。

if accept_ok(n) from majority:

如果从 majority 收到 accept_ok(n):

  send decided(v') to all

向所有 servers 发送 decided(v')。

acceptor state:

acceptor state:

must persist across reboots

必须在 reboots 之间持久化。

n_p (highest prepare seen)

n_p(见过的最高 prepare 编号)。

n_a, v_a (highest accept seen)

n_a、v_a(见过的最高 accept 编号及其 value)。

acceptor's prepare(n) handler:

acceptor 的 prepare(n) handler:

if n > n_p

如果 n > n_p,

n_p = n

令 n_p = n。

reply prepare_ok(n, n_a, v_a)

回复 prepare_ok(n, n_a, v_a)。

else

否则,

reject

reject。

acceptor's accept(n, v) handler:

acceptor 的 accept(n, v) handler:

if n >= n_p

如果 n >= n_p,

n_p = n

令 n_p = n。

n_a = n

令 n_a = n。

v_a = v

令 v_a = v。

reply accept_ok(n)

回复 accept_ok(n)。

else

否则,

reject

reject。

Example 1:正常运行

example 1 (normal operation):

example 1(正常运行):

S1, S2, S3

S1、S2、S3。

but S3 is dead or slow

但 S3 已 dead 或很慢。

S1 starts proposal, n=5 v=A

S1 开始 proposal,n=5、v=A。

S1: p5 a5A dA

S1: p5 a5A dA

S2: p5 a5A dA

S2: p5 a5A dA

S3: dead...

S3: dead...

"p5" means Sx receives prepare(n=5)

“p5”表示 Sx 收到 prepare(n=5)。

"a5A" means Sx receives accept(n=5, v=A)

“a5A”表示 Sx 收到 accept(n=5, v=A)。

"dA" means Sx receives decided(v=A)

“dA”表示 Sx 收到 decided(v=A)。

these diagrams are not specific about who the proposer is

这些 diagrams 不特别说明 proposer 是谁。

we only care about what acceptors saw and replied

我们只关心 acceptors 看到了什么,以及回复了什么。

Proposer only needs to wait for a majority

Proposer 只需要等待 majority。

so it can continue even though S3 was down

因此即使 S3 down 了,协议也可以继续。

Partition 与已 chosen value

What would happen if S3 was alive, but network partitioned?

如果 S3 仍然 alive,但发生 network partition,会怎样?

and S3 wanted to propose value B?

如果 S3 想 proposal value B 呢?

S3's prepare would not assemble a majority

S3 的 prepare 无法组成 majority。

the homework question:

作业问题:

How does Paxos ensure that the following sequence of events can't

Paxos 如何确保下面的事件序列不可能发生?

happen? What actually happens, and which value is ultimately chosen?

实际会发生什么?最终 chosen 的 value 是哪个?

S1 wants to propose v=X, crashes after sending two accepts

S1 想 proposal v=X,发送两个 accepts 后 crash。

S2 wants v=Y

S2 想 proposal v=Y。

S1: p1 a1X

S1: p1 a1X

S2: p1 p2 a2?

S2: p1 p2 a2?

S3: p1 a1X p2 a2?

S3: p1 a1X p2 a2?

S3's prepare_ok to prepare(2) would have included "X"

S3 对 prepare(2) 的 prepare_ok 会包含“X”。

thus a2X

因此会是 a2X。

good: X had been chosen in the first round; chosen again in 2nd

很好:X 已在第一个 round 中 chosen;第二个 round 也会再次 chosen X。

the point:

关键点是:

if the system has already reached agreement, majority will know value.

如果系统已经达成 agreement,majority 就会知道这个 value。

any new majority of prepares will intersect that majority.

任何新的 prepare majority 都会与原来的 majority 相交。

so subsequent proposer will learn of already-agreed-on value,

因此后续 proposer 会得知已经达成一致的 value,

and send it in accept msgs

并在 accept messages 中发送这个 value。

Example 2:Concurrent proposers

example 2 (concurrent proposers):

example 2(concurrent proposers):

S1 starts proposing n=10

S1 开始 proposal,n=10。

S1 sends first accept v=X; meanwhile

S1 发送第一个 accept,value 为 X;与此同时,

S3 starts proposing n=11

S3 开始 proposal,n=11。

but S1 does not receive its proposal

但 S1 没有收到 S3 的 proposal。

S3 only has to wait for a majority of prepare responses

S3 只需要等待 majority 的 prepare responses。

S1: p10 a10X

S1: p10 a10X

S2: p10 p11

S2: p10 p11

S3: p10 p11 a11Y

S3: p10 p11 a11Y

S1 is still sending out accept messages...

S1 仍在发送 accept messages……

has a value been chosen?

某个 value 已经 chosen 了吗?

what will happen?

会发生什么?

what will S2 do if it gets a10X accept msg from S1?

如果 S2 收到 S1 发来的 a10X accept message,会做什么?

what will S1 do if it gets a11Y accept msg from S3?

如果 S1 收到 S3 发来的 a11Y accept message,会做什么?

what if S3 were to crash after just one a11Y (and not restart)?

如果 S3 在只发送了一个 a11Y 之后 crash(且不重启),会怎样?

important design pattern:

一个重要的 design pattern:

if there's evidence that agreement might have been reached already,

如果有证据表明 agreement 可能已经达成,

must act as if it had been.

就必须按照它已经达成来行动。

proposer may not know,

proposer 可能并不知道,

since its majority may overlap by just one with previous.

因为它的 majority 可能只与之前的 majority 相交一个 server。

nevertheless, must be conservative.

尽管如此,也必须采取保守行为。

Commit point 与最高编号 value

how about this:

再看这个例子:

S1: p10 a10X p12

S1: p10 a10X p12

S2: p10 p11 a11Y

S2: p10 p11 a11Y

S3: p10 p11 p12 a12X

S3: p10 p11 p12 a12X

has the system agreed to a value at this point?

在这个时刻,系统已经对某个 value 达成 agreement 了吗?

after all, a majority have accepted value "X"

毕竟,majority 已经接受了 value “X”。

what's the "commit point"?

什么是“commit point”?

i.e. exactly when has agreement been reached?

也就是,agreement 究竟在什么时候达成?

i.e. at what point can a server safely act on the agreement?

也就是,server 在什么时候可以安全地根据 agreement 行动?

i.e. at what point might some other server have already acted?

也就是,在什么时候其他某台 server 可能已经根据 agreement 行动?

after a majority has the same v_a? no -- why not? above counterexample

在 majority 拥有相同的 v_a 之后?不——为什么不行?看上面的 counterexample。

after a majority has the same v_a/n_a? yes

在 majority 拥有相同的 v_a/n_a 之后?是的。

why does the proposer need to pick v_a with highest n_a?

为什么 proposer 必须选择具有最高 n_a 的 v_a?

S1: p10 a10A p12

S1: p10 a10A p12

S2: p10 p11 a11B

S2: p10 p11 a11B

S3: p10 p11 a11B p12 a12?

S3: p10 p11 a11B p12 a12?

n=11 already agreed on vB

n=11 已经对 vB 达成 agreement。

n=12 sees both vA and vB, but must choose vB

n=12 同时看到了 vA 和 vB,但必须选择 vB。

why this makes sense: two cases:

这为什么合理:有两种情况:

  1. a value had been chosen before n=11
  1. 在 n=11 之前已经有一个 value 被 chosen。
n=11's prepares would have seen value and re-used it

n=11 的 prepares 会看到这个 value,并复用它。

so it's safe for n=12 to re-use n=11's value

因此 n=12 复用 n=11 的 value 是安全的。

  1. no value had been chosen before n=11
  1. 在 n=11 之前没有 value 被 chosen。
n=11 might have obtained a majority

n=11 可能已经获得了 majority。

so it's required for n=12 to re-use n=11's value

因此 n=12 必须复用 n=11 的 value。

Accept handler 的两个检查

why does accept handler check n >= n_p?

为什么 accept handler 要检查 n >= n_p?

w/o n >= n_p check, you could get this bad scenario:

如果没有 n >= n_p 检查,可能出现这种糟糕情况:

S1: p1 p2 a1A

S1: p1 p2 a1A

S2: p1 p2 a1A a2B

S2: p1 p2 a1A a2B

S3: p1 p2 a2B

S3: p1 p2 a2B

oops, for a while A was chosen, then changed to B!

糟糕,A 曾经被 chosen,随后却变成了 B!

why does accept handler update n_p = n?

为什么 accept handler 要更新 n_p = n?

required to prevent earlier n's from being accepted

这是为了阻止更早的 n 被接受。

server can receive accept(n,v) even though it never saw prepare(n)

server 可能收到 accept(n,v),即使它从未看到 prepare(n)。

without n_p = n, can get this bad scenario:

如果没有 n_p = n,可能出现这种糟糕情况:

S1: p1 a2B a1A p3 a3A

S1: p1 a2B a1A p3 a3A

S2: p1 p2 p3 a3A

S2: p1 p2 p3 a3A

S3: p2 a2B

S3: p2 a2B

oops, for a while B was chosen, then changed to A!

糟糕,B 曾经被 chosen,随后却变成了 A!

what if proposer S2 chooses n < S1's n?

如果 proposer S2 选择的 n 小于 S1 的 n 呢?

e.g. S2 didn't see any of S1's messages

例如,S2 没有看到 S1 的任何 messages。

S2 won't make progress, so no correctness problem

S2 无法取得 progress,因此不存在 correctness problem。

Acceptor crash 与持久化

what if an acceptor crashes+reboots after sending accept_ok?

如果 acceptor 在发送 accept_ok 后 crash 并 reboot 呢?

S1: p1 a1X

S1: p1 a1X

S2: p1 a1X reboot p2 a2?

S2: p1 a1X reboot p2 a2?

S3: p1 p2 a2?

S3: p1 p2 a2?

we know X was chosen; but will proposal #2 preserve X?

我们知道 X 已被 chosen;但 proposal #2 会保持 X 吗?

the story:

过程是这样的:

S2 is the only intersection between p1's and p2's majorities

S2 是 p1 和 p2 两个 majorities 唯一的交集。

thus the only evidence that Paxos already chose X

因此,S2 是 Paxos 已经选择 X 的唯一 evidence。

so S2 must return X in prepare_ok(n=2)

所以 S2 在 prepare_ok(n=2) 中必须返回 X。

so S2 must be able to recover its pre-crash n_a/v_a (and n_p)

所以 S2 必须能够恢复 crash 前的 n_a/v_a(以及 n_p)。

thus: if S2 wants to re-join this Paxos instance after crash,

因此,如果 S2 想在 crash 后重新加入这个 Paxos instance,

it must remember its n_p/v_a/n_a on disk.

它必须把 n_p/v_a/n_a 记在磁盘上。

if lost, do not re-join!

如果这些状态丢失,就不要重新加入!

what if an acceptor reboots after sending prepare_ok?

如果 acceptor 在发送 prepare_ok 后 reboot 呢?

does it have to remember n_p on disk?

它是否必须把 n_p 记在磁盘上?

if n_p not remembered, this could happen:

如果没有记住 n_p,可能出现:

S1: p10 a10X

S1: p10 a10X

S2: p10 p11 reboot a10X a11Y

S2: p10 p11 reboot a10X a11Y

S3: p11 a11Y

S3: p11 a11Y

11's did not receive a prepare_ok w/ X, so 11 proposed its own value Y

11 没有收到带 X 的 prepare_ok,因此 11 proposal 了自己的 value Y。

but just before that, X had been chosen!

但就在此之前,X 已经被 chosen 了!

b/c S2 did not remember to ignore a10X

因为 S2 没有记住应该忽略 a10X。

so: persisting n_p prevents this

因此,持久化 n_p 可以避免这种情况。

Liveness 与性能

can Paxos get stuck?

Paxos 会 stuck 吗?

yes, if there is not a majority that can communicate

会,如果不存在能够通信的 majority。

once net/computers repaired, Paxos will continue

网络或计算机修复后,Paxos 会继续。

Performance?

性能呢?

viewed as slow due to multiple communication rounds

由于需要多轮 communication rounds,Paxos 看起来很慢。

but lots of schemes for optimizing/batching

但存在许多优化和 batching 的 schemes。

viewed as expensive: need 3 replicas (not 2)

它也被认为很昂贵:需要 3 个 replicas(而不是 2 个)。

but hard to avoid in serious fault-tolerant systems

但对于严肃的 fault-tolerant systems,很难避免这些成本。

Paxos 与 replicated state machine

Many systems use Paxos internally, in a couple of styles.

许多系统在内部使用 Paxos,常见有几种方式。

To agree on a new coordinator when the old one doesn't respond.

当旧 coordinator 没有 response 时,就新的 coordinator 是谁达成一致。

To agree on when the backup should take over from the primary.

就 backup 何时应该从 primary 手中接管达成一致。

To agree on the sequence of operations in an RSM.

就 RSM 中 operations 的顺序达成一致。

How to build a database RSM using Paxos

如何使用 Paxos 构建 database RSM。

[diagram: clients, 3 replicas, paxos layer, log, DB layer]

[diagram: clients, 3 replicas, paxos layer, log, DB layer](原文 diagram 占位,保留在此处。)

clients can send operations to any replica

clients 可以向任意 replica 发送 operations。

servers use Paxos to agree on each next op to append to the log

servers 使用 Paxos 对下一个要 append 到 log 的 operation 达成一致。

servers apply agreed+logged operations to state (e.g. k/v DB)

servers 把已经 agreed 且 logged 的 operations 应用到 state(例如 k/v DB)。

in log order

按照 log order 执行。

example:

例子:

client sends "x=1" to S1

client 向 S1 发送“x=1”。

S1 picks log entry 3

S1 选择 log entry 3。

S1 uses Paxos to get all servers to agree that entry 3 holds x=1

S1 使用 Paxos 让所有 servers 对 entry 3 保存 x=1 达成一致。

after agreement ("commit"), all DBs execute x=1

agreement(“commit”)之后,所有 DB 都执行 x=1。

example:

例子:

client sends "x?" to S2

client 向 S2 发送“x?”。

S2 picks log entry 4

S2 选择 log entry 4。

S2 uses Paxos to get all servers to agree that entry 4 holds "x?"

S2 使用 Paxos 让所有 servers 对 entry 4 保存“x?”达成一致。

after agreement, S2's DB executes "x?"

agreement 之后,S2 的 DB 执行“x?”。

and replies to the client

并向 client 回复。

why a log?

为什么需要 log?

help cope with concurrency

它有助于处理 concurrency。

need to hold later operations until earlier ones have committed

必须让后面的 operations 等待,直到前面的 operations committed。

help replicas catch up

它有助于 replicas 追赶状态。

not in majority, briefly offline, &c

例如某个 replica 不在 majority 中,短时间 offline,等等。

usually only the tail of the log is kept, along with "state"

通常只保留 log 的 tail,以及当前的“state”。

后续内容

next:

接下来:

guest lecture by a Go wizard

一位 Go wizard 的 guest lecture。

then Raft

然后是 Raft。

Lab 1 due tomorrow

Lab 1 明天截止。

机制小结

Quorum intersection

mermaid
flowchart LR
    S1[Server 1] --- Q1[多数派 Q1]
    S2[Server 2] --- Q1
    S2 --- Q2[多数派 Q2]
    S3[Server 3] --- Q2

在 3 台服务器中,任意两个 2-server majority 至少共享一台 server。Paxos 依靠这个交集把“过去可能已经 chosen 的 value”带入未来 proposal,避免新 proposal 擅自改 value。

单次 Paxos 与日志

mermaid
flowchart TD
    Client[Client operation] --> Instance[Paxos instance i]
    Instance --> Entry[Log entry i]
    Entry --> State[Replica state machine]
    State --> Reply[Client reply]

单个 Paxos instance 只能决定一个 value;数据库 RSM 把 operation 放入连续 log entry,并按 entry 顺序应用。这样既能协调并发请求,也能让短暂离线的 replica 通过 log catch up。

本篇验收

  • 已固定官方 l-paxos.txt 共 351 行,SHA-256 为 9a8a203febfb4febf5a9d00e227df62ea5798341716277308498115b36093ee4。
  • Lecture 英文非空源行按原顺序逐行译注;协议伪代码、状态变量、Paxos 状态示意和 [diagram: ...] 占位均保留。
  • 本源文件没有独立 raster image;本篇没有把论文中的外部 Figure 当作本地图片伪造嵌入。
  • 本篇是 Spring 2026 lecture track 的第 4 篇;下一篇为 guest lecture,随后进入 Raft。

参考资料

← 返回列表
← 上一篇 MIT 6.5840:Lecture 03 GFS 下一篇 → MIT 6.5840:Lecture 05 Go Patterns

评论 (0)

暂无评论,来留下第一条吧。
登录 或 注册 后才能发表评论