DIC: AMP Happened Before
Distributed algorithms depend on being able to "time-order" events that happen across (distant) systems. This can be linked with the problem of synchronization of clocks. But, we seek a much simpler solution.
1 Happened-Before
1.1 Event Ordering
- An event is the execution of anything: a statement, a send, a receive, etc.
- Any two events a and b in a single process (i.e., without //) are clearly ordered: either a happens before b (written a → b) or the otherway (b → a).
- Let a and b be two events taken from two processes. Can we order these two? If a is the sending of a message, and b is the receiving of that message, we can see that a → b.
- What if a and b are not so? We cannot say either that a → b or the otherway b → a.
- Happens Before is transitive: a → b and b → c implies a → c.
- Events across processes are only partially ordered.
1.2 Logical Clocks
- Distributed systems do not have central clocks.
- Yet, we desire to establish a total order among events across processes. That is, we wish either a → b or b → a even when a and b are not from the same process or send/receives.
- A logical clock is a private counter
lc
maintained by each process. - On every event,
lc : = lc + 1
. - Include lc as part of every message sent, as the time stamp of the sender.
- On receiving (m, ts), receiver does
lc : = max(lc, ts+1) + 1
- Assume lc never overflows. Arbitrary precision.
2 Reading beyond the Lectures
3 References
- Gregory R. Andrews, Concurrent Programming: Principles and Practice, Benjamin/Cummings, 1991. Chapter 7 on AMP. Required Reading.
- https://en.wikipedia.org/wiki/Happened-before
- https://en.wikipedia.org/wiki/Lamport_timestamps
- Lamport, Leslie (1978). "Time, Clocks and the Ordering of Events in a Distributed System", http://research.microsoft.com/en-us/um/people/lamport/pubs/time-clocks.pdf, Communications of the ACM, 21(7), 558-565.