39
Wait-Free Consensus Wait-Free Consensus CPSC 661 Fall 2003 Supervised by: Lisa Higham Presented by: Wei Wei Zheng Nuha Kamaluddeen

Wait-Free Consensus

  • Upload
    elaina

  • View
    53

  • Download
    0

Embed Size (px)

DESCRIPTION

Wait-Free Consensus. CPSC 661 Fall 2003 Supervised by: Lisa Higham Presented by: Wei Wei Zheng Nuha Kamaluddeen. Outline. Deterministic Wait-Free Impossibility Universality Randomized Wait-Free Robust weak shared coin Multi Consensus Game Use randomizes solution - PowerPoint PPT Presentation

Citation preview

Page 1: Wait-Free Consensus

Wait-Free ConsensusWait-Free Consensus

CPSC 661 Fall 2003

Supervised by: Lisa HighamPresented by: Wei Wei Zheng

Nuha Kamaluddeen

Page 2: Wait-Free Consensus

Outline

● Deterministic Wait-Free– Impossibility– Universality

● Randomized Wait-Free– Robust weak shared coin

● Multi Consensus Game– Use randomizes solution– Recycling counter

● Conclusion

Page 3: Wait-Free Consensus

Deterministic Wait-Free

● Wait-Free Implementation is the one which guarantees that any process can complete any operation in a finite number of steps of that process

● Given two concurrent objects X and Y

● Q: Does there exist a wait-free implementation of X by Y?

● FLP and Herlihy’s papers answered this question

Page 4: Wait-Free Consensus

Consensus Problem

● A system of n processes that communicate through m shared objects

– Each process starts with an input value from domain D

– Communicates with one another by applying operations to the shared objects

– Eventually agree on a common input value and halt

Page 5: Wait-Free Consensus

Consensus Problem

● Requirements:

– Agreement: all processes decide on one common value if they do decide

– Validity: the common decision value is the input of some process

– Wait-Freedom: each process decides after a finite number of steps

Page 6: Wait-Free Consensus

Consensus Number

● Consensus Number for an object X is the largest n for which X solves consensus problem for n processes

● If no largest n exists, then the consensus number is said to be infinite

Page 7: Wait-Free Consensus

FLP vs. Herlihy

● FLP answered the question for a specific object, i.e., R/W register.

● FLP provided a stronger result for this special case: no implementation of consensus problem of n>=2 processes using R/W registers, even for at most 1 stopping faulty process, and even for binary inputs

● Herlihy gave a more generalized answer: Impossibility and Universality Hierarchy for wait-free implementation of any type of object

Page 8: Wait-Free Consensus

Impossibility and Universality Hierarchy

Memory-to-memory move and swap, augmented queue, compare&swap, fetch&cons, sticky byte

Infinity

n-register assignment2n - 2

Test&set, swap, fetch&add, queue, stack2

R/W registers1

Consensus Number

Object

Page 9: Wait-Free Consensus

Impossibility and Universality

● Impossibility– It is impossible to construct a wait-free

implementation of an object with consensus number n from any number of objects with a strictly smaller consensus number

Page 10: Wait-Free Consensus

Impossibility and Universality

●Universality: an object is universal in a system of n (or fewer) processes if it can implement any object of consensus number n

●The n-consensus object is universal in a system of n (or fewer) processes

Page 11: Wait-Free Consensus

FIFO Queue

● Supports two operations:– enq(queue, val): appends a new element to the end

of queue with the value val

– deq(queue): reads and removes the first element of queue

Page 12: Wait-Free Consensus

FIFO Queue has n >= 2

P:

decide(input: value) returns(value)

prefer[P] := input

if deq(A) = 0

then return prefer[P]

else return prefer[Q]

endif

end decide

Prefer

A

1

0

Initially

Page 13: Wait-Free Consensus

FIFO Queue has n = 2

● Impossible for n > 2● Proof:

– Initially:● Three processes P, Q and R● Each about to make decision step● P's operation x-valent● Q's operation y-valent

– Cover all possible combinations of operations

Page 14: Wait-Free Consensus

FIFO Queue has n = 2 (cont.)

● Case 1: P and Q deq(A)

1

v

2

C: bi-valent

T'

T

S'

S

S' ~ T'R

Q deq(A)P deq(A)

Q deq(A) P deq(A)

3

A1

v

23

A

x-valent y-valent

Page 15: Wait-Free Consensus

FIFO Queue has n = 2 (cont.)

● Case 2: P enq(A, p) and Q deq(A)Non-Empty Queue

C: bi-valent

T'S'

S

Q deq(A)P enq(A, p)

Q deq(A) P enq(A, p)

T

S' ~ T'R

1

p

23

A1

p

23

A

x-valenty-valent

Page 16: Wait-Free Consensus

FIFO Queue has n = 2 (cont.)

● Case 2: P enq(A, p) and Q deq(A)Empty Queue

C bi-valent

S

P enq(A, p)

T

S ~ T’R

p

A

p

A

T'

Q deq(A)

P enq(A, p)x-valent y-valent

Page 17: Wait-Free Consensus

FIFO Queue has n = 2 (cont.)

● Case 3: P and Q enq()

12

Q’s

P’s

pq

12

Q’s

P’s

qp

C: bi-valent

T'S'

S

Q enq(A, q)P enq(A, p)

Q enq(A, q) P enq(A, p)T

S’’’ ~ T’’’R

x-valent y-valent

P-only until it deq p

Q-only until it deq q

S’’’

S’’

T’’’

T’’

P-only until it deq q

Q-only until it deq p

A A

Page 18: Wait-Free Consensus

Augmented Queue

● Add one more operation to the FIFO queue:– Peek(): returns but does not remove the first item in

the queue

● See how the queue becomes POWERFULL

Page 19: Wait-Free Consensus

Augmented Queue has n = infinity

decide(input: value)

enq(A, input)

Return peek(q)

end decide

Page 20: Wait-Free Consensus

Universality

● An object is UNIVERSAL if it implements any other object

● Example: Object R implements object A

Front-End Object RPi

Object A

Invoke

RespondRespond

Invoke

Page 21: Wait-Free Consensus

Universality Algorithm: Idea

Input: invoke

Output: respond

Consensus ObjectInput: (var, pref_val)

Output: decides val to var

Universal Algorithm

invoke

respond

Page 22: Wait-Free Consensus

Universality Algorithm: Idea

● A linked list to represent the object● Each cell represents an invocation● Sequence of cells represent the sequence of

applied operations● Sequence: unbounded integer size

Page 23: Wait-Free Consensus

Universality Algorithm: Idea

● When a process P makes an invocation

1. P creates a node with sequence = 0 and fill in its invocation

2. P tries to attach its node to the linked list

3. Attaching the node means performing its invocation

4. Once the node is attached, it will have a sequence and all of its entries will be filled

Page 24: Wait-Free Consensus

Universality Algorithm: Idea

● Apply (invoke, state, state, result)– May be non-deterministic– Apply (invoke, state) represents (new_state, result)

Page 25: Wait-Free Consensus

Universality Algorithm: Node

Seq: integer

Inv: INVOKE

Before: * cell

After: * cell

New

state

result

New: consensus objectAfter: consensus object

Page 26: Wait-Free Consensus

Universality Algorithm: Linked-List

Seq = 1

State: S1

Seq = 2

Inv2

State: S2

Res: R2

Seq = 3

State: S3

Seq = 4

Inv4

State: S4

Res: R4

Inv3

Res: R3

Anchor

before before before

before

after after after

afterExample: Apply(Inv2, S1) (S2, R2)

Similarly: Apply(Inv3, S2) (S3, R3)

……etc.

Page 27: Wait-Free Consensus

Universality Algorithm

P0

Anchor

P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

Initially

decide(var, val)Assigns a val

to var

before after

NULL NULL

Page 28: Wait-Free Consensus

Universality Algorithm

P0Anchor P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

before after

NULL NULL

0Inv

decide(var, val)Assigns a val

to var

3

3

3

Page 29: Wait-Free Consensus

Universality Algorithm

P0Anchor P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

before

afterNULL

decide(var, val)Assigns a val

to var

before

(S1, Inv)(S2, R2)

0

Inv

after

NULL

State: S2

Res: R2

Seq = 2

Page 30: Wait-Free Consensus

Universality Algorithm

P0Anchor P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

beforeafter

NULL

Decide(var, val)Assignes a val

to var

Seq = 2

Inv

State: S2

Res: R2

before

after

NULL

Page 31: Wait-Free Consensus

Universality Algorithm

P0Anchor P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

beforeafter

NULL

decide(var, val)Assigns a val

to var

Seq = 2

Inv

State: S2

Res: R2

before

0Inv3

0Inv1

0Inv4

11 3

after

NULL

1

1

1

1

S2, Inv1S2, Inv1

S2, Inv1

S3, R3

S3, R3

S3, R3

Page 32: Wait-Free Consensus

Universality Algorithm

P0Anchor P4P3P2P1

Announce Head

0 1 2 3 4 0 1 2 3 4

Seq = 1

State: S1

beforeafter

NULL

decide(var, val)Assigns a val

to var

Seq = 2

Inv

State: S2

Res: R2

before

0Inv3

0Inv4Seq = 3

Inv1

State: S3

Res: R3

NULL

after

before

Page 33: Wait-Free Consensus

Universality Algorithm: Why Help

● Beyond being nice

● With help wait-free

● Without help non-blocking

Page 34: Wait-Free Consensus

Universal Algorithmuniversal(what: INVOC) returns(RESULT)

my_cell: cell := [seq:0,

inv: what

new: create(consensus_object)

before: create(consensus_object)

after: null]

announce[P] := my_cell

for each process Q do

head[P] := max(head[P], head[Q])

while (announce[P].seq = 0])

c: *cell := head[P]

help: *cell := announce[(c.seq mod n) + 1]

if help.seq = 0

then prefer := help

else prefer := announce[P]

d := decide(c.after, prefer)

decide(d.new, apply(d.inv, c.new.state))

d.before := c

d.seq := c.seq + 1

head[P] := d

head[P] := announce[P]

return (announce[P].new.result)

end universal

create my_cell (use INV = INVOKE)

Announce my_cell

While my_cell is not attached to the linked-list

Consult head to point to some process: help, and see if it needs help if yes prefer (help) else prefer (my_cell)

send my prefer to decide send my apply preference to decide

fill fields of the attached cell

return my new RESULT

Page 35: Wait-Free Consensus

Impossibility/Universality: Importance

● Research done before was focusing on constructing complex objects from atomic R/W registers

● Atomic registers have few applications in constructing wait-free implementation of more complex data structure– Examples:

●Sets, queues, stacks, priority queues, lists

●Classical synchronization primitives: test&set, compare&swap, fetch&add

●Simple memory-to-memory operation: move and swap

Page 36: Wait-Free Consensus

Research Turning Points

● Pay attention to other primitives: stronger than R/W registers

● Give up wait-free● Use randomized wait-free

Page 37: Wait-Free Consensus

Conclusion● Deterministic Wait-Free Consensus

– Impossibility and universality Hierarchy– Universality algorithm

Page 38: Wait-Free Consensus

References

M. Herlihy. Wait-Free Synchronization. ACM Transactions on Programming Languages and Systems, 13(1): 124-149. January 1991.

Page 39: Wait-Free Consensus

Questions?