Lecture 8: Vector Clocks; Linearizability; State Machine Replication — Whiteboard Descriptions
These are text descriptions of the whiteboard PDF from this lecture.
These materials were drafted by AI based on the live whiteboard PDF and audio transcript from the corresponding lecture and then reviewed and edited by course staff. They may contain errors. Please let us know if you spot any.
Clock Condition
If e1 HB e2, then C(e1) < C(e2).
The converse is false: "If C(e1) < C(e2) then e1 HB e2" does not hold.
Vector Clock
- Assign timestamps to events
- Redefine timestamp: a vector of numbers (a list of numbers)
- Length = #nodes in system
- ith component is the highest clock value you've heard about node i
Vector Clock Example (Space-Time Diagram)
Diagram: Four processes A, B, C, D as vertical lines, time flows downward. Initial vector clocks shown in orange: A = [1,0,0,0], B = [0,1,0,0], C = [0,0,1,0], D = [0,0,0,1]. Events labeled e1 through e4:
- e1 on process A (near top, Lamport clock value 1). A message arrow goes from e1 on A to e2 on B (downward-right).
- e2 on process B (receives message from A, Lamport clock value 2). Vector clock: [1,2,0,0].
- e3 on process D (mid-height, Lamport clock value 1). A message arrow goes from e3 on D to e4 on C (downward-left).
- e4 on process C (receives message from D, Lamport clock value 2). Vector clock: [0,0,2,1].
Now compare e1 and e4: the vector clocks are [1,0,0,0] vs [0,0,2,1], which are unordered, so the events are concurrent. (Neither vector is componentwise ≤ the other.)
Vector Clock Algorithm
- Init every node with 1 in its component
- Send timestamps on messages
- On recv, take the max (componentwise) and add 1 to the receiver's component
- Increment the node's component on local steps
Claim: e1 HB e2 iff VC(e1) < VC(e2) (where < on vector clocks means componentwise less-than-or-equal, with strict inequality in at least one component).
Consistency Models: Setup
Diagram: Two clients C1 and C2 each send requests to a server S in the middle. C1 has an arrow labeled "req" pointing to S, and C2 has an arrow labeled "req" pointing to S.
Diagram: A replicated service containing servers S1, S2, S3 and a view server (VS), enclosed in a large box. C1 sends a request arrow to S1 on the left side. C2 sends a request arrow that reaches S3 on the right side. The service internally handles replication across the servers.
Consistency Model
- Answers the question: what executions of a replicated state machine are correct/allowed?
- execution → bool
State Machine Replication (Single Client)
Diagram: A client C1 on the left sends requests to an RSM (replicated state machine) box on the right, which contains several server nodes. C1 sends req1, receives resp1, then sends req2, receives resp2, sequentially.
- One client
- One request at a time
- → Execute in order
State Machine Replication (Two Clients)
Diagram: Same RSM box with server nodes. Now C1 sends app(k, x) from the left and C2 sends app(k, y) from the right, concurrently.
Execute in some order:
- If C1 goes first, its response is
AppendResult(x)and C2 will getAppendResult(xy) - If C2 goes first, it gets
AppendResult(y)and C1 getsAppendResult(yx)
Sequential Consistency
An execution is allowed if there is an order of all the client operations in the execution such that the responses returned by the RSM agree with executing the requests in that order.
Linearizability
- Sequentially consistent, plus:
- If request r2 is submitted after the response to request r1 is received, then r2 must appear after r1 in the apparent execution order