You are on page 1of 40

Causality

The happens before relation

p0

p1
p2

6 7
10 11 12

3
8
13 14

1 2
happens before
(causes)

9
15

16

2
2

p0
p1
p2

2
6 7

10 11 12

3
8

9
15

13 14

16

1 6
A message is sent from

to

6
3

p0
p1
p2

2
6 7

10 11 12

1 6
and

6 7

3
8
13 14

9
15

16

transitivity

1 7
4

p0
p1
p2

2
6 7

10 11 12

3
8
13 14

9
15

1 8

1 16

10 8

2 9

16

happens before is a partial order

p0
p1
p2

2
6 7

10 11 12

1
/ 10
10
/ 1

3
8
13 14

9
15

Parallel events:

16

1 10

1 10
6

happens before is a partial order

p0
p1
p2

2
6 7

10 11 12

13
/ 8
8
/ 13

3
8
13 14

9
15

Parallel events: 8

16

13

8 13
7

We can move parallel events

p0

2
6

p1
p2

10 11

4 5
7

12

13 14

9
15 16

The happens before relation


doesnt change
8

We want to find a mechanism that


captures the happens before relationship
so that we use causality in various
computation problems

Logical Clocks

p0
p1

1
0

In each process, the logical clock


increases by 1 with each local event

LT (1 ) = 1

LT ( 2 ) = LT (1 ) + 1 = 2
10

Logical clocks are piggy-packed on messages

p0
p1

LT ( 3 ) = max( LT ( 2 ), LT ( 7 )) + 1
= max(2,4) + 1
= 4 +1 = 5

11

p0

6 7

p1
p2

10 11 12
1

13 14
4

9
6

15

16

Logical clocks, seem that they capture the


happens before relation

i j

LT ( i ) < LT ( j )
12

p0

6 7

p1
p2

10 11 12
1

13 14
4

9
6

15

16

Example:

1 7

LT (1 ) = 1 < 4 = LT ( 7 )
13

p0

6 7

p1
p2

10 11 12
1

8
5

13 14

9
6

15

3
4
5
6
However, logical clocks
cannot capture parallelism

8 13
Parallel events

16
7

LT (13 ) = 4 < 5 = LT ( 8 )
(13 8 ???)

14

We need another mechanism that


can capture the parallelism of events

15

Vector Clocks

p0
p1

1
0
0

0
0

1
0

2
0

3
0

4
0

5
0

0
1

0
2

0
3

0
4

1
VC (1 ) =
0

Process

p0 entry

Process

p1 entry
16

Each process increases its entry at each event

p0
p1

1
0
0

0
0

1
0

2
0

3
0

4
0

5
0

0
1

0
2

0
3

0
4

1 2 1 3
VC ( 3 ) = VC ( 2 ) + = + =
0 0 0 0
increment

17

Each process increases its entry at each event

p0
p1

1
0
0

0
0

1
0

2
0

3
0

4
0

5
0

0
1

0
2

0
3

0
4

0 0 0 0
VC ( 9 ) = VC (8 ) + = + =
1 3 1 4
increment

18

vector clocks are piggy-packed on messages

p0
p1

0
0

0
0

1
0

2
0

0
1

0
2

0
3

0
4

2
max ,
0

0
4

3
4

0 2
=

4
4

The maximum of each entry

19

vector clocks are piggy-packed on messages

p0
p1

0
0

0
0

1
0

2
0

0
1

0
2

0
3

0
4

0
4

1
VC ( 3 ) = max(VC ( 2 ),VC ( 7 )) +
0
2 0 1
2 1
3
= max , + = + =
4 0
4
0 4 0

3
4

20

vector clocks are piggy-packed on messages

p0
p1

0
4

0
4

3
4

10
4
4

4
4

0
5

9
4
6

0
VC ( 9 ) = max(VC (8 ),VC (10 )) +
1
0
= max ,
5

4 0
4 0
4
4 + 1 = 5 + 1 = 6


21

p0

1
0

0 1
1
1

0

p1
p3

2
0

0

10 11 12
0
0

1

0
0

2

0
0

3

3
0

0 3

1
72

3

1
3 8

13 14
2
0

4

2
0

5

4
4

5 4

5
4

5 5

2
9 4

5

15
2
3

6

16
2
3

7

22

Comparison of vector clocks


We write

a1 b1
a b
2 2
a3 b3
if

ai bi

for all

i
23

Examples:

3 9
7 < 7

4 5
1 1
5 = 5

3 3

1 6
0 < 1

0 1

24

Incomparable vector clocks


We write

If
neither

a1 b1
a </ b
2 2
a3 b3

a1 b1
a b
2 2
a3 b3

a1 b1

b
nor
2 2
a3 b3

25

Examples:

3 2
7 </ 8

4 5

1 0
0 </ 1

0 1

26

Vector clocks capture causality

If

1 2

then

VC (1 ) < VC ( 2 )

If

1 2

then

VC (1 ) </ VC ( 2 )
27

By examining the vector clocks


we can determine the order of events

If

VC (1 ) < VC ( 2 ) then 1 2

If

VC (1 ) </ VC ( 2 ) then

1 2
28

p0

1
0

0 1
1
1

0

p1
p3

2
0

0

10 11 12
0
0

1

0
0

2

0
0

3

1 2

3
0

0 3

1
72

3

1
3 8

13 14
2
0

4

2
0

5

4
4

5 4

5
4

5 5

2
9 4

5

15
2
3

6

16
2
3

7

VC (1 ) < VC ( 2 )
29

p0

1
0

0 1
1
1

0

p1
p3

2
0

0

1
72

3

10 11 12
0
0

1

0
0

2

3
0

0 3

0
0

3

VC ( 2 ) < VC (13 )

1
3 8

13 14
2
0

4

2
0

5

4
4

5 4

5
4

5 5

2
9 4

5

15
2
3

6

16
2
3

7

2 13
30

p0

1
0

0 1
1
1

0

p1
p3

2
0

0

10 11 12
0
0

1

0
0

2

1 10

0
0

3

3
0

0 3

1
72

3

1
3 8

13 14
2
0

4

2
0

5

4
4

5 4

5
4

5 5

2
9 4

5

15
2
3

6

16
2
3

7

VC (1 ) </ VC (10 )

31

p0

1
0

0 1
1
1

0

p1
p3

2
0

0

10 11 12
0
0

1

0
0

2

0
0

3

3
0

0 3

1
72

3

1
3 8

13 14
2
0

4

VC (8 ) </ VC (14 )

2
0

5

4
4

5 4

5
4

5 5

2
9 4

5

15
2
3

6

8 14

16
2
3

7

32

Theorem:
For n process, the minimum number
of entries in vector clocks is n
(in order for the vector clocks
to capture causality)

Proof:

Proof by contradiction
33

From

pi

pi 1 pi 2

ai

bi

To

pi +1

pi + 2

pi + 2

pi 2
ai +1 bi
34

pi +1

ai +1

pj

bj
For all

i j

ai +1 b j

35

VC[r ](bi ) < VC[r ](ai +1 )


VC[r ](b j ) < VC[r ](a j +1 )
ai +1 b j

VC[r ](bi ) < VC[r ](a j +1 )


contradiction

36

Cuts

cut

p0
p1
p2

2
6 7

10 11 12

3
8
13 14

9
15

A cut consists from the last event


from each process

16

37

Consistent cuts

p0
p1
p2

2
6 7

10 11 12

3
8
13 14

9
15

16

messages can cross from left of the cut


to right of the cut only

38

Inconsistent cuts

p0
p1
p3

2
6 7

10 11 12

3
8
13 14

9
15

messages cross from right of the cut


to left of the cut

16

39

Consistent
cut

p0
p1
p3

Inconsistent
cut

2
6 7

10 11 12

3
8
13 14

9
15

16

For every inconsistent cut there is


a most recent consistent cut: maximal cut
40

You might also like