Lecture 19 · Replication and one-copy semantics: quorums and voting

Distributed Systems · Lecture 19。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: CMU 15-440/640 Spring 2026, learning outcomes “achieving high availability: replication and one-copy semantics”, “taxonomy of replication strategies” and “voting”; the readings Gifford, Weighted Voting for Replicated Data, and Herlihy, A Quorum-Consensus Replication Method for Abstract Data Types. Problem sets / projects: none targets this lecture directly; PS4’s DHT question uses replication only in passing. Sources:

  • D. K. Gifford, Weighted Voting for Replicated Data (SOSP 1979) — reading;
  • M. Herlihy, A Quorum-Consensus Replication Method for Abstract Data Types (ACM TOCS 1986) — reading;
  • R. H. Thomas, A Majority Consensus Approach to Concurrency Control for Multiple Copy Databases (ACM TODS 1979);
  • H. Attiya, A. Bar-Noy and D. Dolev, Sharing Memory Robustly in Message-Passing Systems (JACM 1995) — the ABD register;
  • S. Y. Cheung, M. H. Ammar and M. Ahamad, The Grid Protocol (1990);
  • P. A. Bernstein, V. Hadzilacos and N. Goodman, Concurrency Control and Recovery in Database Systems (1987), ch. 8;
  • M. Herlihy and J. Wing, Linearizability (ACM TOPLAS 1990);
  • G. DeCandia et al., Dynamo (SOSP 2007).

The slides are not public; this is not a transcript. Every number not attributed to a paper comes from code/lecture19/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). All demos are exact or seeded and deterministic. Code: code/lecture19/. Reading time: ~90 minutes, plus ~10 to run the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Say what replication buys (availability, performance, durability), what it costs, and what one-copy semantics requires.
  2. Place a replication scheme in the taxonomy: pessimistic vs optimistic, primary-backup vs quorum, client-server vs peer-to-peer.
  3. Explain primary-backup, its failover, and why choosing the primary after a partition needs a majority (split brain, leases).
  4. Compute the availability of read-one/write-all and of quorum configurations, and know when replication makes things worse.
  5. Apply Gifford’s weighted voting: votes, r + w > N, version numbers, current write quorums, weak representatives.
  6. Explain the extra steps a quorum store needs to look like one copy: unique timestamps for concurrent writers, and read repair for linearizable reads.
  7. Derive quorum constraints for an abstract data type from its semantics, as Herlihy does for a queue.

0.2 Prerequisites and scope

  • Prerequisites:
    • Lecture 13: availability, MTTF/MTTR, correlated failures;
    • Lecture 17: serializability and locks;
    • Lecture 18: why deciding “who is in charge” under partitions is hard;
    • Lecture 1’s dsim simulator.
  • Scope: replicas of one data item, or one object, that must behave like a single copy. Replicated logs and consensus (Paxos) are Lectures 20–21. Optimistic replication with conflict resolution (Coda) is Lecture 22.

0.3 Section → code map

SectionIdeaDemo in code/lecture19/
§1why replicate; ROWA01_why_replicate.py
§2primary-backup, split brain, leases02_primary_backup.py
§3weighted voting03_weighted_voting.py
§4a quorum store: partitions, staleness, concurrent writers04_quorum_store.py, qstore.py
§5linearizable reads: read repair05_linearizable_reads.py
§6the design space: when replication helps, grids, correlation06_quorum_availability.py, quorum.py
§7quorums for abstract data types07_quorum_adt.py

0.4 Notation

  • N copies, called replicas, Gifford’s representatives or Herlihy’s repositories. Copy i holds v_i votes; V = Σ v_i.
  • A read quorum is any set of copies holding at least r votes; a write quorum holds at least w. With one vote per copy, r and w count copies.
  • p is the probability that a copy is up. Unless stated otherwise, copies fail independently.
  • “Unavailable” means the fraction of time (or the probability) that an operation cannot gather its quorum.

1. Why replicate, and what “one copy” means

1.1 Three reasons, one price

  • Availability. If one copy is down 1% of the time, as in demo 01 (MTTF 990 h, MTTR 10 h), a single-copy service is down 3.7 days a year. Several copies can mask that.
  • Performance. Copies close to their users cut latency, and several copies share the read load. Gifford’s paper opens with both arguments: locate information close to its point of use, and serve many requests in parallel.
  • Durability. Data survives the loss of a machine.

The price is consistency. Each copy is updated separately, so at any moment copies may disagree. The goal of the pessimistic schemes in this lecture is one-copy semantics: clients cannot tell that there is more than one copy, except that the data is more available.

  • For transactions, the standard is one-copy serializability: every execution is equivalent to a serial execution on a single copy (Bernstein et al.).
  • For single operations on one object, it is linearizability (Herlihy and Wing). Every operation appears to take effect at one instant between its start and its end, and the instants respect real time.

1.2 A taxonomy

dimensionone endother end
when copies may divergepessimistic: never visibly; operations block or fail instead (this lecture)optimistic: always allowed; conflicts are detected and resolved later (Coda, Lecture 22)
who orders updatesprimary-backup: one distinguished copy decides (§2)quorum / voting: any copies that form a quorum (§3–§7)
who replicatesclient-server: replicas are servers; clients do not hold authoritative copiespeer-to-peer: every node holds copies and may serve them

Gifford notes that weighted voting spans the second row. All votes on one copy is a primary-site scheme; equal votes everywhere is fully decentralized.

1.3 Read-one / write-all (demo 01)

The obvious pessimistic scheme is ROWA: read any copy, write every copy. With copies up 99% of the time:

copiesROWA read unavailableROWA write unavailablemajority (reads and writes)
11.0e-2 (3.7 days/yr)1.0e-21.0e-2
31.0e-63.0e-2 (10.8 days/yr)3.0e-4 (2.6 h/yr)
51.0e-104.9e-2 (17.9 days/yr)9.9e-6 (5.2 min/yr)
71.0e-146.8e-23.4e-7

ROWA makes reads almost never unavailable, but writes less available than with a single copy: with five copies, 4.9 times worse. A majority makes both kinds of operation about a thousand times better than one copy at five copies. The rest of the lecture is about the space between these two schemes.

A simulation of five copies failing and being repaired for 20 million hours matched the formulas (majority: 1.02e-5 simulated, 9.85e-6 exact).

“Read-one / write-all-available” is not a fix. Writing to every copy that is currently reachable keeps writes available. But under a partition each side writes “all available copies” on its side, and the copies diverge. Section 4 shows the same failure in a quorum store with r + w ≤ N.

1.4 The independence assumption

All these formulas assume copies fail independently. Demo 01 Part C put copies 1–3 of a majority-of-5 group in one rack that fails for about 4 hours every 5,000 hours:

  • Shared racks: majority unavailability rose from 9.9e-6 to 8.3e-4, 85 times worse. When rack A is down, the majority is gone.
  • One rack per copy: 1.2e-5.
  • One repair crew instead of unlimited repair: 6.0e-5.

Correlated failures (Lecture 13 §3) can turn the arithmetic of replication into wishful thinking.


2. Primary-backup

2.1 The scheme

One copy, the primary, receives all writes. It applies each one, forwards it to the backups, waits for their acknowledgements (synchronous replication), and then acknowledges the client. Reads go to the primary. If the primary fails, a backup takes over (failover).

Its appeal is simplicity: the primary orders all writes, so there is no ordering problem. Its difficulty is deciding who is the primary, which turns out to be the whole problem.

2.2 Crash failover works (demo 02 Part A)

Three replicas; two clients write a unique value every 10 ms. Heartbeats go out every 10 ms; a backup suspects the primary after 50 ms of silence. When R1 crashes at 200 ms, R2 takes over at 250 ms.

  • No acknowledged write was lost. Replication was synchronous, so R2 had every write R1 had acknowledged.
  • Writes stopped for 70–88 ms: the suspicion timeout plus either a vote round or a write timeout.

Two details mattered:

  • Stagger the backups. Our first version let both backups promote themselves at the same moment.
  • Keep replication ordered. Part C turned off FIFO delivery: a backup received entry k+1 before entry k, its “truncate the log at the incoming index” rule dropped an entry, and after failover one acknowledged write was gone. Primary-backup needs ordered, gap-free replication: sequence numbers, or TCP.

2.3 Partitions make two primaries (demo 02 Part B)

Split the network into {R1, C1} | {R2, R3, C2} for 300 ms:

  • Naive failover. R2 misses heartbeats and promotes itself, while R1, which still thinks it is primary, drops the backups it cannot reach and carries on. For 22 of the 30 ten-millisecond slots, both sides acknowledged writes. When the partition healed, R1 saw a higher view and stepped down, and 27 writes that clients had been told were safe disappeared. This is split brain.
  • Majority leases. A primary may serve only while a majority (itself included) has recently acknowledged its heartbeats: its lease. A backup may take over only with votes from a majority, given only by replicas that have not heard the old primary for a full lease period. R1 stopped serving when its lease ran out, and R2 was elected on the majority side. The result: 0 slots with two primaries and 0 writes lost. C1’s writes failed instead.

The lesson recurs throughout the course. Choosing a single leader safely in a partitionable network requires a majority, and a lease is a way to make “the old leader has stopped” a matter of time rather than of hope. Real systems built this way include GFS chunk leases (with the master), primary-backup with a coordination service (ZooKeeper, Chubby), and Raft/Paxos leaders (Lectures 20–21).


3. Weighted voting (Gifford 1979)

3.1 The algorithm

Gifford’s algorithm has four parts:

  1. Votes. Each copy of a file has some number of votes. A read must gather copies holding at least r votes, a write at least w votes, with r + w > V. So every read quorum shares at least one copy with every write quorum.
  2. Version numbers tell which copies in a quorum are current. A read takes the data from a current copy, ideally the fastest one in its quorum.
  3. Writes go to current copies only. A write is sent to a write quorum made only of current copies, which get a new version number. If not enough current copies are reachable, the collector first copies the current contents onto obsolete copies in the background.
  4. Transactions supply isolation. Gifford runs all of this on top of a transactional file system: locks for serial consistency, 2PC for atomic multi-copy writes. Voting handles replication; the transaction layer handles concurrency.

The read quorum works because “there is always a write quorum of current copies”, so any read quorum includes one. That is the r + w > V rule seen from the read’s side.

3.2 The knobs (demo 03)

Gifford’s three examples, with each copy unavailable 1% of the time:

votesrwread latency, blockingwrite latency, blocking
Example 1⟨1, 0, 0⟩1165 ms, 1.0e-275 ms, 1.0e-2
Example 2⟨2, 1, 1⟩2375 ms, 2.0e-4100 ms, 1.0e-2
Example 3⟨1, 1, 1⟩1375 ms, 1.0e-6750 ms, 3.0e-2

quorum.py reproduces every number in Gifford’s table.

  • Example 1: one server holds the only vote; two users keep weak representatives (zero-vote copies) on their local disks, read from them at 65 ms, and still need the server for both reads and writes.
  • Example 2: a local server with 2 votes and two remote servers with 1 each. Reads need only the local server; writes need it plus one remote copy. The file stays readable, read-only, if the local server fails.
  • Example 3: a system directory, read often and written rarely. Read anywhere, write everywhere.

r and w trade against each other. With five equal copies at 99% (demo 03 Part B):

rwread unavailablewrite unavailable
339.9e-69.9e-6
245.0e-89.8e-4
151.0e-104.9e-2

Weights let reliable copies count for more, but not monotonically. One copy is up 99.9% and four are up 95% (Part C); quorums are a majority of the votes.

  • With 1 vote (equal votes) for the reliable copy: unavailable 4.95e-4.
  • With 2 votes: 6.66e-4, which is worse. The total becomes 6, and a majority of 6 is 4.
  • With 3 votes: 1.92e-4, the best.
  • With all the weight on it, primary-site replication: 1.0e-3, its own unavailability.

Weak representatives have zero votes. They cannot change any quorum, so they can be added or dropped at any time and need not be stored durably. Yet they can serve reads when current: Part D’s read latency fell from 75 to 65 ms. Gifford uses them for temporary copies on users’ machines, a form of caching.

3.3 Why “w > V/2”?

The rule usually quoted with Gifford’s scheme is r + w > V and w > V/2. The second half makes any two write quorums intersect. In Gifford’s design that matters because writes are synchronized by locks: two concurrent writers conflict only if their write quorums share a copy on which both need a write lock. Version numbers must also increase without gaps: two writes that both pick version 7 on disjoint quorums would leave two different “version 7”s.

Section 4.3 shows the second problem directly, and a second cure: make version numbers unique.


4. A quorum store under partitions, distance and concurrency (demo 04)

qstore.py implements a register replicated on five replicas, with no transactions:

  • A write reads r replicas for the current timestamp, then sends (timestamp + 1, value) to everybody and waits for w acknowledgements.
  • A read asks everybody and takes the newest of the first r replies.

4.1 Partitions

Two replicas and client C1 were split from the other three and C2:

r, wminority side: writes / reads okmajority side: writes / reads ok
3, 30/10, 0/1010/10, 10/10
2, 40/10, 10/100/10, 10/10
1, 5 (ROWA)0/10, 10/100/10, 10/10
4, 20/10, 0/100/10, 0/10
2, 210/10, 10/1010/10, 10/10
  • Majorities keep exactly one side working.
  • ROWA and (2, 4) keep reads everywhere and lose writes everywhere.
  • (4, 2) loses writes too, because a write must first read 4 replicas to learn the version.
  • (2, 2) keeps everything working on both sides. That is two independent copies, split brain again, which is what r + w ≤ N buys.

4.2 Distance: stale reads

Clients usually sit near some replicas and far from others, so the nearest answers come first. Each client was put 1–2 ms from two replicas and 15–25 ms from the rest, with 300 random workloads per configuration:

r, wr + w > N?stale readshistories not linearizable
1, 1no608265
2, 2no394233
2, 3no (= N)020
1, 5yes07
2, 4yes016
3, 3yes00
3, 3 + read repairyes00

A stale read returns a value that was overwritten before the read began. With r + w ≤ N they are common. With r + w > N they never happened: every read quorum met the latest write. (For (2, 3), where r + w equals N exactly, the conservative stale check missed the violations, but the linearizability check caught them.)

With all links equally fast (1–6 ms), the first version of this experiment found no stale reads even for r = w = 2. Writes reached every replica before anyone looked. Anomalies of weak quorums hide in benchmarks with uniform latency and appear across distance, which is one reason geo-distributed stores make consistency an explicit choice.

4.3 Concurrent writers need unique timestamps

70% writes, so writers often overlap:

timestampr, wruns ending with replicas disagreeingnot linearizable
counter only3, 3107 / 30014
counter only4, 2213 / 30019
(counter, writer id)3, 300
(counter, writer id)4, 200

With a bare counter, two concurrent writers both read version 7 and both write version 8 with different values. Each replica keeps whichever arrived first and rejects the other as “not newer”. The replicas then hold different values under the same version, and they never converge.

Adding the writer’s id to the timestamp makes every pair of writes ordered. With it, even w = 2 of 5 was correct. Each write first reads a quorum that meets every earlier write, so it picks a larger counter, and ties are broken by id. This is Herlihy’s observation, made formal for files: with logical timestamps, write quorums need not intersect each other (the Thomas write rule). Gifford’s w > V/2 is the price of ordering writes with locks and plain version numbers instead.


5. Fresh is not enough: linearizable reads (demo 05)

5.1 New, then old

r + w > N guarantees that a read sees every write that completed before it began. It does not stop the following:

  • a write is still in progress and has reached one replica;
  • read A’s quorum includes that replica, so A returns the new value;
  • read B starts after A finished, but its quorum misses that replica, so B returns the old value.

No single copy behaves like that: once someone has seen the new value, everyone later must too.

Demo 05 Part A builds it on purpose. Writer C1 is near R1 only, so its write spends 40 ms reading timestamps, sends the new value at 140 ms, and completes at 180 ms. C2 (near R1–R3) reads at 142 ms and gets new. C3 (near R2, R4, R5) reads at 150 ms, after C2 has finished, and gets old. The history is not linearizable.

5.2 Read repair

Attiya, Bar-Noy and Dolev’s fix: before returning a value, a reader writes it back to a write quorum. Then any later read’s quorum meets a copy that has it. With read repair, C2 wrote “new” back to R1–R3 before returning, and C3, reading R2, got “new”: linearizable.

The result is an atomic register built from message passing and majorities alone: no transactions, no locks, no leader.

In random workloads the window is narrow but real:

r, wwithout read repairwith
3, 32 / 400 histories not linearizable0
1, 5260
2, 4100

The price is a second round trip on reads: mean latency 3.3 → 6.7 ms, 10 → 20 messages per read. Real systems skip the write-back when all replies already agree.


6. The design space (demo 06)

6.1 Replication only helps if copies are mostly up

Majority of 5 against one copy, as each copy’s availability p varies:

pone copymajority of 3majority of 5write-all of 5
0.30.700.780.841.00
0.50.500.500.500.97
0.70.300.220.160.83
0.90.100.0280.00860.41
0.990.013.0e-49.9e-60.049

Below p = 0.5, a majority quorum is less available than one copy: you need several flaky machines at once. Quorums amplify reliability; they do not create it.

6.2 Load: grids

With majorities, every operation contacts more than half the copies, so each copy serves over half of all operations. Adding copies does not spread the load.

Grid quorums (Cheung, Ammar and Ahamad) arrange k × k copies in a grid. A read takes one copy from every column; a write takes a whole column plus one copy from every column. Every read meets every write, and every write meets every write. Results for 16 copies:

read sizewrite sizeread unavailablewrite unavailableread loadwrite load
majority991.2e-121.2e-120.560.56
4 × 4 grid474.0e-82.5e-60.250.44

Smaller quorums mean less load and lower latency, but they are easier to kill. Naor and Wool analysed this trade-off among load, capacity and availability formally.

6.3 Shapes and synchronization

Lecture 13 showed that the mean time to the first group failure depends on the shape of the lifetime distribution. The fraction of time a quorum is up, for independent copies at random ages, depends only on MTTF and MTTR:

lifetime distributionsimulated (majority of 5)exact
exponential1.05e-59.85e-6
Weibull k = 0.59.36e-69.85e-6
fixed 990 h, random ages8.27e-69.85e-6
fixed 990 h, all new at t = 01.62e-59.85e-6

The exception is instructive. Copies installed on the same day, with similar lifetimes, keep failing at nearly the same time: correlation by synchronization. Disks from one batch behave like this, which is why storage systems mix vendors and ages. (Each simulated figure rests on a few dozen outages, so ±20% is noise.)

6.4 Changing the quorums

Copies are added and removed, and votes need re-weighting. Gifford stores the voting configuration in each copy’s prefix, with version numbers, so that the current configuration is read with a read quorum like any data. Herlihy’s paper proposes reconfiguration through a replicated counter type. Doing it while operations continue is a consensus problem in disguise. Lecture 21 returns to it as membership change.


7. Quorum consensus for abstract data types (Herlihy 1986)

7.1 From read/write to operations

Gifford’s scheme treats a file as an uninterpreted value with Read and Write. Herlihy observes that many objects have operations that carry more meaning: queues, sets, directories, counters. Exploiting their semantics allows quorum choices that a read/write view cannot express.

The method:

  • Logs, not values. Each repository holds a log of timestamped events (an operation together with its response), not a value.
  • Initial and final quorums. To execute an operation, a front end reads the logs of an initial quorum and merges them in timestamp order into a view. It computes the response from the view, appends the new event, and writes the view to a final quorum.
  • Constraints from the type. The only constraint is that each operation’s initial quorum must intersect the final quorum of every earlier event it depends on. Herlihy proves that this is necessary and sufficient when the dependency relation is a serial dependency relation, which follows from the type’s specification.

7.2 The queue

For a FIFO queue:

  • Enq returns nothing about the state, so its initial quorum may be empty.
  • Deq must see every earlier Enq (to know the items) and every earlier Deq (to know which have gone): Deq’s initial quorum must meet the final quorums of both.

Writing ef, di, df for the sizes of Enq’s final, Deq’s initial and Deq’s final quorums, the constraints are di + ef > n and di + df > n.

That leaves ⌈n/2⌉ useful assignments, Herlihy’s count. With five repositories (demo 07 Part A):

objectuseful assignments
file with version numbers (Gifford)3 (r3 w3, r2 w4, r1 w5)
file with logical timestamps5
queue built on a replicated file (Enq and Deq both read-then-write)1: both majority
queue replicated as a queue3: ef1 di5 df1, ef2 di4 df2, ef3 di3 df3

7.3 Checking it (demo 07 Parts B–C)

10,000 random sequences of 12 operations each, with quorums picked at random every time:

assignmentconstraintsillegal histories
ef1 di5 df1, ef2 di4 df2, ef3 di3 df3obeyed0 / 0 / 0
ef2 di3 df2 (Deq reads one too few)di + ef = n3,848
ef3 di3 df2 (Deq writes one too few)di + df = n2,559

The violations are exactly the queue’s: a Deq that reports “empty” after an Enq, and an item dequeued twice.

The point of the exercise is the availability it buys, with repositories up 90%:

assignmentEnq unavailableDeq unavailable
ef1 di5 df11.0e-50.41
ef2 di4 df24.6e-40.081
ef3 di3 df38.6e-38.6e-3
queue on a replicated file8.6e-38.6e-3

A print spooler that must always accept jobs, and whose single printer can wait, wants ef1. Through a file interface that choice does not exist.

7.4 Directories, and “weaker” types

For a directory, a Lookup must meet the final quorums of Inserts and Changes of the same key; a Size must meet all of them. Herlihy also discusses directories that systems made “probabilistically consistent”, where updates go to one copy and propagate later. His suggestion is to see these as a different, nondeterministic type (a “SemiDirectory”, whose Lookup may return any item ever bound to the key). It needs no quorum intersection at all, and serializability still describes what programmers may rely on. That framing is the road to optimistic replication and Lecture 22.


8. Replication in practice

  • Primary-backup with leases is the workhorse. GFS gives a chunk’s primary a lease from the master. Many databases replicate synchronously to a standby and fail over through a coordination service (ZooKeeper, etcd) that itself runs a majority protocol.
  • Quorum stores: Amazon’s Dynamo (and Cassandra, Riak) expose N, R and W per request.
    • R + W > N gives overlapping quorums; R = W = 1 gives speed and availability with eventual consistency.
    • Sloppy quorums with hinted handoff count any N reachable nodes, not the item’s home nodes, so a write quorum may not intersect a later read quorum during failures: availability over consistency.
    • Read repair is used, but often after returning, so reads are not linearizable.
  • Consensus-replicated logs (Paxos, Raft: Lectures 20–21) give one-copy semantics for every operation by ordering them all through a majority-elected leader. They are §2’s “primary chosen by a majority”, made rigorous.
  • The CAP trade-off in one line: during a partition, a replicated object can stay available or stay one-copy, not both. Every row of §4.1’s table picks a side.

9. Design rules

  1. State the consistency you promise (one-copy serializable, linearizable, eventual) before choosing quorums.
  2. Make every read quorum meet every write quorum (r + w > N) if reads must be current.
  3. Order concurrent writes with unique timestamps (counter, writer id), or with locks over intersecting write quorums.
  4. Write back before returning if reads must be linearizable.
  5. Choose the leader with a majority, and let leadership expire (leases). Never promote a backup just because the primary went quiet.
  6. Replicate in order: sequence numbers or ordered channels, or a failover loses acknowledged writes.
  7. Count votes by reliability and by locality, and check: weights do not help monotonically.
  8. Remember independence. Shared racks, shared software and shared installation dates make copies fail together.
  9. Use the type’s semantics. Operations that need not see each other need not have intersecting quorums.

Summary

  • Replication buys availability, performance and durability, at the price of keeping copies one-copy.
  • ROWA makes reads nearly perfect and writes worse than one copy (4.9× with five copies at 99%). A majority makes both about a thousand times better. Correlated copies (a shared rack) lose 85× of that gain.
  • Primary-backup fails over cleanly after a crash, losing 0 acknowledged writes, but makes two primaries after a partition (27 acknowledged writes lost) unless leadership needs a majority and expires as a lease (0 lost).
  • Gifford’s weighted voting: votes, r + w > V, version numbers, writes to current copies, weak representatives. His table reproduced exactly. r and w trade read against write availability; weights help, but not monotonically.
  • A quorum store needs more than overlap:
    • r + w ≤ N gave 394–608 stale reads in 300 workloads, and split brain under partition;
    • bare version counters let replicas disagree forever (up to 213 of 300 runs); (counter, writer id) fixed it, even with w = 2 of 5;
    • majority reads can still go new-then-old, and read repair makes them linearizable at twice the read cost.
  • Design space: quorums help only above p = 0.5. Grids cut load (0.25 vs 0.56) and availability. Synchronized copies are correlated copies.
  • Herlihy: quorum constraints come from the type’s dependencies. A replicated queue gets ⌈n/2⌉ assignments instead of 1, and can make Enq almost always available.

Common pitfalls

  • ROWA “for safety”: every copy you add makes writes less available.
  • Write-all-available under partitions: split brain.
  • Promoting a backup on a timeout without a majority and a lease.
  • r + w ≤ N “because reads are mostly fresh in testing”: uniform-latency tests hide the problem.
  • Version numbers without a tie-break, and no locks.
  • Calling majority quorums linearizable without read repair.
  • Assuming independent failures for copies in one rack, one power domain, or one software release.
  • Out-of-order replication to backups.
  • Replicating an abstract data type through a file interface, losing its availability options.

Exercises

  1. ROWA arithmetic. Copies are up with probability p = 0.95, independently. (a) For n = 4, compute the unavailability of ROWA reads and writes and of majority (r = w = 3). (b) For which n does ROWA write availability drop below 50%?

    Answer(a) ROWA read: 0.05⁴ = 6.25e-6. ROWA write: 1 − 0.95⁴ = 0.185. Majority of 4 needs 3 up: P(≤ 2 up) = P(2) + P(1) + P(0) = 6·0.95²·0.05² + 4·0.95·0.05³ + 0.05⁴ ≈ 0.01354 + 0.000475 + 0.0000063 ≈ 0.0140. Note that with an even n, a majority (3 of 4) is no better than a majority of 3 (2 of 3: 1 − 0.95³ − 3·0.95²·0.05 ≈ 0.00725), and here it is worse. (b) 0.95ⁿ < 0.5 when n > ln 0.5 / ln 0.95 ≈ 13.5, so from n = 14.
  2. Choose the votes. Three servers: A (local, 20 ms, up 99.9%), B and C (remote, 120 ms, up 99%). Reads are 95% of operations. Propose votes, r and w, and give read and write latency and blocking probability. Compare with equal votes and majority quorums.

    AnswerOne good choice is votes ⟨2, 1, 1⟩ with r = 2 and w = 3 (Gifford's Example 2 pattern). Reads need A alone (20 ms), or B and C together; blocking ≈ P(A down) × P(not both B and C up) = 0.001 × 0.0199 ≈ 2.0e-5. Writes need A plus B or C, at 120 ms; blocking ≈ P(A down) + P(A up) × P(B and C down) ≈ 0.001 + 0.0001 ≈ 1.1e-3. With equal votes and r = w = 2: reads and writes both need two servers, so reads take 120 ms (A plus a remote one). Blocking for both is P(at most one up) ≈ 0.001·0.01·2 + 0.01² ≈ 1.2e-4. The weighted choice gives up some write availability for 6× faster reads and better read availability, which suits a 95% read mix.
  3. Partition sides. Seven replicas with one vote each, r = 3, w = 5. A partition splits them 4 | 3. Which side can read, which can write? Is anything unsafe?

    AnswerReads need 3 copies: both sides can read. Writes need 5: neither side can write. Nothing is unsafe: any read quorum (3) meets any write quorum (5), since 3 + 5 > 7, and no write can happen during the partition, so both sides read the same last-written value. With r = 4, w = 4, the side of 4 could both read and write, and the side of 3 could do neither.
  4. Two writers, one version. In a store without tie-breaks, writers X and Y both read version 9 from overlapping read quorums and write version 10 with values x and y. Replicas keep the first version-10 value they receive. (a) What can the replicas hold afterwards? (b) What can later reads return? (c) Give two fixes.

    Answer(a) Some replicas hold (10, x), others (10, y), depending on arrival order, and nothing ever reconciles them, since neither is "newer". (b) A read returns x or y depending on which replicas answer first: two reads in a row can return different values with no write in between, which no single copy would do. (c) Make timestamps unique and totally ordered, (counter, writer id), so that every replica keeps the same winner (y, say, if Y's id is larger). Or serialize writers with locks on intersecting write quorums (w > N/2, Gifford's setting), so that the second writer waits and then reads version 10.
  5. Read repair by hand. Five replicas hold (ts 4, “a”) on R1–R5. A write of (5, “b”) reaches R1 only, then the writer pauses. Reader P asks R1, R2, R3; reader Q, starting after P returns, asks R3, R4, R5. (a) What do they return without read repair? (b) With it? (c) Is the history linearizable in each case?

    Answer(a) P sees ts 5 at R1 and returns "b"; Q sees only ts 4 and returns "a". (b) With read repair, P writes (5, "b") to a write quorum, say R1–R3, before returning "b"; Q's quorum includes R3, so it returns "b". (c) Without read repair it is not linearizable: "b" was returned, then a later read returned the older "a" with no intervening write. With read repair it is: the write of "b" can be placed before P's read, and Q's read after it.
  6. Grid quorums. In a 3 × 3 grid (copies indexed row × column), give a smallest read quorum and a smallest write quorum, prove they intersect, and say what one more column of failed copies does to each operation.

    AnswerRead quorum: one copy per column, for example (0,0), (1,1), (2,2): 3 copies. Write quorum: a whole column plus one copy per other column, for example column 0 = (0,0), (1,0), (2,0) plus (0,1) and (0,2): 5 copies. A read quorum has a copy in every column, including the write's full column, so they intersect. Two write quorums intersect because each contains a full column and a copy in every column. If one entire column fails, no read quorum exists (no copy in that column), so neither reads nor writes work, even though 6 of 9 copies are up. A majority quorum would still work. That is the grid's availability price for its lower load.
  7. A counter as a type. A replicated counter supports Inc() (adds 1, returns nothing) and Read() (returns the value). Using Herlihy’s method (logs of timestamped events), which quorums must intersect? How many useful assignments are there for n copies, and how does that compare with implementing the counter on a replicated file?

    AnswerInc returns nothing, so its initial quorum may be empty. Read must see every earlier Inc, so Read's initial quorum must meet Inc's final quorum: ri + if > n. Read changes nothing, so its final quorum may be empty, and no other constraint is needed: Incs commute, and neither Inc nor Read depends on earlier Reads. Useful assignments: if from 1 to n with ri = n + 1 − if, giving n of them, including "Inc anywhere, Read everywhere". On a file, Inc becomes read-then-write: its initial quorum must meet earlier Incs' final quorums and its final quorum must meet later reads, which with version numbers forces writes to intersect. That leaves ⌈n/2⌉ assignments, all with Inc needing at least a majority.
  8. Primary-backup and leases. A primary holds a 2-second lease, renewed every 500 ms by heartbeats acknowledged by a majority. Clocks may drift by at most 1%. (a) After a partition isolates the primary, how long must a backup wait, from the last heartbeat it saw, before taking over? (b) Why must the primary stop serving before its lease nominally ends? (c) What happens to clients of the old primary during the wait?

    Answer(a) At least the lease length measured on the backup's clock with drift allowed: 2 s × 1.01 ≈ 2.02 s after the last heartbeat it received, plus a margin. Many systems also add the maximum message delay, because the lease may have been granted slightly later than the backup heard it. (b) The primary measures the lease from when it *sent* the heartbeat, on its own clock, which may run slow. Stopping at, say, 2 s × 0.99 ≈ 1.98 s guarantees that it stops before any backup could have taken over. (c) Their requests fail, or wait, for up to about 2 s: unavailability is the price of never having two primaries. Shorter leases shorten the gap but need more frequent heartbeats and tighter clock bounds.
  • No problem set question targets this lecture directly. PS4’s DHT question replicates each key at its successors without quorums. §1’s taxonomy explains what such replication guarantees, and what it does not.
  • No project uses quorums. Project 4’s coordinator is a single primary; §2 explains why replicating it would need a majority.

Further reading

  • D. K. Gifford, “Weighted Voting for Replicated Data”, SOSP 1979 — reading.
  • M. Herlihy, “A Quorum-Consensus Replication Method for Abstract Data Types”, ACM TOCS 4(1), 1986 — reading.
  • R. H. Thomas, “A Majority Consensus Approach to Concurrency Control for Multiple Copy Databases”, ACM TODS 4(2), 1979.
  • H. Attiya, A. Bar-Noy and D. Dolev, “Sharing Memory Robustly in Message-Passing Systems”, JACM 42(1), 1995.
  • M. P. Herlihy and J. M. Wing, “Linearizability: A Correctness Condition for Concurrent Objects”, ACM TOPLAS 12(3), 1990.
  • S. Y. Cheung, M. H. Ammar and M. Ahamad, “The Grid Protocol: A High Performance Scheme for Maintaining Replicated Data”, ICDE 1990.
  • M. Naor and A. Wool, “The Load, Capacity, and Availability of Quorum Systems”, SIAM J. Computing 27(2), 1998.
  • P. A. Bernstein, V. Hadzilacos and N. Goodman, Concurrency Control and Recovery in Database Systems, 1987, chapter 8 (replicated data).
  • G. DeCandia et al., “Dynamo: Amazon’s Highly Available Key-value Store”, SOSP 2007.
  • S. Ghemawat, H. Gobioff and S.-T. Leung, “The Google File System”, SOSP 2003 — leases for primaries.

Preview of Lecture 20 — Consensus I: leader election and Paxos

Sections 2 and 5 kept running into one question: how do replicas agree — on who the primary is, or on which value was written — when messages are delayed and machines crash, without ever disagreeing? Lecture 20 states the consensus problem precisely, shows why majorities are the key (every two intersect), and builds Paxos step by step:

  • Prepare and Promise;
  • PleaseAccept and Accept_OK;
  • what each acceptor must store stably;
  • why a single value is chosen no matter how proposals interleave;
  • why two proposers can still keep each other from finishing.

术语表 (Glossary, English → 中文)

English中文
replication / replica复制 / 副本
one-copy semantics单副本语义
one-copy serializability单副本可串行化
linearizability线性一致性(可线性化)
pessimistic / optimistic replication悲观 / 乐观复制
primary-backup (primary copy)主备复制(主副本)
failover故障切换
split brain脑裂
lease租约
heartbeat心跳
view / view change视图 / 视图变更
synchronous replication同步复制
read-one/write-all (ROWA)读一写全
read-one/write-all-available读一写全部可用副本
quorum / read quorum / write quorum法定人数(仲裁集) / 读仲裁集 / 写仲裁集
quorum intersection仲裁集相交
weighted voting / votes加权投票 / 票数
representative / weak representative代表(副本) / 弱代表(零票副本)
file suite文件组
version number版本号
current copy / obsolete copy当前副本 / 过时副本
blocking probability阻塞概率
stale read陈旧读
logical timestamp / tie-break逻辑时间戳 / 平局决胜
Thomas write ruleThomas 写规则
read repair (write-back)读修复(回写)
atomic register (ABD)原子寄存器(ABD 算法)
grid quorum网格仲裁集
load (of a quorum system)(仲裁系统的)负载
correlated failures相关故障
reconfiguration重配置
abstract data type抽象数据类型
general quorum consensus通用仲裁共识
initial quorum / final quorum初始仲裁集 / 终结仲裁集
event / history / view事件 / 历史 / 视图
serial dependency relation串行依赖关系
front end / repository前端 / 存储库
sloppy quorum / hinted handoff宽松仲裁 / 提示移交
eventual consistency最终一致性
CAP trade-offCAP 权衡
← 返回课程目录