1 consensus hierarchy part 2. 2 fifo (queue) fifo object headtail

54
1 Consensus Hierarchy Part 2

Upload: eustacia-pope

Post on 17-Jan-2016

243 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

1

Consensus HierarchyPart 2

Page 2: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

2

FIFO (Queue)

FIFO Object

),( xQenq

Q

headtail

x

a

aQdeq )( x

b

ac b

c

bc

Page 3: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

3

Special case: empty queue

)(Qdeq

tail head

Page 4: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

4

Theorem: A FIFO object has consensusnumber 2

Proof:1. We can solve wait-free consensus using FIFO (and read/write) objects for 2 processes

2. We cannot solve wait-free consensus using FIFO (and read/write) variables for 3 or more processes

Page 5: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

5

A Wait-Free Consensus algorithmfor 2 processors using a FIFO object(and read/write objects)

Initially:

tail head

0

Proof-Part 1

Page 6: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

6

Shared Memory

Queue

Other Variables

0tail

head

Page 7: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

7

0x 1x0p 1p

Local variables

}1,0{, ii yx

:initial values for the consensus problem

0y 1y

ix

iy:resulting values for the consensus problem

Page 8: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

8

Shared Memory

Queue

Other Variables

0tail

head

1x

0xPrefer[0]Prefer[1]

Initial values

Page 9: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

9

Code for processor ip }1,0{i

If then else

0)( Qdeq

ii xy ]1[ ipreferyi

//am I the first?

//yes, choose my value

//no, choose the other processor’s value

Note: the algorithm uses a FIFO object and read/write objects

ixiprefer ][

Page 10: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

10

Example execution:

Shared Memory

Queue0tail

head

01 x

10 xPrefer[0]Prefer[1]

10 x

01 x

0p

1p

0y

1y

Page 11: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

11

Suppose that accesses first the queue

Shared Memory

Queuetail

head

01 x

10 xPrefer[0]Prefer[1]

10 x

01 x

0p

1p

0y

01 y

1p

)(0 Qdeq

decides on its own value

Page 12: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

12

Suppose that accesses second

Shared Memory

Queuetail

head

01 x

10 xPrefer[0]Prefer[1]

10 x

01 x

0p

1p

00 y

01 y

2p

decides on the other processor’s value

)(Qdeq

Consensus Reached

Page 13: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

13

There is no wait-free consensusalgorithm using only FIFO(and read-write) objects for 3n

Consider three processors(the same proof generalizes to more)

Proof-Part 2

We will prove:

Page 14: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

14

There is a bivalent initial configuration(we proved it before)

We will show that every bivalent configurationhas a processor which is not critical

Therefore, we can construct an infiniteexecution with bivalent configurations whereconsensus is never reached

Page 15: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

15

Assume for contradiction that all processors are critical

C

0C

1C

1nC

bivalent0p

1p

2p

univalent

univalent

univalent

Possibleexecutions

Page 16: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

16

bivalent

valent

It cannot be that all have the same valence

v

)1 or 0( v

valentv

valentv

valentv

Contradiction

C

0C

1C

2C

0p

1p

2p

Page 17: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

17

There must exist two processors with different valences

valent-0

valent-1C

0C

1C

2C

bivalent0p

1p

2p

univalent

Page 18: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

18

Shared Memory

1QQueue

2QQueue

zQQueue

Read/WriteObjects

Page 19: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

19

Shared Memory

1QQueue

2QQueue

zQQueue

Read/WriteObjects

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2p

Case: the processors access different objects

0p

1p

Note: if an object was read/write the analysis is the similar

univalent

Page 20: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

20

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2p

op Q

1

op Q2

op Q2

op Q1

C

C

1p

0p

valent-0

valent-1

CCp

2

Impossible since

Two possible executions

univalent

Page 21: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

21

Shared Memory

1QQueue

QQueue

zQQueue

Read/WriteObjects

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2p

Case: the processors access same object

0p

1p

Note: if the object was read/write the analysisis the same as in the case with read/write objects

univalent

Page 22: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

22

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

deq(

Q)

deq(Q)

Subcase: deq/deq

Page 23: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

23

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

deq(

Q)

deq(Q)

deq(Q)

deq(Q)

C

C

1p

0p

valent-0

valent-1

CCp

2

Impossible since

Queue Q before operations: bc

a b

a d

a b

Page 24: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

24

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

deq(

Q)

enq(Q,x)

Subcase: deq/enq

Page 25: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

25

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

deq(

Q)

enq(Q,x)

enq(Q,x)

deq(Q)

C

C

1p

0p

valent-0

valent-1

CCp

2

Impossible since

Suppose Q was not empty a bc

a bx

a bx

Page 26: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

26

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

deq(

Q)

enq(Q,x)

enq(Q,x)C 1pvalent-0

1

2

CCp

Impossible since

Suppose Q was empty

x

x

Page 27: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

27

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

enq(

Q,a)

enq(Q,b)

Subcase: enq/enq

Page 28: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

28

valent-0

valent-1

C

0C

1C

2C

bivalent0p

1p

2punivalent

enq(

Q,a)

enq(Q,b)

enq(Q,b)

enq(Q,a)

C

C

1p

0p

valent-0

valent-1

Suppose Q was not empty yx

yx

yx

a

a

b

b

Page 29: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

29

valent-1

C 1C

2C

bivalent

0p

1p

2punivalent

enq(

Q,a

)

enq(Q,b) enq(Q,a)C 0p

valent-1

valent-0

0C enq(Q,b)C 1p

yxab b

0p

z w t w

1p0D

yxab z w t w

0p 1p1D

a

valent-0

Dequeue a Dequeue b

Dequeue b Dequeue a

Impossible since

10

2

DDp

Page 30: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

30

C

bivalent

0p

enq(

Q,a

)

valent-0

0C enq(Q,b)C 1p

yxab b

0p

a

0 decidesvalent-0

Suppose does not dequeue a

0

A decision will be reached since the consensus algorithm is wait-free

0p

Explanation

0p

Page 31: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

31

valent-1

C 1Cbivalent

0p

1p

enq(

Q,a

)

enq(Q,b) enq(Q,a)C 0p

valent-0

0C enq(Q,b)C 1p

yxab

0p

yxab

0p

0

0

valent-0

valent-1

The same value will be decided by ,since sees the same shared memory values in both executions

0p

decides 00p

decides 00p

contradiction

0

ba

ba

0p

Page 32: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

32

In all cases we obtained contradiction;Therefore, there exists a processorwhich is not critical

C

0C

1C

1nC

bivalent0p

1p

1np

univalent

univalent

univalent

kC bivalent(not critical)

Page 33: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

33

Therefore, we can construct an execution

0C 1C 2C

Initialconfiguration

0ip

1ip

2ip Never

ends

bivalent bivalent bivalent

Consensus can never be reached

End of Theorem Proof

Page 34: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

34

Compare&Swap

Compare&Swap(X,A,B) { Temp X;

If X==A then X B;Return Temp; }

Shared Memory

X

Page 35: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

35

Theorem: The consensus number ofthe Compare&Swap object is

Proof:

Given processes, for any , we can solve wait-free consensus using a Compare&Swap object(and read/write objects)

n n

Page 36: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

36

A Wait-Free Consensus algorithm for n processors using a compare&swap object

Shared Memory

1nx

0x

1np

0p

1ny

0y

First

Local Memory

(compare&swap object)

Initial value

Final value

Page 37: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

37

Code for processor ip }1,0{i

If then else

),,(& ii xFirstSwapComparev

ii xy

ii vy

//am I the first?

//yes, choose my value

Note: the algorithm uses a compare&swap and read/write objects

iv

//no, choose the value of the first process which is stored in First

Page 38: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

38

Shared Memory00 x

0p0y

First

Local Memory

Example execution:

11 x1p

1y

02 x2p

2y

Page 39: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

39

00 x0p

0y

Local Memory

Suppose executes first

11 x1p

1y

02 x2p

2y

2p

Compare&Swap(First, ,0)

Shared Memory

First

Page 40: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

40

00 x0p

0y

Local Memory

Suppose executes first

11 x1p

1y

02 x2p

02 y

2p

0

Shared Memory

First

Realizes it is first, decides on its own value

Page 41: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

41

00 x0p

0y

Local Memory

Suppose executes second

11 x1p

1y

02 x2p

1p

Compare&Swap(First, ,1)

Shared Memory

First0

02 y

Page 42: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

42

00 x0p

0y

Local Memory

11 x1p

01 y

02 x2p

Shared Memory

First0

0

Realizes is not first, decides on value of First

02 y

Suppose executes second 1p

Page 43: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

43

00 x0p

00 y

Local Memory

11 x1p

01 y

02 x2p

Shared Memory

First0

0

Realizes is not first, decides on value of First

02 y

Similarly for 0p Consensus has beenreached

Page 44: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

44

The algorithm is wait-free, since after the completion of the Compare&Swap operation, every processor decides (without consideringwhat the other processors do)

Page 45: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

45

Consensus HierarchyPart 3

Page 46: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

46

Consensus Number

Consensus Number of an object type:

The maximum number of processes for which the object can be used tosolve the wait-free consensus problem(together with read/write objects)

Page 47: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

47

Object Type Consensus Number

Read/Write 1

FIFO 2

Compare&Swap (infinity)

Page 48: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

48

Simulation:Object Type B

Object Type A

Object Type A

Read/Write Object

Object of type A simulates object of Type B

Page 49: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

49

Theorem:Objects of type A with consensus numbercannot simulate another object of type B withconsensus number

n

nm

Proof: Since otherwise, object A wouldhave consensus numberm

End of Proof

Page 50: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

50

Universality

can simulate in a wait-free mannerany other arbitrary object

Universal object:

Page 51: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

51

Objects with consensus number ncan simulate in a wait-free mannerany other arbitrary object of up toprocessors

n

We can show:

Page 52: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

52

new-state

Compare&Swap

inv

responsebefore

new-stateinv

responsebefore

initial

head

anchor

Non-Blocking Simulation

Page 53: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

53

new-state

Consensus Object

inv

responseafter

new-stateinv

responseafter

initial

Head

anchor

Non-Blocking Simulation

seq seq 1

Page 54: 1 Consensus Hierarchy Part 2. 2 FIFO (Queue) FIFO Object headtail

54

new-stateinv

responseafter

Announce

seq

Wait-free Simulation