Lecture 7: More Virtual Clocks — 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.
Simultaneity
e1 happens before e2 (written e1 HB e2, or e1 → e2):
- They happen on one machine, and e1 is first
- e2 receives a message that e1 sent
- Or any transitive combination
e1 is concurrent with e2 (simultaneous) if e1 did not HB e2 and e2 did not HB e1.
Event
An event is one of:
- Node executed a local instruction
- Sending a message
- Receiving a message
Some events may appear to occur in different orders to different observers.
Space-Time Diagram (Example 1)
Diagram: Four processes A, B, C, D as vertical lines, time flows downward. Events labeled e1 through e4:
- e1 on process A (near top). A message arrow goes from e1 on A to e2 on B (downward-right).
- e3 on process D (mid-height). A message arrow goes from e3 on D to e4 on C (downward-left).
- e2 and e4 have no causal connection.
- In this version, e2 is slightly higher on the slide than e4, so e2 appears to happen earlier.
Written below: "which is first, e2 or e4? they're concurrent"
Space-Time Diagram (Example 2)
Diagram: Same four processes A, B, C, D. Everything is the same as before, but now e2 is slightly below e4 on the slide, so e2 appears to happen later than e4.
Space-Time Diagram from Lamport's paper
Diagram: Three processes P, Q, R as vertical lines, time flows downward. Events and messages:
- q1 on Q (top). Messages go from q1 to p2 on P (left) and from q1 to r4 on R (right, long diagonal).
- p1 on P sends a message to q2 on Q.
- q4 on Q sends a message to r3 on R. This arrow and the q1→r4 arrow cross each other.
- q5 on Q sends a message to p4 on P.
- r2 on R sends a message to q7 on Q.
Logical Clocks
Can we compute HB from inside the distributed system?
- Logical clocks: C maps events → timestamps (non-negative integers)
- C(e) = logical timestamp of e
Clock Condition: if e1 HB e2 then C(e1) < C(e2)
Lamport Clock Algorithm
- Every node will timestamp its events
- Add to every message the logical time of the send event
- On recv:
- Take the timestamp of the previous event on this node
- Take the timestamp on the message (of the send event)
- Take the max, add 1