+ All Categories
Home > Documents > 1 Causality. 2 The “happens before” relation happens before (causes)

1 Causality. 2 The “happens before” relation happens before (causes)

Date post: 17-Dec-2015
Category:
Upload: norma-johns
View: 218 times
Download: 0 times
Share this document with a friend
130
1 Causality
Transcript

1

Causality

2

The “happens before” relation1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

21 happens before (causes)

1 2

3

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

61

A message is sent from to 1 6

4

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

61 and

76 71

transitivity

5

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

81

810

161

92

6

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

“happens before” is a partial order

101

110

Parallel events: 101

101

7

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

“happens before” is a partial order

813

138

Parallel events: 138

138

8

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

We can move parallel events

The happens before relationdoesn’t change

9

We want to find a mechanism thatcaptures the “happens before” relationship

so that we use causality in various computation problems

10

Logical Clocks

1 2 3 4 50p

1p

1 2 3

1 2

1)( 1 LT 21)()( 12 LTLT

3

4 5

4

6 7 8 9

In each process, the logical clockincreases by 1 with each local event

0

0

11

1 2 30p

1p

1 2

1 2

514

1)4,2max(

1))(),(max()( 723

LTLTLT

3

5

4

4 5 6 7

Logical clocks are piggy-packed on messages

40

0

12

Logical clocks, seem that they capture the happens before relation

ji )()( ji LTLT

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

1 2 3 7 8

2 4 5 6

1 2 3 4 5 6 7

13

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

1 2 3 7 8

2 4 5 6

1 2 3 4 5 6 7

71 )(41)( 71 LTLT

Example:

14

However, logical clocks cannot capture parallelism

)(54)( 813 LTLT

Parallel events

138

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

2p

1 2 3 7 8

2 4 5 6

1 2 3 4 5 6 7

???)( 813

15

We need another mechanism that can capture the parallelism of events

16

Vector Clocks

1 2 3 4 50p

1p6 7 8 9

0

0

0

0

0

1

0

2

0

3

0

4

0

5

1

0

2

0

3

0

4

0

Process entry

Process entry

0p

1p

0

1)( 1VC

17

1 2 3 4 50p

1p6 7 8 9

0

0

0

0

0

1

0

2

0

3

0

4

0

5

1

0

2

0

3

0

4

0

Each process increases its entry at each event

0

3

0

1

0

2

0

1)()( 23 VCVC

increment

18

1 2 3 4 50p

1p6 7 8 9

0

0

0

0

0

1

0

2

0

3

0

4

0

5

1

0

2

0

3

0

4

0

Each process increases its entry at each event

4

0

1

0

3

0

1

0)()( 89 VCVC

increment

19

1 2 30p

1p4 5 6 7

vector clocks are piggy-packed on messages

0

0

0

0

0

1

0

2

1

0

2

0

3

0

4

0

4

0

4

3

4

2

4

0,

0

2max

The maximum of each entry

20

1 2 30p

1p4 5 6 7

vector clocks are piggy-packed on messages

0

0

0

0

0

1

0

2

1

0

2

0

3

0

4

0

4

0

4

3

4

3

0

1

4

2

0

1

4

0,

0

2max

0

1))(),(max()( 723 VCVCVC

21

30p

1p7

vector clocks are piggy-packed on messages

4

0

4

0

4

3

6

4

1

0

5

4

1

0

4

4,

5

0max

1

0))(),(max()( 1089 VCVCVC

4

4

5

0

6

4

4

4

8 9

10

22

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

3p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

23

Comparison of vector clocks

3

2

1

3

2

1

b

b

b

a

a

a

if for all

We write

ii ba i

24

5

7

9

4

7

3

Examples:

1

1

6

0

0

1

3

5

1

3

5

1

25

Incomparable vector clocks

3

2

1

3

2

1

b

b

b

a

a

aWe write

3

2

1

3

2

1

b

b

b

a

a

a

3

2

1

3

2

1

b

b

b

a

a

aIf neither nor

26

5

8

2

4

7

3

Examples:

1

1

0

0

0

1

27

Vector clocks capture causality

If then 21 )()( 21 VCVC

If then 21 )()( 21 VCVC

28

If then 21 )()( 21 VCVC

If then 21 )()( 21 VCVC

By examining the vector clockswe can determine the order of events

29

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

3p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 )()( 21 VCVC

30

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

3p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

132 )()( 132 VCVC

31

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

3p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

101 )()( 101 VCVC

32

1 2 3

6 7 8 9

10 11 12 13 14 15 16

4 50p

1p

3p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

148 )()( 148 VCVC

33

Cuts

34

0p

1p

2p

21 3 4 5

1 2 3 4

21 3 4 5 6 7

35

0p

1p

2p

consists from an event from each process

Cut:

3

2

1

21 3 4 5

1 2 3 4

21 3 4 5 6 7

36

0p

1p

2p

no messages cross the cutConsistent cut:

21 3 4 5

1 2 3 4

21 3 4 5 6 7

3

2

1

37

0p

1p

2p

messages can crossfrom left to right of the cut

Consistent cut:

21 3 4 5

1 2 3 4

21 3 4 5 6 7

5

3

2

38

0p

1p

messages cross from right to left of the cut

Inconsistent cut:

21 3 4 5

1 2 3 4

21 3 4 5 6 7

4

2

1

2p

39

0p

1p

21 3 4 5

1 2 3 4

21 3 4 5 6 7

5

3

4

messages cross from right to left of the cut

Inconsistent cut:

2p

40

A consistent cut such that

Maximal Consistent Cut

Maximal Consistent Cut of :

Consider some (inconsistent) cut r

r

s rs

and contains most recent events s

41

0p

1p

(inconsistent cut)

21 3 4 5

1 2 3 4

21 3 4 5 6 7

4

2

1

r

2p

42

0p

1p

maximal consistent cuts

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

(inconsistent cut)

4

2

1

3

2

1

2p

43

Theorem: For every cut ,there is a unique maximal consistent cut

Proof: Proof by contradiction

r

44

Assume for contradiction there are two(or more) maximal cuts of r

1s 2s

maximal consistent cuts

r

45

1s 2snot maximal!

It cannot be that and don’t cross 1s 2s

r

46

r1s 2s

and cross 1s 2s

47

r1s 2s

and cross 1s 2s

snew cut

48

r1s 2s

and cross 1s 2s

s

impossible

is consistent1ssince

49

r1s 2s

and cross 1s 2s

s

impossible

is consistent2ssince

50

r1s 2s

and cross 1s 2s

s is consistentnot maximal! not maximal!

Contradiction!

End of proof

51

A distributed algorithm for computing the maximum consistent cut of :

•Use vector clocks

•For each processor: Find most recent event with vector clock

r

rv

52

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 72p

53

0p

1p

2p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

54

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

6

2

2

0

0

2

OK

:0p

2p

55

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

6

2

2

3

2

1

OK

:1p

OK

2p

56

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

6

2

2

6

3

2

OK

:2p

OK

2p

57

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

6

2

2

5

0

2

OK

:2p

OK

2pOK

58

0p

1p

0

0

1

0

0

2

0

0

3

5

4

4

5

4

5

0

1

1

3

2

1

3

3

1

5

4

2

1

0

0

2

0

0

3

0

0

4

0

2

5

0

2

6

3

2

7

3

2

21 3 4 5

1 2 3 4

21 3 4 5 6 7

r

6

2

2

2p

s

5

2

2

59

Distributed Snapshot

•A set of processors initiate the computation for obtaining a global snapshot

S

•The cut contains the state of at least one processor in in the initiation S

(these processors receive special marker messages from the system)

60

A Distributed Snapshot Algorithm

•Upon receiving a marker message:

Processor : 0inum nilansi ip

•Count local events in inum

If thennilansi set nilansi

send marker to all neighbors

61

0p

1p

2p

21 3 4 5

1 2 3 4

21 3 4 5 6 7

inum

62

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

63

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m

64

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m

65

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m mm

m

mm

66

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m mm

m

mm

67

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m mm

m

mm

m

68

0p

2p

1p

3p

}{ 0pS

0p

1p

2p

3p

m

m

m mm

m

mm

m

cut

69

Theorem:The cut obtained by the algorithmis consistent

Proof: By contradiction

70

Suppose the cut is incosistent

71

It must be:

m

Impossible!

End of proof

(we assume FIFO)

Spring 2003 Costas Busch 72

FIFO-Broadcast

Spring 2003 Costas Busch 73

0p

1p

2p

1m 2mFIFO Order

Messages from are received in the order they are sent from

ip

ip

3p

Spring 2003 Costas Busch 74

Not FIFO-order

0p

1p

2p

1m 2m

3p

Spring 2003 Costas Busch 75

0p

1p

2p

1m 2m

3p

3m 4m

Messages from differentprocessors may be received indifferent order

FIFO order

Spring 2003 Costas Busch 76

Not FIFO-order

0p

1p

2p

1m 2m

3p

3m 4m

Spring 2003 Costas Busch 77

Why is FIFO important?

Deposit$1000

ATM

BankAccount

Withdraw$500

$0 $1000 $500

FIFO order

Spring 2003 Costas Busch 78

Why is FIFO important?

Deposit$1000

ATM

BankAccount

Withdraw$500

$0 $500-$500

Not FIFO order Not an allowedtransaction

Spring 2003 Costas Busch 79

0p

1p

2p

3p

2

A processor increments a counterwhen it broadcasts

1

11 22

1 2

A simple FIFO algorithm

1m 2m1 2

Spring 2003 Costas Busch 80

A processor keeps track of the highest valuesreceived from other processors

00

pV 10

pV 20

pV

0p

1p

2p

3p

21

11 22

1 21m 2m1 2

Spring 2003 Costas Busch 81

00

pV

Wait until all messages with smaller values from the same sender are received

wait ok

0p

1p

2p

3p

21

1 1 22

1 21m 2m1 2

Spring 2003 Costas Busch 82

00

pV

receive

10

pV 20

pV

0p

1p

2p

3p

21

1 1 22

1 21m 2m1 2

2

Spring 2003 Costas Busch 83

Totally Ordered - Broadcast

Spring 2003 Costas Busch 84

0p

1p

2p

1m

2m

Total Order

Messages are received in the same order in every processor

3p

Spring 2003 Costas Busch 85

0p

1p

2p

1m

2m

3p

Not Total Order

Spring 2003 Costas Busch 86

0p

1p

2p

1m

2m

3p

Total Order

Spring 2003 Costas Busch 87

0p

1p

2p

1m

2m

3p

Not Total Order

Spring 2003 Costas Busch 88

0p

1p

2p

3p

An Asymmetric Algorithm

1

Request a counter value

counter

Spring 2003 Costas Busch 89

0p

1p

2p

3p

1

1

counter

Receive a counter value

Spring 2003 Costas Busch 90

0p

1p

2p

3p

1

1

counter

Broadcast

1

1

1

1

Spring 2003 Costas Busch 91

0p

1p

2p

3p

1

1

counter

1

1

1

1

22 2

2

2

2

Spring 2003 Costas Busch 92

0p

1p

2p

3p

2

With the counter,broadcast messages are totally ordered

1

wait ok

2

1

Spring 2003 Costas Busch 93

0p

1p

2p

3p

2

With the counter,broadcast messages are totally ordered

1

wait ok

received

2

2

1

2

Spring 2003 Costas Busch 94

A Symmetric Algorithm

Builds on top of FIFO

It is a form of Vector Clocks

Spring 2003 Costas Busch 95

Every process has a counter

On broadcast: the process sends the counter value to every boby

Spring 2003 Costas Busch 96

On reception of a message:

If received counter value is higher than local value, then:

•Update local counter to new value

•Broadcast new counter value to everybody else

Spring 2003 Costas Busch 97

2p

1p

0p

0

0

0

0

0

0

0

0

0

Spring 2003 Costas Busch 98

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

1

1

Spring 2003 Costas Busch 99

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

1

0

0

1

Spring 2003 Costas Busch 100

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

1

1

1

1

0

1

1

0

1

1

0

1

1

0

0

1

Special broadcast message

Spring 2003 Costas Busch 101

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

1

1

1

1

0

1

1

0

1

1

0

1

1

0

0

1

1

1

1

1

1

1

1

1

1

1

1

1

Spring 2003 Costas Busch 102

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

1

1

1

1

0

1

1

0

1

1

0

1

1

0

0

1

1

1

1

1

1

1

1

1

1

1

1

1

Actual reception of normal broadcast message

Spring 2003 Costas Busch 103

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

1

1

1

1

0

1

1

0

1

1

0

1

1

0

0

1

1

1

1

1

1

1

1

1

1

1

1

1

1

2

1 2

2

2

Another normal broadcast

Spring 2003 Costas Busch 104

2

1

0

a

a

a

Local vector of :

receive a normal broadcast message if message’s counter is smaller or equal than each ja

ip

ip

Spring 2003 Costas Busch 105

2p

1p

0p

0

0

0

0

0

0

0

0

0

Spring 2003 Costas Busch 106

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

1

1

1

1

1 1

Spring 2003 Costas Busch 107

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

1

1

1

1

1 1

1

1

1

1

0

1

1

0

1

Spring 2003 Costas Busch 108

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

1

1

1

1

1 1

1

1

1

1

0

1

1

0

1

1

1

1

1

1

1

1

1

1

1

1

1

Spring 2003 Costas Busch 109

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

1

1

1

1

1 1

1

1

1

1

0

1

1

0

1

1

1

1

1

1

1

1

1

1

1

1

1

Spring 2003 Costas Busch 110

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

1

1

1

111

1

1

1

1

0

1

1

0

1

1

1

1

1

1

1

1

1

1

1

1

1

Symmetry is broken with node ids

Spring 2003 Costas Busch 111

Casually Ordered - Broadcast

Spring 2003 Costas Busch 112

0p

1p

2p

1m

2m

Casual Order

Messages are received in the order they are caused

3p

Spring 2003 Costas Busch 113

0p

1p

2p

1m

2m

3p

Not causal order

Spring 2003 Costas Busch 114

0p

1p

2p1m

2m

3p

Casual order

Spring 2003 Costas Busch 115

0p

1p

2p1m

2m

3p

Not casual order

Spring 2003 Costas Busch 116

The Total Order algorithmswe described are also Casual Order algorithms

Observation:

There is a more efficient algorithmin terms of message complexity

Spring 2003 Costas Busch 117

2p

1p

0p

0

0

0

0

0

0

0

0

0

Spring 2003 Costas Busch 118

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

1

0

0

1

0

0

1

0

0

1

0

0

1

0

0

1

0

0

1

0

Spring 2003 Costas Busch 119

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

1

0

0

1

0

0

1

0

0

1

0

0

2

0

0

2

0

0

2

0

Spring 2003 Costas Busch 120

2p

1p

0p

0

0

0

0

0

0

0

0

0

0

1

0

0

1

0

0

1

0

0

1

0

0

2

0

0

2

0

0

2

0

0

2

0

Spring 2003 Costas Busch 121

2p

1p

0p

0

2

0

0

2

0

0

2

0

Spring 2003 Costas Busch 122

2p

1p

0p

0

2

0

0

2

0

0

2

0

0

3

0

0

3

0

0

3

0

0

3

0

Spring 2003 Costas Busch 123

2p

1p

0p

0

2

0

0

2

0

0

2

0

0

3

0

0

3

0

0

3

0

0

3

0

0

3

1

0

3

1

0

3

1

Spring 2003 Costas Busch 124

2p

1p

0p

0

2

0

0

2

0

0

2

0

0

3

0

0

3

0

0

3

0

0

3

0

0

3

1

0

3

1

0

3

1

0

3

1

Spring 2003 Costas Busch 125

Processor officially receives a message from with vector clock

ip

2

1

0

v

v

v

1) All messages from smaller or equal to arrive

2) All messages from smaller than arrive

kv

jp

kp )( jk

jp

jv

When:

Spring 2003 Costas Busch 126

Relationship Between Broadcast Orders

Spring 2003 Costas Busch 127

Casual Order

Casual Order does not imply Total Order

a

b

a b

b a

Spring 2003 Costas Busch 128

Casual Order

Casual Order implies FIFO

a b a b

ba

Spring 2003 Costas Busch 129

Total Order

Total Order does not imply Casual Order nor FIFO

a b ab

b a

Spring 2003 Costas Busch 130

FIFO

FIFO does not imply Casual Order nor Total Order

a ab

ba b


Recommended