p 1

Theoretical Foundations:
Partially Ordered Clocks
CS/CE/TE 6378
Advanced Operating Systems
Theoretical Foundations
▸Clocks
▹Logical clocks (Lamport)
▹Partially ordered clocks (Fidge)
▸Causally ordered message delivery
▹Broadcast-based (Birman et al.)
▹Unicast-based (Raynal, Schiper & Toueg)
▸System states
▹Global snapshots (Chandy & Lamport)
▹Termination detection (Huang)
Theoretical Foundations
2
“Happened Before” Relation
▸Denoted by “→”
▸Conditions:
▹If a and b are events in the same process and
a comes before b, then a → b.
▹If a is the sending of a message by one process and
b is the receipt of the same message by another
process, then a → b.
▹If a → b and b → c, then a → c.
Theoretical Foundations > Logical Clocks > Happened Before Relation
3
Concurrent Relation
▸Denoted by “ǀǀ” in this course
▸Definition:
▹For two distinct events a and b,
if a ↛ b (i.e., a → b is false)
and b ↛ a (i.e., b → a is false),
then a ǀǀ b.
▸Not transitive!
▹If a ǀǀ b and b ǀǀ c, then a ǀǀ c is not necessarily true
Theoretical Foundations > Logical Clocks > Concurrent Relation
4
Logical Clocks
▸Logical Clock:
▹a method for assigning a number to an event
▸Clock function:
▹A clock Ci assigns a number Ci⟨a⟩ to any event a in
process Pi
▸System clock function:
▹C assigns to any event b the number C⟨b⟩, where
C⟨b⟩ = Cj⟨b⟩, if b is an event in process Pj
Theoretical Foundations > Logical Clocks > Clock Condition
5
Clock Condition
▸Definition:
▹For any events a and b,
if a → b then C⟨a⟩ < C⟨b⟩
▸Basic logic: the reverse is not true
▹if C⟨a⟩ < C⟨b⟩ then a → b is not necessarily true
Theoretical Foundations > Logical Clocks > Clock Condition
6
Total Ordering Relation
▸Denoted by “⇒”
▸Uses an arbitrary total ordering “≺” for the
processes
▸Definition:
▹If a is an event in process Pi and b is an event in
process Pj, then a ⇒ b iff (i.e., if and only if) either
(i) Ci⟨a⟩ < Cj⟨b⟩ or
(ii) Ci⟨a⟩ = Cj⟨b⟩ and Pi ≺ Pj
Theoretical Foundations > Logical Clocks > Total Ordering
7
Logical Clock Exercise
P
p1 = 1
p2 = 3
p3 = 5
p4 = 6
p5 = 7
Tm = 6
Tm = 2
Q
q1 = 1
q3 = 9
q2 = 2
Tm = 2
R
r1 = 3
Tm = 4
r2 = 4
r3 = 7
Tm = 8
r4 = 8
▸Total ordering of all events given Q ≺ R ≺ P?
▹ q1 ⇒ p1 ⇒ q2 ⇒ r1 ⇒ p2 ⇒ r2 ⇒
p3 ⇒ p4 ⇒ r3 ⇒ p5 ⇒ r4 ⇒ q3
Theoretical Foundations > Logical Clocks > Total Ordering
8
Theoretical Foundations
▸Clocks
▹Logical clocks (Lamport)
▹Partially ordered clocks (Fidge)
▸Causally ordered message delivery
▹Broadcast-based (Birman et al.)
▹Unicast-based (Raynal, Schiper & Toueg)
▸System states
▹Global snapshots (Chandy & Lamport)
▹Termination detection (Huang)
Theoretical Foundations
9
Revisits “Happened Before” Relation
▸Still denoted by “→”
▸Description:
▹An irreflexive, transitive relation among the events
performed during a given computation
▸Definition:
▹Smallest relation satisfying the six following
conditions
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
10
“Happened Before” Condition #1
▸Sequential Behavior:
▹If events e and f occur in the same process p,
and f occurs after e, then e → f.
p
e
f
▸One of Lamport’s conditions?
▹Yes
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
11
“Happened Before” Condition #2
▸Process Creation:
▹If event e and process q occur in the same process p,
and event f occurs in q, and q begins after e,
then e → f.
p
e
q
f
▸One of Lamport’s conditions?
▹No
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
12
“Happened Before” Condition #3
▸Process Termination:
▹If event e and process q occur in the same process p,
and event f occurs in q, and e occurs after q
terminates, then f → e.
e
p
q
f
▸One of Lamport’s conditions?
▹No
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
13
“Happened Before” Condition #4
▸Synchronous Message-Passing:
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
14
Synchronous Message-Passing
Channel c
Sender
Receiver
send(e,c)
receive(c)
▸ The process calling the
send operation is
blocked until the
message e is received
from the channel c.
▸ The process calling the
receive operation is
blocked until a message
is sent to the channel c.
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
15
“Happened Before” Condition #4
▸Synchronous Message-Passing:
▹If event e is a synchronous send, and event f is the
corresponding receive, and there is an event g
such that e → g, then f → g. If there is an event h
such that h → e, then h → f.
f
h
e
g
▸One of Lamport’s conditions?
▹No
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
16
“Happened Before” Condition #5
▸Asynchronous Message-Passing:
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
17
Asynchronous Message-Passing
Port p
Sender
Receiver
send(e,p)
receive(p)
▸ The process calling the
send operation is not
blocked. The message e
is queued at the port p
if the receiver is not
waiting.
▸ The process calling the
receive operation is
blocked if there are no
messages queued at the
port p.
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
18
“Happened Before” Condition #5
▸Asynchronous Message-Passing:
▹If event e is an asynchronous send, and event f is the
corresponding receive, then e → f.
f
e
▸One of Lamport’s conditions?
▹Yes
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
19
“Happened Before” Condition #6
▸Transitivity:
▹If e → f and f → g, then e → g.
g
f
e
▸One of Lamport’s conditions?
▹Yes
Theoretical Foundations > Partially Ordered Clocks > Happened Before Relation
20
Partially Ordered Timestamps
▸Assume ei represents event e performed by
process i
▸tei is the timestamp for event ei and consists of
partially ordered pairs
▸Partially Ordered Pair:
▹a pair consisting of a process identifier j and a clock
counter nj representing the value of the clock at
process j, as perceived by the current process
Theoretical Foundations > Partially Ordered Clocks > Timestamps
21
Partially Ordered Timestamps
▸Timestamp representation:
▹{ (i, ni), …, (r, nr) }
▸Example timestamp:
▹tei = { (P, 4), (R, 1), (S, 1) }
▸tei(j) is the value of the counter for process j in this
timestamp
▹tei(P) = 4, tei(R) = 1, tei(S) = 1
▸Counters for unknown processes are considered 0
▹tei(Q) = 0, tei(T) = 0
Theoretical Foundations > Partially Ordered Clocks > Timestamps
22
Implementation Rule A
▸Initialization
When the program begins execution, the time is
initialized to the empty set (i.e., Cm = { }, where
m is the process identifier associated with the
main program).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
23
Partially Ordered Clock Example
Process
C
B
Q
D
Process
P
E
A
F
M
G
?
Process
Process
R
S
J
I
L
H
Process
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
24
Partially Ordered Clock Example
Process
C
B
Q
D
Process
P
E
A
F
M
G
{}
Process
Process
R
S
J
I
L
H
Process
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
25
Implementation Rule B
▸Ticking
Whenever a process i performs an event, it
increments Ci(i) at least once.
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
26
Partially Ordered Clock Example
Process
C
B
Q
D
Process
P
{}
E
A
F
M
G
?
Process
Process
R
S
J
I
L
H
Process
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
27
Partially Ordered Clock Example
Process
C
B
Q
D
Process
P
{}
E
A
F
M
G
{ (P, 1) }
Process
Process
R
S
J
I
L
H
Process
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
28
Implementation Rule C
▸Monotonically Increasing Counters
No counter in any Cj is ever decremented.
▸Why?
▹Can’t rewind time
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
29
Implementation Rule D
▸Process Creation
Whenever a process i creates a set of
processes { j, …, r }, they each inherit the current
time from process i (i.e.,∀x:[j…r] Cx = Ci)
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
30
Partially Ordered Clock Example
Process
C
B
Q
D
?
Process
P
{}
E
A
F
M
G
{ (P, 1) }
Process
Process
R
S
J
I
L
H
?
Process
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
31
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
E
A
F
M
G
{ (P, 1) }
Process
R
H
{ (P, 1) }
?
Process
Process
S
J
I
L
T
K
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
32
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
E
A
F
M
G
{ (P, 1) }
Process
S
J
I
?
Process
R
L
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
K
?
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
33
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
{ (P, 1) }
?
F
Process
S
M
G
J
I
{ (P, 1), (R, 1) }
Process
R
L
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
34
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
{ (P, 1) }
{ (P, 2) }
F
Process
S
M
G
J
I
{ (P, 1), (R, 1) }
Process
R
L
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
35
Implementation Rule E
▸Process Termination
▹Will come back to in a second
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
36
Implementation Rule F
▸Synchronous Events
During a synchronous event, all processes
involved { j, …, r} maximize their local clocks
(i.e.,∀x:[j…r] Cx = max(Cj, …, Cr) ).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
37
Max Function
▸Given one or more partially ordered timestamps,
returns a time reading in which every counter is
set to the maximum of all corresponding values
▸Example:
▹max( { (i, 2), (j, 1), (k, 3) }, { (i, 4), (k, 1) } )?
{ (i, 4), (j, 1), (k, 3) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
38
Implementation Rule F
▸Synchronous Events
During a synchronous event, all processes
involved { j, …, r} maximize their local clocks
(i.e.,∀x:[j…r] Cx = max(Cj, …, Cr) ).
▸Important! Apply after rule B (ticking).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
39
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
F
{ (P, 1) }
{ (P, 2) }
?
Process
S
M
G
J
I
{ (P, 1), (R, 1) }
Process
R
L
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
40
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
F
{ (P, 1) }
{ (P, 2) }
{ (P, 3) }
Process
S
{ (P, 1), (R, 1) }
Process
R
J
I
?
L
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
M
G
T
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
41
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
F
{ (P, 1) }
{ (P, 2) }
{ (P, 3) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
M
G
J
I
{ (P, 1), (R, 1), (S,
1) }
L
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
42
Partially Ordered Clock Example
Process
C
B
Q
D
{ (P, 1) }
Process
P
{}
A
E
F
{ (P, 1) }
{ (P, 2) }
{ (P, 3) } ?
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
M
G
J
I
{ (P, 1), (R, 1), (S,
1) } ?
L
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
43
Partially Ordered Clock Example
Q
B
{ (P, 1) }
?
Process
C
D
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
M
G
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
J
I
{ (P, 3), (R, 1), (S,
1) }
L
K
{ (P, 1), (R, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
44
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
D
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
M
G
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
J
I
{ (P, 3), (R, 1), (S,
1) }
L
K
?
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
45
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
D
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
M
G
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
I
J
{ (P, 3), (R, 1), (S,
1) }
?
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
46
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
D
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
M
G
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
47
Implementation Rule G
▸Sending
Whenever a process i sends a message, that
message carries the current value of Ci.
▸Important! Apply after rule B (ticking).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
48
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
D
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
?
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
49
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
D
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
50
Implementation Rule H
▸Receiving
Upon receiving a message, the receiving
process i maximizes its counter values using
those received in the piggybacked timestamp
Creceived (i.e., Ci = max(Ci, Creceived) ).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
51
Partially Ordered Clock Example
Process
B
C
{ (P, 1), (Q, 1) }
?
Q
{ (P, 1) }
D
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
52
Partially Ordered Clock Example
Process
B
C
{ (P, 1), (Q, 1) }
{ (P, 4), (Q, 2),
(R, 1), (S, 1) }
Q
{ (P, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
D
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
53
Implementation Rule E
▸Process Termination
Whenever a set of processes { j, …, r }
terminates, the parent process i merges all the
children’s clocks by maximizing the counter
values (i.e., Ci = max(Ci, Cj, …, Cr) ).
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
54
Partially Ordered Clock Example
Process
B
C
{ (P, 1), (Q, 1) }
{ (P, 4), (Q, 2),
(R, 1), (S, 1) }
Q
{ (P, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
?
{ (P, 1) } { (P, 1), (R, 1) }
Process
M
G
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
D
T
{ (P, 1), (R, 1) }
L
K
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
55
Partially Ordered Clock Example
Process
B
C
{ (P, 1), (Q, 1) }
{ (P, 4), (Q, 2),
(R, 1), (S, 1) }
Q
{ (P, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
D
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
K
L
?
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
56
Partially Ordered Clock Example
Process
B
C
D
{ (P, 1), (Q, 1) }
{ (P, 4), (Q, 2),
(R, 1), (S, 1) }
?
Q
{ (P, 1) }
Process
P
{}
E
A
{ (P, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
M
G
{ (P, 4), (R, 1), (S, 1) }
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
57
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
?
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
58
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
© 2013 Dr. Ryan P. McMahan
59
Implementation Rule I
▸Timestamping
The timestamp tei, associated with the
execution of event e by process i, is the value of
Ci immediately following the application of rules
B through H.
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
60
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸tG ? { (P, 4), (R, 1), (S, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
61
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
Process
S
{ (P, 1), (R, 1) }
Process
H
R
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
▸tG(P) ? 4
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
{ (P, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
62
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
Process
S
{ (P, 1), (R, 1) }
Process
H
R
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
▸tG(S) ? 1
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
{ (P, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
63
Partially Ordered Clock Example
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
Process
S
{ (P, 1), (R, 1) }
Process
H
R
{ (P, 1) } { (P, 1), (R, 1) }
Process
T
{ (P, 1), (R, 1) }
▸tG(Q) ? 0
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
{ (P, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
64
Quiz Question
▸What is the timestamp of r5?
▹t = { (Q, 2), (R, 5) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
65
Quiz Question
▸What is the timestamp of r6?
▹t = { (P, 3), (Q, 3), (R, 6) }
Theoretical Foundations > Partially Ordered Clocks > Implementation Rules
66
Comparison Property
▸Given two timestamps tei and tfj,
event ei happened before event fj iff
tfj has knowledge of process i as recent as the
execution of ei but not vice versa
ei  fj  (tei(i) ≤ tfj(i)) ∧ (tei(j) < tfj(j))
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
67
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸B  D ? Yes, (1 ≤ 3) ^ (1 < 3)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
68
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸G  C ? Yes, (4 ≤ 4) ^ (0 < 2)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
69
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸I  D ? Yes, (1 ≤ 1) ^ (0 < 3)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
70
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸C  B ? No, (2 ≤/ 1) ^ (2 </ 1)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
71
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸C  C ? No, (2 ≤ 2) ^ (2 </ 2)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
72
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸F  I ? No, (3 ≤ 3) ^ (1 </ 1)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
73
Comparison Property Examples
Process
C
B
Q
{ (P, 1) }
{ (P, 4), (Q, 2), { (P, 4), (Q, 3),
(R, 1), (S, 1) }
(R, 1), (S, 1) }
{ (P, 1), (Q, 1) }
Process
P
{}
E
A
{ (P, 1) }
Process
S
{ (P, 1), (R, 1) }
Process
R
H
{ (P, 1) } { (P, 1), (R, 1) }
Process
G
M
{ (P, 4), (R, 1), (S, 1) }
{ (P, 5), (Q, 3),
(R, 2), (S, 2), (T, 1) }
F
{ (P, 2) } { (P, 3), (R, 1), (S, 1) }
T
{ (P, 1), (R, 1) }
D
J
I
{ (P, 3), (R, 1), (S, { (P, 3), (R, 1), (S, 2) }
1) }
K
L
{ (P, 3), (R, 1),
(S, 2), (T, 1) }
{ (P, 3), (R, 2),
(S, 2), (T, 1) }
{ (P, 1), (R, 1), (T, 1) }
▸I  F ? No, (1 ≤ 1) ^ (3 </ 3)
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
74
Quiz Questions
▸If tp = { (P, 3), (Q, 3) } and tq = { (Q, 3) }, then
3
3
▹p3  q3 ? No, (3 ≤/ 0) ^ (3 </ 3)
▹q3  p3 ? Yes, (3 ≤ 3) ^ (0 < 3)
▸If tq = { (Q, 3) } and tr = { (Q, 2), (R, 3) }, then
3
3
▹q3  r3 ? No, (3 ≤/ 2) ^ (0 < 3)
▹r3  q3 ? No, (3 ≤/ 0) ^ (2 < 3)
▹Hence, q3 and r3 are concurrent
Theoretical Foundations > Partially Ordered Clocks > Comparison Property
75
Optimization: Vector Clocks
▸Assume a static number of processes
▸Use an array of counters instead of pairs
▸Pros:
▹Provide an upper bound on storage requirements for
clock variables
▹Clock variables are easier to read and manipulate
▸Cons:
▹The upper bound on storage requirements is also the
lower bound
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
76
Vector Clock Example
Process
C
B
Q
D
Process
P
E
A
F
M
G
?
Process
Process
R
S
J
I
L
H
Process
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
77
Vector Clock Example
Process
C
B
Q
D
Process
P
[0 0 0 0 0]
E
A
F
M
G
?
Process
Process
R
S
J
I
L
H
Process
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
78
Vector Clock Example
Process
C
B
Q
D
Process
P
[0 0 0 0 0]
E
A
F
M
G
[1 0 0 0 0]
Process
Process
R
S
J
I
L
H
?
Process
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
79
Vector Clock Example
Process
C
B
Q
D
Process
P
[0 0 0 0 0]
A
E
[1 0 0 0 0]
?
F
Process
Process
R
S
J
I
L
H
[1 0 1 0 0]
Process
M
G
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
80
Vector Clock Example
Process
C
B
Q
D
Process
P
[0 0 0 0 0]
A
E
F
[1 0 0 0 0]
[2 0 0 0 0]
?
Process
S
M
G
J
I
?
Process
R
L
H
[1 0 1 0 0]
Process
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
81
Vector Clock Example
Process
C
B
Q
D
?
Process
P
[0 0 0 0 0]
A
E
F
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
Process
S
M
G
J
I
[3 0 1 1 0]
Process
R
L
H
[1 0 1 0 0]
Process
T
K
▸Vector = [P Q R S T]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
82
Vector Clock Example
Process
C
B
Q
D
[1 1 0 0 0]
Process
P
[0 0 0 0 0]
A
E
F
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
Process
S
M
G
J
I
[3 0 1 1 0]
Process
R
L
H
[1 0 1 0 0]
Process
T
▸Vector = [P Q R S T]
K
?
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
83
Vector Clock Example
Process
C
B
Q
D
[1 1 0 0 0]
Process
P
[0 0 0 0 0]
A
E
F
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
Process
Process
R
S
I
J
[3 0 1 1 0]
?
L
H
[1 0 1 0 0]
Process
M
G
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
84
Vector Clock Example
Process
C
B
Q
D
[1 1 0 0 0]
Process
P
[0 0 0 0 0]
A
E
F
G
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
?
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
L
H
[1 0 1 0 0]
Process
M
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
85
Vector Clock Example
Process
B
C
[1 1 0 0 0]
?
Q
D
Process
P
[0 0 0 0 0]
A
E
F
G
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
[4 0 1 1 0]
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
L
H
[1 0 1 0 0]
Process
M
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
86
Vector Clock Example
Process
B
C
D
[1 1 0 0 0]
[4 2 1 1 0]
?
Q
Process
P
[0 0 0 0 0]
A
E
F
G
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
[4 0 1 1 0]
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
L
H
[1 0 1 0 0]
Process
M
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
87
Vector Clock Example
Process
B
C
D
[1 1 0 0 0]
[4 2 1 1 0]
[4 3 1 1 0]
Q
Process
P
[0 0 0 0 0]
A
E
F
G
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
[4 0 1 1 0]
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
M
H
L
[1 0 1 0 0]
?
Process
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
88
Vector Clock Example
Process
B
C
D
[1 1 0 0 0]
[4 2 1 1 0]
[4 3 1 1 0]
Q
Process
P
[0 0 0 0 0]
A
E
F
G
M
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
[4 0 1 1 0]
?
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
H
L
[1 0 1 0 0]
[3 0 2 2 1]
Process
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
89
Vector Clock Example
Process
B
C
D
[1 1 0 0 0]
[4 2 1 1 0]
[4 3 1 1 0]
Q
Process
P
[0 0 0 0 0]
A
E
F
G
M
[1 0 0 0 0]
[2 0 0 0 0]
[3 0 1 1 0]
[4 0 1 1 0]
[5 3 2 2 1]
Process
Process
R
S
I
J
[3 0 1 1 0]
[3 0 1 2 0]
H
L
[1 0 1 0 0]
[3 0 2 2 1]
Process
T
▸Vector = [P Q R S T]
K
[1 0 1 0 1]
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
90
Quiz Question
▸Consider a system with processes P, Q, R, and S.
Assume vector-time elements are alphabetically
ordered.
If tq = { (Q, 3), (R, 2), (S, 1) }, then [3 2 1] is the
3
vector-time equivalent.
▹False. Should be [0 3 2 1].
Theoretical Foundations > Partially Ordered Clocks > Vector Clocks
91
Applications
▸Languages
▸Debugging distributed systems
▸Definition of global states
▸Concurrency measures
▸Enforcement of causal ordering
Theoretical Foundations > Partially Ordered Clocks
92
Questions
Theoretical Foundations > Partially Ordered Clocks
93