390 likes | 624 Views
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
E N D
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 • Recycling counter • Conclusion
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 • Giventwoconcurrent objects Xand Y • Q: Does there exist a wait-free implementation of X by Y? • FLP and Herlihy’s papers answered this question
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
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
Consensus Number • Consensus Number for an object X is the largestn for which X solves consensus problem for n processes • If no largest n exists, then the consensus number is said to be infinite
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
Consensus Number 1 R/W registers 2 Test&set, swap, fetch&add, queue, stack 2n - 2 n-register assignment Infinity Memory-to-memory move and swap, augmented queue, compare&swap, fetch&cons, sticky byte Impossibility and Universality Hierarchy Object
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
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
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
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 0 ┴ 1 ┴ Initially
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
FIFO Queue has n = 2 (cont.) • Case 1: P and Q deq(A) A A C: bi-valent 1 1 Q deq(A) P deq(A) 2 2 3 3 x-valent y-valent T S P deq(A) Q deq(A) T' v S' v R S'~T'
FIFO Queue has n = 2 (cont.) • Case 2: P enq(A, p) and Q deq(A) A Non-Empty Queue A C: bi-valent 1 1 Q deq(A) P enq(A, p) 2 2 3 3 y-valent T x-valent S P enq(A, p) Q deq(A) p T' p S' R S'~T'
FIFO Queue has n = 2 (cont.) • Case 2: P enq(A, p) and Q deq(A) A Empty Queue A C bi-valent Q deq(A) p p P enq(A, p) y-valent T x-valent S P enq(A, p) T' R S~T’
FIFO Queue has n = 2 (cont.) • Case 3: P and Q enq() A A C: bi-valent P enq(A, p) Q enq(A, q) 1 1 2 2 x-valent y-valent S T Q enq(A, q) P enq(A, p) S' T' p P-only until it deq q P-only until it deq p q q p P’s P’s T’’ S’’ Q’s Q-only until it deq q Q-only until it deq p Q’s R S’’’~T’’’ S’’’ T’’’
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
Augmented Queue has n = infinity decide(input: value) enq(A, input) Return peek(q) end decide
Universality • An object is UNIVERSAL if it implements any other object • Example: Object R implements object A Object A Invoke Invoke Pi Front-End Object R Respond Respond
Universality Algorithm: Idea Consensus Object Input: (var, pref_val) Output: decides val to var Input: invoke invoke Universal Algorithm Output: respond respond
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
Universality Algorithm: Idea • When a process P makes an invocation • P creates a node with sequence = 0 and fill in its invocation • P tries to attach its node to the linked list • Attaching the node means performing its invocation • Once the node is attached, it will have a sequence and all of its entries will be filled
Universality Algorithm: Idea • Apply (invoke, state, state, result) • May be non-deterministic • Apply (invoke, state) represents (new_state, result)
Universality Algorithm: Node Seq: integer New: consensus object After: consensus object Inv: INVOKE state New result Before: * cell After: * cell
Universality Algorithm: Linked-List Anchor before before before Seq = 1 Seq = 2 Seq = 3 Seq = 4 Inv2 Inv3 Inv4 State: S1 State: S2 State: S3 State: S4 Res: R2 Res: R3 Res: R4 after after after before after Example: Apply(Inv2, S1) (S2, R2) Similarly: Apply(Inv3, S2) (S3, R3) ……etc.
P4 P1 P2 P3 P0 Universality Algorithm decide(var, val) Assigns a val to var Head Announce 0 1 2 3 4 0 1 2 3 4 Anchor Seq = 1 State: S1 Initially before after NULL NULL
P4 P1 P2 P3 P0 Universality Algorithm decide(var, val) Assigns a val to var Head Announce 0 1 2 3 4 0 1 2 3 4 3 Anchor 3 Seq = 1 0 Inv State: S1 3 before after NULL NULL
P4 P1 P2 P3 P0 Universality Algorithm decide(var, val) Assigns a val to var Head Announce 0 1 2 3 4 0 1 2 3 4 (S1, Inv) (S2, R2) Anchor Seq = 1 0 Seq = 2 Inv before State: S1 State: S2 Res: R2 before after after NULL NULL
P4 P1 P2 P3 P0 Universality Algorithm Decide(var, val) Assignes a val to var Head Announce 0 1 2 3 4 0 1 2 3 4 Anchor Seq = 1 Seq = 2 before Inv State: S1 State: S2 Res: R2 before after after NULL NULL
P4 P1 P2 P3 P0 Universality Algorithm decide(var, val) Assigns a val to var Head Announce 0 1 2 3 4 S2, Inv1 0 1 2 3 4 1 S2, Inv1 3 S2, Inv1 1 1 S3, R3 Anchor 1 S3, R3 Seq = 1 0 0 0 Seq = 2 Inv1 Inv3 before Inv4 1 Inv State: S1 State: S2 Res: R2 1 before S3, R3 after after NULL NULL
P4 P1 P2 P3 P0 Universality Algorithm decide(var, val) Assigns a val to var Head Announce 0 1 2 3 4 0 1 2 3 4 Anchor Seq = 1 0 0 Seq = 2 Seq = 3 Inv3 before Inv4 before Inv Inv1 State: S1 State: S2 State: S3 Res: R2 Res: R3 before after after NULL NULL
Universality Algorithm: Why Help • Beyond being nice • With help wait-free • Without help non-blocking
Universal Algorithm 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) elseprefer (my_cell) send my prefer to decide send my apply preference to decide fill fields of the attached cell return my new RESULT universal(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) enduniversal
Impossibility/Universality: Importance • Research done before was focusingonconstructing complex objects from atomic R/W registers • Atomic registers have few applicationsin 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
Research Turning Points • Pay attention to other primitives: stronger than R/W registers • Give up wait-free • Use randomized wait-free
Conclusion • Deterministic Wait-Free Consensus • Impossibility and universality Hierarchy • Universality algorithm
References • M. Herlihy. Wait-Free Synchronization. ACM Transactions on Programming Languages and Systems, 13(1): 124-149. January 1991.