Title: Logical Time and Logical Clocks
1Logical Time and Logical Clocks
References G. Coulouris, J. Dollimore and T.
Kindberg "Distributed Systems Concepts and
Design", Ed. 4, Addison-Wesley 2005, Chap.
11.4 Michel Raynal, Mukesh Singhal "Capturing
Causality in Distributed Systems", IEEE Computer,
Febr. 1996, pp. 49-56
Distributed SystemsBéat Hirsbrunner (UniFr),
Peter Kropf (UniNe) and Pierre Kuonen
(EiaFr) Summer Semester 2007, Lecture 2b, 30
March 2007
2Causality
- In relativity, if L causes R, then the order of L
and R must be the same for all observers - Woudn't this be a nice property for a distributed
computer system?
3Logical Time Basic Observation
- If two events occurred at the same process pi (i
1, 2, N) then they occurred in the order
observed by pi, that is in the order ???? - When a message m is sent between two processes,
the event of sending the message occured before
the event of receiving the message send(m) ??
receive(m)
Fig. 11.5. Events occuring at three processes
4Lamport's Happened-Before Relation ?
- HB1 for any pair of events e and e, if there is
a process pi such that e ?i e, then e ? e - HB2 for any pair of events e and e and for any
message m, if e send(m) and e receive(m),
then e ? e - HB3 if e, e and e are events and if e ? e
and e ? e, then e ? e (transitivity)
- Remarks.
- HB defines only a partial order, i.e. not all
events are related by the relation ?. - Concurrency if not (e ? e) and not (e' ? e),
events e and e' are concurrent, and are denoted
as e e'. - HB captures only potential causality, i.e. two
events can be related by ? even though there is
no real connection between them.
5Lamport's Logical Clock
- In a system of logical clock, every process has a
logical clock that is advanced using a set of
rules. - Lamport's logical clocks capture the
happen-before relation each process pi keeps
its own clock Li. - Lamport's timestamp of event e at pi is denoted
by Li(e).
The rules to update Li are LC1 Li is
incremented before each event at pi Li Li
1. LC2a When a process pi sends a message m, it
piggybacks on m the value t Li. LC2b On
receiving (m,t), a process pj computes Lj
max(Lj, t) and then applies LC1 before
timestamping the event receive(m).
6Example
Fig. 11.6
- Remark 1
- Note that e ? e gt L(e) lt L(e').
- Unfortunately, the inverse is not true!
- Remark 2
- L generates only a partial order, i.e. some
distincts events have numerically identical
Lamport timestamps. - A total order can be defined as follows
- we timestamps an event e occuring at pi with
local timestamp Ti by (Ti, i) - and define (Ti,i) lt (Tj,j) if and only if Ti lt Tj
or Ti Tj and i lt j.
7Vector Clocks
- Vector clocks overcome the shortcoming of Lamport
logical clocksL(e) lt L(e) does not imply e
happened before e.
- As for Lamport's clock, each process keeps its
own vector clock Vi - Vii is the number of events that pi has
timestamped, - Vij, i?j, is the number of events that have
occured at pj that pi has potentially been
affected to.
The rules to update the vector Vi of N intergers
are VC1 Initially Vij 0 for i, j 1, 2,
N. VC2 Just before pi timestamps an event, it
sets Vii Vii 1. VC3 pi piggybacks t
Vi on every message it sends. VC4 when pi
receives (m,t) it sets Vij max(Vij , tj)
for all j, and then applies VC2 before
timestamping the event receive(m).
8Example
Fig. 11.7
- Vector comparison definition
- V V iff Vj Vj for all j
- V ? V iff Vj ? Vj for all j
- V lt V iff V ? V and V ? V
Example V(b) lt V(d), i.e. b ? d V(e) is
unorded to V(d), i.e. e d
A last remark matrix clocks have been defined,
whereby processes keep estimates of other
processes' times as well as their own, cf Raynal
96.
Theorem e ? e ltgt V(e) lt V(e')