共识算法 Raft 是如何选出主节点(leader)的?
How does the Raft consensus algorithm elect a leader?
Raft 中节点在“跟随者、候选者、领导者”三态间切换。跟随者超过选举超时未收到心跳就变成候选者,投自己一票并向他人拉票;拿到多数票的成为 leader,并定期发心跳维持权威。随机化的超时时间降低了平票重试的冲突。
In Raft nodes cycle follower/candidate/leader. A follower that times out without a heartbeat becomes a candidate, votes for itself and asks peers for votes; the one with a majority becomes leader and sends heartbeats. Randomized timeouts avoid tied re-votes.
难度 专业 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#Raft #共识
两阶段提交(2PC)的阻塞问题指什么?
What is the blocking problem in two-phase commit (2PC)?
2PC 由协调者先让各参与者“准备”,再发“提交”。若协调者在发出提交前崩溃,参与者已锁定资源却不知道该提交还是回滚,只能一直等待,造成资源阻塞。它用强一致换来了可用性脆弱。
2PC has a coordinator ask participants to 'prepare', then 'commit'. If the coordinator crashes before committing, participants hold locked resources with no decision and must wait—blocking. It trades availability for strong consistency.
难度 专业 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#2PC #事务
分布式存储宣称的线性一致性到底向客户端承诺了什么?
What does linearizability actually promise to clients of a distributed system?
线性一致性要求每个操作看起来都在其调用与返回之间的某一瞬间原子地生效,且所有客户端看到同一个实时顺序:一旦某次写操作完成,之后发起的任何读都必须返回这次写入的值或更新的值。这等于把整个分布式服务对外呈现为一份数据的单一副本。最终一致性弱得多:只承诺停止更新后副本终将收敛,收敛之前允许读到旧数据。
Linearizability requires every operation to take effect atomically at some instant between its invocation and its response, with all clients observing the same real-time order: once a write completes, any read issued afterwards must return that written value or a newer one. The whole service thereby behaves externally as a single copy of the data. Eventual consistency promises far less - merely that replicas converge once updates stop, while stale reads remain possible until then.
难度 专业 · 适合 高中(15-18)
CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source
M. Herlihy 与 J. Wing《Linearizability: A Correctness Condition for Concurrent Objects》,ACM Transactions on Programming Languages and Systems 第12卷第3期,1990,DOI: 10.1145/78969.78972
M. Herlihy & J. Wing, 'Linearizability: A Correctness Condition for Concurrent Objects', ACM TOPLAS 12(3), 1990, DOI: 10.1145/78969.78972
独立核验依据 · Independent verification: 核验依据 1 CROSSREF 标识 10.1145/78969.78972:Linearizability: a corre
#分布式系统 #一致性模型 #线性一致性
Raft 一致性算法为什么需要任期号和随机化的选举超时?投票前的“日志至少一样新”检查保证了什么?
Why does the Raft consensus algorithm need term numbers and randomized election timeouts? What does the "log at least as up-to-date" check before granting a vote guarantee?
Raft 把时间切成单调递增的任期,每个任期最多选出一位领导者。收不到心跳的跟随者会自增任期并发起拉票;随机化超时让各节点参选时刻错开,避免选票长期瓜分陷入活锁。候选人须附上自己最后一条日志的任期与索引,投票者仅当对方日志不旧于自己时才投——这确保已提交的日志不会被缺失它的新领导者覆盖,是安全性的基石。
Raft splits time into monotonically increasing terms, and each term elects at most one leader. A follower that stops hearing heartbeats increments its term and campaigns; randomizing the election timeout staggers candidacies so votes are rarely split forever. Candidates attach their last log entry's term and index, and voters grant a vote only if that log is at least as up-to-date as their own. This prevents committed entries from ever being overwritten by a new leader missing them — the cornerstone of Raft's safety.
难度 专业 · 适合 高中(15-18)
CC BY 4.0 · 来源待核验 · Source pending review
来源 · Source
出处备注:著录含书名,但缺版次 / 出版社 / 年份中的一部分,需编辑补全后才能做独立比对。
Ongaro、Ousterhout,《寻找一种易于理解的一致性算法》,USENIX ATC 2014
Ongaro & Ousterhout, In Search of an Understandable Consensus Algorithm, USENIX ATC 2014
#共识算法 #领导者选举 #日志复制
CAP 定理说一致性、可用性、分区容错三者为何不能同时满足?
Why can't consistency, availability and partition tolerance all hold per CAP?
网络分区(P)在分布式系统中不可避免;一旦发生分区,你要么拒绝部分请求以保一致性(C),要么继续响应但可能返回旧数据以保可用性(A)。因此实际系统只能在 P 前提下二选一,而不是三者兼得。
Network partitions (P) are unavoidable in distributed systems; when one happens you must either reject some requests to keep consistency (C) or keep responding with possibly stale data for availability (A). So under P you pick C or A, not both.
难度 专业 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#CAP #分布式
一致性哈希(consistent hashing)怎么减少节点增减时的数据迁移?
How does consistent hashing reduce data movement when nodes join or leave?
它把节点和数据都映射到一个首尾相接的哈希环上,每个数据只交给环上顺时针最近的节点。新增或移除一个节点时,只有它相邻区间的数据需要迁移,而不是全部重新分配,从而把动荡降到最低。
It maps both nodes and data onto a circular hash ring, each item going to the nearest node clockwise. Adding or removing one node only moves the data in its neighboring arc, not everything, minimizing churn.
难度 进阶 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#一致性哈希 #分布式
某 Dynamo 风格键值存储将每份数据复制到 3 个节点,写操作需得到其中 2 个节点(W=2)确认,读操作需访问其中 2 个节点(R=2)。请解释为什么任何一次成功读取都能读到最新写入的数据。
A Dynamo-style key-value store replicates every piece of data onto 3 nodes; a write needs confirmation from 2 nodes (W=2) and a read consults 2 nodes (R=2). Explain why every successful read returns the most recently written data.
关键在于读集合与写集合必然相交:两个节点的子集取自同一个三节点集合,由抽屉原理至少共享一个节点。写入成功后,交集节点已持有最新版本号,读取时比较版本号即可选出最新数据,因此无需分布式事务便能得到一致的读写效果。该机制还可调节 R 与 W 的取值,在读写延迟与一致性之间做工程权衡。
The crux is that the read set and the write set must intersect: any two-element subsets drawn from the same three-node collection share at least one node by the pigeonhole principle. After a successful write, that intersecting node already holds the newest version number, and readers compare versions to pick the latest value, so consistent reads need no distributed transactions. The scheme also lets engineers tune R and W to trade off read latency, write latency, and consistency.
难度 进阶 · 适合 初中(12-15)
CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source
G. DeCandia 等人论文 Dynamo:亚马逊的高可用键值存储,发表于 SOSP 2007,DOI: 10.1145/1294261.1294281
G. DeCandia et al., Dynamo: Amazon's Highly Available Key-value Store, Proc. SOSP 2007, DOI: 10.1145/1294261.1294281
独立核验依据 · Independent verification: 核验依据 1 CROSSREF 标识 10.1145/1294261.1294281:Dynamo(2007,按著录自报 DO
#分布式系统 #仲裁机制 #一致性
什么是“最终一致性”?
What is 'eventual consistency'?
最终一致性是说:如果暂时不再写入,过一段时间后所有副本会自动变成相同的数据。它允许系统先快速响应、各副本暂时不一致,适合对实时一致要求不高的场景,比如社交动态的时间线。
Eventual consistency means that if writes stop, all replicas will become identical after some time. The system can respond fast with temporarily differing copies—fine for feeds where instant agreement isn't critical.
难度 入门 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#一致性 #分布式
为什么把任务分给很多台电脑(分布式)反而比一台更难?
Why is splitting work across many computers harder than using one?
因为多台机器会各自出错、网络会延迟或断开,而且它们对“现在发生了什么”看法可能不一致。要让它们像一台机器那样可靠协作,就得额外处理同步、容错和冲突,所以更难。
Machines fail independently, networks lag or drop, and they may disagree on 'what happened'. Making them cooperate reliably like one machine means handling sync, faults and conflicts—so it's harder.
难度 入门 · 适合 大众
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#分布式 #容错
什么是幂等性,为什么在分布式系统里很重要?
What is idempotency and why does it matter in distributed systems?
幂等指同一操作执行一次或多次结果相同;网络重试和重复消息很常见,接口设计成幂等可避免重复扣款、重复下单等错误,常用去重键或状态机实现。
Idempotency means repeating an operation yields the same result; since retries and duplicates are common in networks, idempotent APIs prevent double-charging or double-ordering, often via dedup keys or state machines.
难度 入门 · 适合 幼儿(3-6)
CC BY 4.0 · 已核验 · Verified 2026-08-23 · 2 条独立证据
来源 · Source
Tanenbaum & Bos,《Modern Operating Systems》第4版,Pearson,2014
A. S. Tanenbaum and H. Bos, Modern Operating Systems, 4th ed., Pearson, 2014
独立核验依据 · Independent verification: 核验依据 2 OPENLIBRARY 标识 /works/OL1970688W:Modern Operating System
#分布式 #可靠性