MIT 6.5840:Lecture 08 Consistency and Linearizability
本篇逐行译注 MIT 6.5840 Spring 2026 Lecture 8,覆盖 consistency models、linearizability、history、linearization point、stale read、duplicate request suppression,以及 eventual consistency。
MIT 6.5840:Lecture 08 Consistency and Linearizability
TL;DR
- Consistency model:规定不同 clients 对同一 service 的 views 之间允许存在什么关系。
- Linearizability:每个 operation 都能在自己的 start 和 finish 之间找到一个 linearization point,并且所有结果等价于按这些 points 顺序执行的 serial spec。
- Linearizability 的约束:不允许 stale reads、split brain、忘记已经完成的 writes,也不允许不同 clients 以不同顺序看到 concurrent writes。
- Raft 与 linearizability:Raft 用来构建 fault-tolerant linearizable services;Lab 4 的 KV service 也必须满足这一性质。
- Eventual consistency:通过放宽 stale read、write order 和跨 client view 的约束换取性能与 availability,但不能直接支持所有 operations,例如
test-and-set。
名词解释
| 名词 | 含义 | 本讲对应物 |
|---|---|---|
| Consistency model | 描述不同 clients 如何看到 service 的规范 | linearizability、eventual consistency |
| History | 并发 operations 的时间线及其参数、返回值 | 用于事后检查 linearizability |
| Linearization point | operation 在 start 与 finish 之间抽象出的单一生效时刻 | 将 concurrent operations 排成 serial order |
| Linearizability | 结果等价于某个满足实时约束的 serial execution | Raft/Lab 4 的目标性质 |
| Stale read | 读到了已经被较新 write 取代的旧值 | linearizability 不允许 |
| Eventual consistency | 更新最终传播到 replicas,但短期允许不同 views | 更高性能与 availability 的弱模型 |
目录
| 章节 | 内容 |
|---|---|
| 版本与来源 | 固定 Lecture 8 源文件 |
| 原文逐行翻译 | 按 l-linearizability.txt 顺序译注 |
| 机制小结 | linearizability 的定义、代价与弱一致性 |
| 本篇验收 | 源行、ASCII 图示和边界记录 |
版本与来源
- 课程版本:MIT 6.5840 Spring 2026。
- Lecture 源文件:l-linearizability.txt,346 行,非空源行 301 行,SHA-256:
45901e8bc6833ddea0f1c6c47897a0c05b2347d92485047305f2281e3c27f7d6。 - 相关资料:Jepsen consistency models。
- 课程日程:MIT 6.5840 Spring 2026 Schedule。
- 翻译边界:英文源行按原顺序保留,随后给出中文译文;
put/get、RPC、Raft、GFS、history、linearization point、consistency model 和 operation 名称保留原样。 - 图片结论:本 Lecture 源文件没有独立图片文件;
[simple client/server diagrams]、[client / network / server diagram]、[diagram: ...]和 ASCII 时序图均按原位置保留。
原文逐行翻译
Consistency model 与动机
6.5840 2026 Lecture 8: Consistency, Linearizability
6.5840 2026 年 Lecture 8:Consistency、Linearizability。
today's topic: consistency models, specifically linearizability
今天的主题:consistency models,具体来说是 linearizability。
consistency model:
consistency model:
a spec for the relationship of different clients' views of a service
关于不同 clients 对同一个 service 的 views 之间关系的 spec。
I'll focus on key/value storage with network clients
我将聚焦于带有 network clients 的 key/value storage。
given a bunch of put/get calls, what outcome(s) are valid?
给定一批 put/get calls,哪些 outcome(s) 是有效的?
assuming individual operations, in isolation, are correct
假设每个 individual operation 单独来看都是正确的。
in ordinary sequential programming, there's nothing to talk about:
在普通的 sequential programming 中,没有什么可讨论的:
we expect a read to yield the last written value
我们期望一次 read 返回最近写入的 value。
when might there be any question about what's correct?
什么时候才会产生“什么是正确的”这个问题?
[simple client/server diagrams]
[simple client/server diagrams]。
read simultaneous with write
read 与 write 同时发生。
replicas
replicas。
caches
caches。
failure, recovery
failure、recovery。
lost messages + retransmission
丢失的 messages + retransmission。
why does a storage system need an explicit consistency model?
为什么 storage system 需要一个明确的 consistency model?
for applications, hard to be correct w/o guarantees from storage
对 applications 来说,如果 storage 不提供保证,就很难写出正确程序。
e.g. producer computes, then executes
例如 producer 先计算,然后执行:
put("result", 27)
put("result", 27)。
put("done", true)
put("done", true)。
consumer executes
consumer 执行:
while get("done") == false:
while get("done") == false:
pause
pause。
v = get("result")
v = get("result")。
is v guaranteed to be 27?
能保证 v 是 27 吗?
for services, hard to design/optimize w/o a specification
对 services 来说,如果没有 specification,也很难设计或优化。
e.g. OK for clients to read from GFS replicas? from Raft followers?
例如:允许 clients 从 GFS replicas 读取吗?允许从 Raft followers 读取吗?
there are lots of consistency models
consistency models 有很多种。
today: linearizability
今天讨论:linearizability。
but we'll also see:
但我们还会看到:
eventual consistency
eventual consistency。
causal consistency
causal consistency。
fork consistency
fork consistency。
serializability
serializability。
driving force: tradeoffs among
背后的驱动力是以下因素之间的 tradeoffs:
performance
performance。
simplicity
simplicity。
fault tolerance
fault tolerance。
Linearizability 的定义
linearizability
linearizability。
it's a specification -- a requirement for how a service must behave
它是一种 specification——规定 service 必须如何行为的 requirement。
from clients' point of view: from outside the service
从 clients 的角度看:也就是从 service 外部看。
it's usually what people mean by "strong consistency".
它通常就是人们所说的“strong consistency”。
few "anomalies" / surprises
“anomalies”或 surprises 很少。
a gold standard
它是 gold standard。
but rules out many optimizations.
但它排除了许多 optimizations。
important for us:
对我们来说很重要的是:
Raft is intended for building fault-tolerant linearizable services
Raft 的目标是构建 fault-tolerant linearizable services。
Lab 4 will be a linearizable key/value store on Raft
Lab 4 将是一个建立在 Raft 之上的 linearizable key/value store。
starting point
起点。
we assume that there's a serial spec for what individual operations do
我们假设存在一个 serial spec,规定 individual operations 的行为。
serial = a single server executing operations one at a time
serial = 一个 server 一次执行一个 operation。
db[]
db[]。
put(k, v):
put(k, v):
db[k] = v
db[k] = v。
return true
return true。
get(k):
get(k):
return db[k]
return db[k]。
no surprises here.
这里没有 surprises。
Concurrent operations 与 history
what about concurrent client operations?
那么 concurrent client operations 呢?
"concurrent" = overlap in time
“concurrent” = 在时间上重叠。
a client sends an RPC request;
一个 client 发送 RPC request;
takes some time crossing the network;
它需要一些时间穿过 network;
server computes, talks to replicas, &c;
server 进行计算、与 replicas 通信,等等;
reply moves through network;
reply 穿过 network;
client receives reply
client 收到 reply。
other clients may send/receive/wait during that time!
在此期间,其他 clients 可能发送、接收或等待!
the serial spec doesn't tell us what results are legal
serial spec 没有告诉我们哪些结果是合法的。
we need a way to describe concurrent scenarios,
我们需要一种描述 concurrent scenarios 的方法,
so we can talk about which results are/aren't allowed
这样才能讨论哪些结果被允许、哪些不被允许。
definition: a history
定义:history。
describes a time-line of possibly-concurrent operations
它描述一系列可能 concurrent operations 的时间线。
each operation tagged w/ client start and finish times
每个 operation 都标记有 client 的 start 和 finish times。
time client sent RPC request; time received reply
包括 client 发送 RPC request 的时间,以及收到 reply 的时间。
as well as argument and return values
还包括 argument 和 return values。
example:
例子:
C1: |-Wx1-| |-Wx2-|
C1: |-Wx1-| |-Wx2-|。
C2: |---Rx2---|
C2: |---Rx2---|。
the x-axis is real time
x-axis 是 real time。
|- indicates the time at which client sent request
|- 表示 client 发送 request 的时间。
-| indicates the time at which the client received the reply
-| 表示 client 收到 reply 的时间。
"Wx1" means put(x, 1)
“Wx1”表示 put(x, 1)。
"Rx2" means get(x) -> 2
“Rx2”表示 get(x) -> 2。
records assumed to start with some undefined value
假设记录开始时 value 是某个 undefined value。
C1 sent put(x, 1), recv reply, sent put(x, 2), recv reply
C1 发送 put(x, 1)、收到 reply,再发送 put(x, 2)、收到 reply。
writes have responses, signifying completion
writes 都有 responses,表示 operation 已完成。
C2 sent get(x), recv reply=2
C2 发送 get(x),收到 reply=2。
a history is a trace of what clients saw (or might see)
history 是 clients 已经看到(或可能看到)的 trace。
used to check whether the execution was linearizable
它用于检查 execution 是否 linearizable。
used by designers in "would this be OK" thought experiments
designers 也可以用它进行“这样做是否 OK”的 thought experiments。
definition: a history is linearizable if
定义:如果一个 history 满足以下条件,它就是 linearizable 的:
- you can find a point in time for each operation
- 对每个 operation,都能找到一个时间点,
between its start and finish, and
且该时间点位于 operation 的 start 和 finish 之间;
- the history's result values are the same as serial
- history 的 result values 与 serial
execution in point order.
按这些时间点顺序执行时的结果相同。
Linearization point:示例 1
example history 1:
示例 history 1:
|--Wx1--| |--Wx2--|
|--Wx1--| |--Wx2--|。
|----Rx2----|
|----Rx2----|。
|--Rx1--|
|--Rx1--|。
is this history linearizable?
这个 history 是 linearizable 的吗?
can we find a linearization point for each operation?
我们能否为每个 operation 找到一个 linearization point?
we may need to try a few different point assignments.
我们可能需要尝试几种不同的 point assignments。
this order of points satisfies the rules:
下面这个 points 顺序满足规则:
Wx1 Rx1 Wx2 Rx2
Wx1 Rx1 Wx2 Rx2。
- each point lies between start and finish.
- 每个 point 都位于 start 和 finish 之间。
- the sequence satisfies the serial put/get spec.
- 这个 sequence 满足 serial put/get spec。
so: yes, this history is linearizable
所以:是的,这个 history 是 linearizable 的。
(and it's an answer to The Question)
(这也是 The Question 的一个答案。)
note: either read could have returned either 1 or 2.
注意:任意一个 read 都可能返回 1 或 2。
so linearizability often allows multiple different outcomes.
因此 linearizability 往往允许多个不同的 outcomes。
so we often can't predict in advance, but we can check afterwards.
所以我们通常无法提前预测结果,但可以事后检查。
note: the service may not have executed the operations at those points!
注意:service 可能根本没有在这些 points 执行 operations!
we're not concerned here with how the service operated internally
我们不关心 service 内部究竟如何运行。
we only care that the client-visible results could have
我们只关心 client-visible results 是否可能
resulted from execution in some point order
由按照某种 point order 的 execution 产生。
what can we do with the linearizability definition?
利用 linearizability definition,我们能做什么?
for designer: could this optimization result in non-linearizable results?
对 designer:这个 optimization 会不会产生 non-linearizable results?
for programmer: what can I assume / expect as a client?
对 programmer:作为 client,我可以假设或期待什么?
for testing: generate requests, check observed history.
对 testing:生成 requests,检查 observed history。
why is it called "linearizability"?
为什么称为“linearizability”?
the linearization points turn concurrent operations
linearization points 把 concurrent operations 转换成
into a serial execution -- "linear".
serial execution——也就是“linear”。
thus "linearizable" in the sense that the results are the same
因此称为“linearizable”,是因为结果相同,
as some linear execution of the operations.
就像 operations 的某种 linear execution 一样。
更多 history 示例
example 2:
示例 2:
|-Wx1-| |----Wx2----|
|-Wx1-| |----Wx2----|。
|-Rx1-|
|-Rx1-|。
linearizable?
linearizable 吗?
if yes, linearization points?
如果是,linearization points 在哪里?
so: concurrent read/write can go either way
所以:concurrent read/write 可以采用任意一种顺序。
example 3: like example 2, but...
示例 3:类似示例 2,但是……
|-Wx1-| |----Wx2----|
|-Wx1-| |----Wx2----|。
|---Rx2---|
|---Rx2---|。
|-Rx1-|
|-Rx1-|。
we can try a few assignments of linearization points.
我们可以尝试几种 linearization points assignments。
how about Wx1 Wx2 Rx2 Rx1?
比如 Wx1 Wx2 Rx2 Rx1 呢?
not valid because "Wx2 Rx1" doesn't conform to serial spec.
这不合法,因为 Wx2 Rx1 不符合 serial spec。
how to show something isn't linearizable?
如何证明某个东西 不是 linearizable 的?
show that no assignment of points works.
证明不存在任何有效的 points assignment。
i.e. breaks either time rule or value rule.
也就是说,它违反了 time rule 或 value rule。
no assignment works for example 2!
示例 2 中没有任何 assignment 能够奏效!
Wx2's point must be before Rx2's point
Wx2 的 point 必须位于 Rx2 的 point 之前。
so Wx2's point is also before Rx1's point
所以 Wx2 的 point 也位于 Rx1 的 point 之前。
so the second read got an impossible value
因此第二次 read 得到了一个不可能的 value。
thus, if a system can produce this history, we know the
因此,如果一个 system 能产生这样的 history,我们就知道该
system isn't linearizable: has a bug, or never promised linearizability.
system 不是 linearizable 的:它要么有 bug,要么从未承诺 linearizability。
the Rx1 would have been legal if there had been no Rx2
如果不存在 Rx2,那么 Rx1 本来可以是合法的。
reads -- not just writes -- can affect what's subsequently legal
reads——而不只是 writes——也会影响之后哪些结果是合法的。
so, if we want linearizability:
因此,如果我们希望满足 linearizability:
once any read sees a write, all strictly-subsequent reads must also see it.
一旦某个 read 看到了某个 write,所有 strictly-subsequent reads 也必须看到它。
rules out split-brain
这排除了 split-brain。
can't forget a revealed write
不能忘记一个已经暴露给 client 的 write。
rules out e.g. forgetting data due to a crash
这排除了例如因为 crash 而忘记数据。
GFS is not linearizable: it can produce example 3 since
GFS 不是 linearizable 的:它可能产生示例 3,因为
the Rx1 could come from a replica that hasn't yet been updated.
Rx1 可能来自一个尚未更新的 replica。
if we wanted GFS to be linearizable,
如果我们希望 GFS 是 linearizable 的,
one approach is to have client reads go through the primary too.
一种方法是让 client reads 也经过 primary。
would be slower!
但这样会更慢!
Concurrent writes 的全局顺序
example 4:
示例 4:
|--Wx0--| |--Wx1--|
|--Wx0--| |--Wx1--|。
|--Wx2--|
|--Wx2--|。
C1: |-Rx2-| |-Rx1-|
C1: |-Rx2-| |-Rx1-|。
C2: |-Rx1-| |-Rx2-|
C2: |-Rx1-| |-Rx2-|。
can there be a serial order?
是否存在一个 serial order?
C1 needs Wx2 Rx2 Wx1 Rx1
C1 需要 Wx2 Rx2 Wx1 Rx1。
C2 needs Wx1 Rx1 Wx2 Rx2
C2 需要 Wx1 Rx1 Wx2 Rx2。
we can't have both Wx2 before Wx1, and Wx2 after Wx1.
我们不可能同时满足 Wx2 在 Wx1 之前,以及 Wx2 在 Wx1 之后。
so not linearizable.
所以它不是 linearizable 的。
so:
所以:
service can choose either order for concurrent writes
service 可以为 concurrent writes 选择任意一个顺序。
but all clients must see the writes in the same order
但所有 clients 都必须以相同顺序看到这些 writes。
this is important when there are replicas or caches
当存在 replicas 或 caches 时,这一点很重要。
they must all appear to execute operations in the same order
它们看起来必须都以相同顺序执行 operations。
Stale reads 与 retransmission
example 5:
示例 5:
|-Wx1-|
|-Wx1-|。
|-Wx2-|
|-Wx2-|。
|-Rx1-|
|-Rx1-|。
no order is possible -- not linearizable
不存在可行的 order——不是 linearizable 的。
so:
所以:
linearizability rules out "stale" reads
linearizability 排除了“stale” reads。
even if the reader doesn't know there was a write
即使 reader 不知道曾经发生过 write,
the time rule requires reads to see the latest completed update
time rule 仍要求 reads 看到最近完成的 update。
"no stale data" restricts caching and replication designs
“no stale data” 会限制 caching 和 replication designs。
linearizability outlaws many design possibilities / anomalies:
linearizability 禁止许多 design possibilities / anomalies:
split brain (two active leaders)
split brain(两个 active leaders)。
forgetting completed writes after a crash+reboot
在 crash+reboot 后忘记已经完成的 writes。
reading from lagging replicas or out-of-date caches
从 lagging replicas 或 out-of-date caches 读取。
example 6:
示例 6:
[client / network / server diagram]
[client / network / server diagram]。
C1 sends put(x, 1)
C1 发送 put(x, 1)。
C2 sends put(x, 2)
C2 发送 put(x, 2)。
service receives C1's request;
service 收到 C1 的 request;
network drops response;
network 丢弃 response;
C1's RPC library re-sends request
C1 的 RPC library 重新发送 request。
is it legal for service to execute both of C1's request messages?
service 执行 C1 的两条 request messages 是否合法?
we then might see this if C3 reads three times:
如果 C3 读取三次,那么可能看到:
C1: |--------Wx1---------| (due to retransmission)
C1: |--------Wx1---------| (due to retransmission)。
C2: |-Wx2-|
C2: |-Wx2-|。
C3: |-Rx1-| |-Rx2-| |-Rx1-|
C3: |-Rx1-| |-Rx2-| |-Rx1-|。
this history is not linearizable!
这个 history 不是 linearizable 的!
so, if we want linearizability:
因此,如果我们希望满足 linearizability:
repeated requests from retransmissions should only execute once!
来自 retransmissions 的 repeated requests 应该只执行一次!
the Raft paper mentions this issue (and a solution) in Section 8
Raft 论文在 Section 8 中提到了这个问题(以及一种解决方案)。
Linearizable operations 与程序员视角
linearizable systems are not limited to just read and write operations
linearizable systems 不局限于 read 和 write operations。
increment
increment。
append
append。
test-and-set (to implement locks)
test-and-set(用于实现 locks)。
any self-contained single-object operation
任何 self-contained single-object operation。
application programmers like linearizability:
application programmers 喜欢 linearizability:
- reads see latest data -- never stale
- reads 看到 latest data——永远不会 stale。
- all clients see the same data (when there aren't writes)
- 所有 clients 看到相同 data(不存在 writes 时)。
- all clients see data changes in the same order
- 所有 clients 以相同顺序看到 data changes。
so my put(v,27); put(done,true); example works
因此我的 put(v,27); put(done,true); example 能够正常工作。
these benefits will be clearer when we look at weaker consistencies.
当我们研究 weaker consistencies 时,这些 benefits 会更加清晰。
can we have better semantics than linearizability?
我们能否拥有比 linearizability 更好的 semantics?
or, what might you want that linearizability won't support?
或者,哪些需求是 linearizability 不支持、但你可能想要的?
- transactions: atomic groups of operations on different objects
- transactions:作用于不同 objects 的 atomic operation groups。
linearizability only thinks about individual operations, not groups of ops
linearizability 只考虑 individual operations,不考虑 operation groups。
- operations that themselves invoke other services
- 自身会调用其他 services 的 operations。
如何实现 Linearizability
how can we implement linearizability?
如何实现 linearizability?
depends on how much replication, caching, and fault-tolerance we want.
这取决于我们需要多少 replication、caching 和 fault-tolerance。
single serial server that doesn't crash.
一个不会 crash 的 single serial server。
[diagram: clients, server, op queue, state]
[diagram:clients、server、op queue、state]。
server picks an order for concurrently arriving client requests.
server 为 concurrent 到达的 client requests 选择一个 order。
executes them in that order, one at a time,
按照该 order 一次执行一个,
replies to each before starting the next.
在开始下一个之前先对每个 request 回复。
plus duplicate request suppression
另外还需要 duplicate request suppression。
this simple implementation directly implements linearizability definition
这个简单实现直接实现了 linearizability definition。
executes in serial order, one at a time
它按 serial order 一次执行一个 operation。
executes an operation after it is received
它在收到 operation 后执行,
and doesn't reply until after operation is finished
并且直到 operation 完成后才 reply。
(thus can't eagerly reply to put()s)
(因此不能 eager 地 reply put()s。)
good news: server does not have to reason about histories,
好消息是:server 不需要推理 histories、
linearization points, or concurrency.
linearization points 或 concurrency。
what about fault-tolerant linearizability?
那么 fault-tolerant linearizability 呢?
primary-backup replication
primary-backup replication。
like GFS but would need modifications e.g. read only via primary
类似 GFS,但需要修改,例如 read 只能通过 primary。
Raft!
Raft!
and we'll see more examples
我们还会看到更多 examples。
Linearizability 的性能代价
what about the performance of linearizable systems?
linearizable systems 的 performance 如何?
a fundamental performance limit imposed by no-stale-reads rule:
no-stale-reads rule 带来了一个 fundamental performance limit:
[W, E]
[W, E]。
a write on the west coast, which completes
west coast 上的一次 write 完成,
then a read on the east coast
然后 east coast 上发生一次 read。
there must be communication of the written value
写入的 value 必须被传递过去,
*and* either reader or writer must wait for communication
并且 reader 或 writer 中至少有一方必须等待 communication。
speed of light is a serious problem:
speed of light 是一个严重问题:
dozens of milliseconds cross-country
跨越整个国家需要几十 milliseconds。
can limit serial throughput to a few tens per second
这可能把 serial throughput 限制在每秒几十次。
generally:
一般来说:
bad news: serial aspect makes it hard to get parallel speedup for individ objs
坏消息:serial aspect 让 individual objects 很难获得 parallel speedup。
bad news: if replication, then lots of communication and waiting
坏消息:如果存在 replication,就会有大量 communication 和 waiting。
bad news: if replication, replicas must be reachable,
坏消息:如果存在 replication,replicas 必须 reachable,
limiting fault tolerance
这会限制 fault tolerance。
good news: you can shard by key
好消息:可以按 key 做 shard。
Eventual consistency
what about other consistency models?
其他 consistency models 呢?
can they allow better performance?
它们能否带来更好的 performance?
do they have intuitive semantics?
它们是否拥有直观的 semantics?
example: eventual consistency -- a weak model
例子:eventual consistency——一种 weak model。
[diagram: two copies, clients]
[diagram:two copies、clients]。
multiple copies of the data (e.g. in different datacenters, for speed)
数据有多个 copies(例如位于不同 datacenters,以提高速度)。
a read consults any replica (e.g. closest)
一次 read 查询任意 replica(例如距离最近的 replica)。
a write updates any replica (e.g. closest)
一次 write 更新任意 replica(例如距离最近的 replica)。
replica sends response when that one update is done
该 replica 在这一次 update 完成后发送 response。
replicas synchronize updates in the background
replicas 在后台 synchronize updates。
eventually, other replicas will see my update
最终,其他 replicas 会看到我的 update。
many systems provide eventual consistency
许多 systems 提供 eventual consistency。
faster than linearizability
它比 linearizability 更快,
especially if replicas are in different cities for fault-tolerance
尤其当 replicas 为了 fault-tolerance 分布在不同城市时。
and more available -- any one replica will do
并且 availability 更高——任意一个 replica 都可以工作。
no waiting for primary/backup communication or Raft quorum
不需要等待 primary/backup communication 或 Raft quorum。
Amazon's Dynamo; Cassandra; GFS (sort of)
Amazon 的 Dynamo、Cassandra、GFS(某种程度上)。
but eventual consistency exposes some anomalies to application programmer:
但 eventual consistency 会向 application programmer 暴露一些 anomalies:
- reads can see stale data
- reads 可能看到 stale data。
a problem for password change, ACL change
这会给 password change、ACL change 带来问题。
- writes may appear out of order
- writes 可能以 out-of-order 的形式出现。
breaks my result/done example
这会破坏前面的 result/done example。
- different clients may see different data
- 不同 clients 可能看到不同 data。
- concurrent writes to same item need to be resolved somehow!
- 对同一个 item 的 concurrent writes 必须以某种方式解决!
C1: put(x, 1)
C1: put(x, 1)。
C2: put(x, 2)
C2: put(x, 2)。
may initially be applied at different replicas
它们最初可能被应用到不同 replicas。
only later will they be pushed to other replicas
只有之后它们才会被推送到其他 replicas。
how to merge concurrent new values?
如何 merge concurrent new values?
how to ensure all replicas choose the same final value?
如何确保所有 replicas 选择相同的 final value?
so that, eventually, they are identical?
从而最终让它们相同?
- eventual consistency cannot support e.g. test-and-set
- eventual consistency 无法支持例如
test-and-set这样的 operation。
A general pattern: you can usually choose only one of these:
一个 general pattern 是:通常只能在下面两者中选择一个:
Strong consistency
Strong consistency。
Maximum availability
Maximum availability。
But not both.
但不能两者兼得。
Strong consistency makes you wait to update replicas,
Strong consistency 要求你等待 replicas 完成 update,
and can't proceed if too many replicas are unavailable.
如果太多 replicas unavailable,就无法继续。
Thus poor availability.
因此 availability 较差。
Eventual consistency can proceed even if no other replicas are reachable.
Eventual consistency 即使其他 replicas 都 unreachable,也可以继续运行。
But has poor consistency.
但 consistency 较差。
Next week:
下周:
ZooKeeper, an interesting service built on a Raft-like protocol
ZooKeeper,一个建立在 Raft-like protocol 之上的有趣 service,
combines strong and weak consistency
结合 strong consistency 和 weak consistency。
https://jepsen.io/consistency/models
https://jepsen.io/consistency/models
机制小结
1. Linearizability 是什么
Linearizability 不要求 service 内部真的在某个瞬间完成 operation;它要求每个 operation 都能被解释为在其 start 和 finish 之间某个 point 生效,并且所有 client-visible results 等价于按照这些 points 串行执行。这个定义同时约束了时间顺序和 value 结果。
2. 它排除了什么
一旦某次 read 已经观察到某个 write,后续严格发生的 reads 不能重新看到旧值;所有 clients 也必须以同一顺序观察 concurrent writes。因此 split brain、lagging replica、过期 cache、crash 后遗忘已完成 write 都是不允许的。RPC retransmission 还要求服务端做 duplicate request suppression,否则同一 request 执行两次可能破坏 linearizability。
3. 强一致性的代价
Linearizability 要求在不同地点之间传播最新写入,因此受 network latency 和 speed of light 限制;replication 还需要通信并等待 replicas。按 key 分片可以提供并行性,但单个 object 的 serial 约束仍然存在。
4. Eventual consistency 的取舍
Eventual consistency 允许 client 从任意 replica 读写,并在后台传播更新,因此通常拥有更高性能和 availability;代价是 stale reads、不同 client 看到不同数据、writes 顺序不一致,以及 concurrent writes 的冲突合并问题。选择哪种 consistency model,本质上是 performance、simplicity、fault tolerance 和 semantics 之间的 tradeoff。
本篇验收
- [x] 官方
l-linearizability.txt已固定:346 行、301 个非空源行,SHA-256 与来源记录一致。 - [x] 源文本的非空行按原顺序逐行保留,中文译文紧随对应英文源行。
- [x] History 1–6 的时序线、
Wx/Rx标记、客户端顺序和 retransmission 示例均保留。 - [x]
[simple client/server diagrams]、[client / network / server diagram]、[diagram: ...]和[W, E]原位置保留;源文件没有独立图片。 - [x]
put/get、GFS、Raft、primary-backup、linearization point、consistency model 和 URL 保留原样。 - [ ] Lecture 8 的中文译文仍建议进行一次人工术语审校;自动审计只验证源文覆盖与顺序,不证明翻译语义正确。
评论 (0)