Professional Documents
Culture Documents
M. T. Bennani
Assistant Professor, FST - El Manar University, LISI-INSAT
2 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Event:
I occurrence of a single action that a process carries out as it
executes
3 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Thus, if e and e’ are events, and if e − > e’, then we can find
a series of events e1, e2, ..., en occurring at one or more
processes such that
I e = e1 , e’ = en ,
I for i = 1, 2, ..., N-1 either HB1 or HB2 applies between ei
and ei+1 .
- Either they occur in succession at the same process, or there is a
message m such that ei = send(m) and ei+1 = receive(m).
5 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Introduction
Definition:
local logical clock Li in process pi is a function which associates a
value, Li (e), in an ordered set V with each event e in pi .
I Note that values of a logical clock need bear no particular
relationship to any physical clock.
8 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
9 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
In Practice
I To capture the − > relation, processes update their logical
clocks and transmit the values of their logical clocks in
messages as follows:
I LC1: Li is incremented before each event is issued at process
pi : Li := Li + 1.
I LC2: (a) When pi sends a msg m, it piggybacks on m the
value t = Li .
(b) On receiving (m, t), a process pj computes
Lj := max(Lj , t) and then applies LC1 before timestamping
the event receive(m).
I Although we increment clocks by 1, we could have chosen any
positive value.
I Clocks which follow these rules are known as LAMPORT
LOGICAL CLOCKS.
e− > e 0 ⇒ L(e) < L(e 0 )
10 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
11 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
12 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
13 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
14 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Exercise 1
By considering a chain of zero or more messages connecting events
e and e’ and using induction on the length of any sequence of
events relating e and e’, show that e − > e’ ⇒ L(e) < L(e’).
Exercise 2
15 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
16 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
18 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
19 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Vector Clocks
I A vector clock for a system of N processes: array of N
integers.
I Each process pi keeps its own vector clock Vi , which it uses to
timestamp local events.
20 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Note That . . .
Vi[j] (j 6= i):
I Latest clock value received by pi from process pj .
I Number of events that have occurred at pj that pi has
potentially been affected by.
I Process pj may have timestamped more events by this point,
but no information has flowed to pi about them in messages
yet!
21 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
22 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
23 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Ordering on Vectors
24 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
25 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
26 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Elements
In a system of matrix clocks, the time is represented by a set of
nxn matrices of non-negative integers.
A process pi maintains a matrix mti [1..n, 1..n] where,
I mti [i, i] denotes the local logical clock of pi and tracks the
progress of the computation at process pi .
I mti [i, j] denotes the latest knowledge that process pi has
about the local logical clock, mtj [j, j], of process pj .
I mti [j, k] represents the knowledge that process pi has about
the latest knowledge that pj has about the local logical clock,
mtk [k, k], of pk .
I The entire matrix mti denotes pi ’s local view of the global
logical time.
27 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Rules
Process pi uses the following rules R1 and R2 to update its clock:
I R1 : Before executing an event, process pi updates its local
logical time as follows:
mti [i, i] := mti [i, i] + d / (d > 0)
I R2: Each message m is piggybacked with matrix time mt.
When pi receives such a message (m,mt) from a process pj , pi
executes the following sequence of actions:
1. Update its global logical time as follows:
(a) 1 ≤ k ≤ n : mti [i, k] := max(mti [i, k], mt[j, k])
(That is, update its row mti [i, *] with the pj ’s row in the
received timestamp, mt.)
(b) 1 ≤ k, l ≤ n : mti [k, l] := max(mti [k, l], mt[k, l])
2. Execute R1.
3. Deliver message m.
28 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Example
I We assume d = 1.
I Let us consider the following events: e which is the xi -th
event at process pi , ek1 and ek2 which are the xk1 -th and xk2 -th
events at process pk , and ej1 and ej2 which are the xj1 -th and
xj2 -th events at process pj .
I Let mte denote the matrix timestamp associated with event e.
Due to message m4 , ek2 is the last event of pk that causally
precedes e, therefore, we have mte [i, k]=mte [k, k] = xk2 .
I Likewise, mte [i, j]=mte [j, j]=xj2 . The last event of pk known
by pj , to the knowledge of pi when it executed event e, is ek1 ;
therefore, mte [j, k]=xk1 . Likewise, we have mte [k, j]=xj1 .
29 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Example
30 / 31
Introduction Logical Clocks: Time Stamp Vector Time Matrix Time
Basic properties
I Vector mti [i,.] contains all the properties of vector clocks.
I In addition, matrix clocks have the following property:
mink (mti [k, l]) ≥ t ⇒ process pi knows that every other
process pk knows that pl ’s local time has progressed till t.
I If this is true, it is cleat that process pi knows that all other
processes know that pl will never send information with a local
time ≤ t.
I In many applications, this implies that processes will no longer
require from pl certain information and can use this fact to
discard obsolete information.
I If d is always 1 in the rule R1, then mti [k, l] denotes the
number of events occurred at pl and known by pk as far as
pi ’s knowledge is concerned.
31 / 31