51
1 Consensus Hierarchy Part 1

1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

Embed Size (px)

Citation preview

Page 1: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

1

Consensus HierarchyPart 1

Page 2: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

2

Consensus in Shared Memory

Consider processors in shared memory:n

10,..., npp

which try to solve the consensus problem

Page 3: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

3

0

1

0

0p

1p

2p

0

1

0

3p

4p

5p

Every process starts with an initial valuestored in local memory (0 or 1)

Shared memory

Local memory

Local memory

Page 4: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

4

0

1

0

0p

1p

2p

0

1

0

3p

4p

5p

communication through shared memory

Page 5: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

5

1

1

1

0p

1p

2p

1

1

1

3p

4p

5p

At the end of execution, every processhas decided the same value (0 or 1)

Page 6: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

6

Validity condition:

If every process starts with the same value, the every process should decide that value

Additional condition:The decided value is one of the initial values

Page 7: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

7

Wait-freedom in asynchronous systems:

A process should be able to finishexecution of an algorithmeven if all other processes fail

Wait-freedom captures:•Asynchronous executions•Crash failures

Page 8: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

8

Object Types

Read/Write

FIFO

Compare&Swap

Test&Set

n-register assignment

Page 9: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

9

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 10: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

10

Object Type Consensus Number

Read/Write 1

FIFO, Test&Set 2

Compare&Swap (infinity)

n-register assignment 2n-2

Page 11: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

11

int compare_and_swap ( int* register, int oldval, int newval) { int old_reg_val = *register; if (old_reg_val == oldval) *register = newval; return old_reg_val;}

int Test-and-Set(boolean lock) { boolean initial = lock; lock = true; return initial;}

(Shared ) boolean lock = false;

function Critical_Section() { while TestAndSet(lock) skip //spin until lock is acquired //Critical-section code - only one process can be in this section at a time begin { … } //end-of critical section – release lock lock = false //release lock when finished with the critical section }

Mutual Exclusion

Page 12: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

12

Simulation:Object Type B

Object Type A

Object Type A

Read/Write Object

Object of type A simulates object of Type B(using auxiliary read/write objects)

Page 13: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

13

Theorem:Objects of Type A with consensus numbercannot simulate in wait-free manner another object of Type B withconsensus number

n

nm

Proof: Since otherwise, object A wouldhave consensus numberm

End of Proof

Page 14: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

14

can simulate in a wait-free mannerany other arbitrary object

Universal object:

Compare&SwapExample:

(infinity consensus number)

Page 15: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

15

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

n

We can show:

Page 16: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

16

Read/Write

Shared Memory

Suppose that the sharedmemory can only be accessedthrough Read or Write operations

Page 17: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

17

Theorem:

Proof of Theorem:

The consensus number of the Read/Write object is 1

Trivially, any consensus algorithm with 1 process using read/write variables is wait-free.

Page 18: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

18

Wait-free consensus cannot besolved using only read/write objectsfor processors 2n

It remains to show:

We will show that any algorithmthat solves wait-free consensus for has an execution that never terminates

Approach:

2n

Page 19: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

19

System configuration:

Is the set of all variables in the system, including local and shared

0

1

0

0p

1p

2p

0

1

0

3p

4p

5p

C

Page 20: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

20

A distributed system execution can be always be viewed as a: sequence of configurations

0C fC1C 2C

Initialconfiguration

Finalconfiguration

0ip

1ip

2ip

Processor action: Read or Write

Page 21: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

21

1

C

D

C D

1 0 1 0 0 0

bivalent

univalentunivalent

bivalent

Valence of system configurations

1-valent0-valent

Consensus value at possible execution paths

consensus reached consensusnot reached

consensus reached

Page 22: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

22

A terminating execution:

0C 1C 2C

Initialconfiguration

0ip

1ip

2ip

Bivalent Bivalent Univalent

fC

Univalent

UnivalentBivalent

Finalconfiguration

Page 23: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

23

To prove the theorem, we will show that there is always an executionwhere every configuration is bivalent

0C 1C 2C

Initialconfiguration

0ip

1ip

2ip

Bivalent Bivalent Bivalent

Never-ending execution

Bivalent

Page 24: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

24

1

1

1

0p

1p

2p

1

0

0

0p

1p

2p

Similar configurations for processor 0p

23

198

76

23

198

76

Same shared variablesLocal variables of others may differ

1C 2C21

0

CCp

Page 25: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

25

21 CCip

Lemma:If there exist univalent configurations

1C and such that2C

then if is -valentthen is -valent too

1C

2Cv

v

Proof of Lemma:

)1 or 0( v

Page 26: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

26

1C

Univalent

Executionwith onlytaking actions

ip

ip

v v v

All possible executionsfrom 1C

final decision for each Possible execution

Page 27: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

27

1C

Univalent

Executionwith onlytaking actions

ip

ip

v v v

2C

Univalent

Executionwith onlytaking actions

ip

ip

x x x

Page 28: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

28

1C

Univalent

Executionwith onlytaking actions

ip

ip

v v v

2C

Univalent

Executionwith onlytaking actions

ip

ip

x vx x

21 CCip

Page 29: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

29

1C

Univalent

Executionwith onlytaking actions

ip

ip

v v v

2C

Univalent

Executionwith onlytaking actions

ip

ip

21 CCip

v v v

End of Lemma Proof

Page 30: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

30

Lemma:There exists a bivalentinitial configuration

Proof of Lemma:

Page 31: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

31

Possible Initial Configurations

Shared Memory

Empty

Local Memory

10p

Initial Configuration1I

11p

1np 1

0

0I

0

0

0

01I

1

1

Page 32: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

32

Possible Initial Configurations

Shared Memory

Empty

Local Memory

10p

11p

1np 1

0

0I

0

0

0

01I

1

1

0-valent 1-valent?

Initial Configuration1I

Page 33: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

33

Possible Initial Configurations

Shared Memory

Empty

Local Memory

10p

11p

1np 1

0

0I

0

0

0

01I

1

1

0-valent 1-valent1-valent?

No, because 010

0

IIp

Initial Configuration1I

Page 34: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

34

Possible Initial Configurations

Shared Memory

Empty

Local Memory

10p

11p

1np 1

0

0I

0

0

0

01I

1

1

0-valent 1-valent0-valent?

No, because 101

1

IIp

Initial Configuration1I

Page 35: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

35

Possible Initial Configurations

Shared Memory

Empty

Local Memory

10p

11p

1np 1

0

0I

0

0

0

01I

1

1

0-valent 1-valentbivalent

End of Lemma Proof

Initial Configuration1I

Page 36: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

36

Critical processor for a configuration:

the configuration is bivalent,and after the processor takes stepthe configuration becomes univalent

C C ipBivalent Univalent

Page 37: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

37

Lemma:If is a bivalent configurationthen, there is at least one processorwhich is not critical

C

Proof of Lemma:

Page 38: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

38

Assume for contradiction that all processors are critical

C

0C

1C

1nC

bivalent0p

1p

1np

univalent

univalent

univalent

Possibleexecutions

Page 39: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

39

C

bivalent0p

1p

1np

valent

It cannot be that all have the same valence

v

)1 or 0( v

valentv

valentv

0C

1C

1nC

Page 40: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

40

C

bivalent0p

1p

1np

valent

It cannot be that all have the same valence

v

)1 or 0( v

valentv

valentv

valentv

Contradiction 0C

1C

1nC

Page 41: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

41

C

bivalent0p

jp

1np

There must exist two processors with different valences

iC

jC

ip

0C

1nC

valent-0

valent-1

Page 42: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

42

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Case 1: suppose that they access different shared variables

Read x

Read y

x

y

ip

jp

Page 43: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

43

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Read x

Read y

two possible executions

C

C

jp

ip

Read y

Read x

valent-0

valent-1

impossible since CC different valence

Page 44: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

44

same result holds for any kind of operation (Read or Write) that the processors apply to x and y

Page 45: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

45

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Case 2: suppose that they access the same shared variable

Read x

Read x

xip

jp

subcase: read/read

Page 46: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

46

two possible executions

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Read x

Read x

C

C

jp

ip

Read x

Read x

valent-0

valent-1

impossible since CC different valence

Page 47: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

47

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Read x

Write x

subcase: read/write

Page 48: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

48

two possible executions

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Read x

Write x

C

C

jp

ip

Write x

Read x

valent-0

valent-1

impossible since j

p

CCj

different valence

Page 49: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

49

subcase: write/write

C

bivalent

jp

iC

jC

ip

valent-0

valent-1

Write x

Write x

C

C

jp

ip

Write x

Write x

valent-0

valent-1

impossible since j

p

CCj

different valence

Page 50: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

50

In all cases we obtained contradictionTherefore, there exists a processorwhich is not critical

C

0C

1C

1nC

bivalent0p

1p

1np

univalent

univalent

univalent

kC bivalent(not critical)

End of Lemma Proof

Page 51: 1 Consensus Hierarchy Part 1. 2 Consensus in Shared Memory Consider processors in shared memory: which try to solve the consensus problem

51

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