Time and Ordering Lab
Retrieval Prompts
- State the happens-before relation in words, including the three rules.
- Write the Lamport clock update rule from memory for a local event, a send, and a receive.
- Write the vector clock update rule from memory for the same three cases.
- State the comparison rule for "a happens before b" using vector clocks.
- State two things you should never use wall-clock time for in a distributed system.
Compare and Distinguish
Separate these pairs cleanly in writing:
- wall-clock time vs monotonic time
- monotonic time vs logical time
- Lamport clock vs vector clock
L(a) < L(b)vsa -> b- "concurrent" in a distributed sense vs "simultaneous" in a wall-clock sense
Common Mistake Check
For each, identify the error:
- "Our servers run NTP so timestamp-based last-write-wins is safe."
- "I used
System.nanoTime()to stamp events and compared them across two services." - "Lamport timestamps
L(a) = 3andL(b) = 3meanaandbare concurrent." - "Vector clocks give a total order over events."
- "We resolve write conflicts by the timestamp with the largest value."
Mini Application: Three-Process Trace by Hand
Work this trace on paper, filling in both Lamport and vector timestamps at every event.
Processes: P1, P2, P3. Events in real-time order:
aon P1 (local)bon P2 (local)- P1 sends
m1to P2; receiptcon P2 don P3 (local)- P2 sends
m2to P3; receipteon P3 fon P1 (local)- P3 sends
m3to P1; receiptgon P1 hon P2 (local)
Deliverables:
- Lamport timestamp on each event.
- Vector timestamp on each event.
- A written list of every pair of concurrent events you can detect from the vector clocks but not from the Lamport clocks.