Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distributed Algorithms (22903) Lecturer: Danny Hendler The Atomic Snapshot Object The Renaming Problem This presentation is based on the book “Distributed.

Similar presentations


Presentation on theme: "Distributed Algorithms (22903) Lecturer: Danny Hendler The Atomic Snapshot Object The Renaming Problem This presentation is based on the book “Distributed."— Presentation transcript:

1 Distributed Algorithms (22903) Lecturer: Danny Hendler The Atomic Snapshot Object The Renaming Problem This presentation is based on the book “Distributed Computing” by Hagit attiya & Jennifer Welch.

2 2 The Atomic snapshot object Each process has a SWMR register, which we call a segment A process may obtain an ‘atomic snapshot’ of all segments. Atomic Snapshot sequential specification Two operations are supported: 1.Update i (v), by p i, updates p i ’s segment to value v. 2.Scan, returns a vector V, where V is an n-element vector called a view (with a value for each segment). V[i] must return the value of the latest Update i operation (or the initial value if there were none) Scan returns a view of the segments array that existed at some point during the execution

3 3 A trivial (and wrong) algorithm Initially segment[i]=v i Scan i (S) 1.for i=1 to n 2. tmp[i]=Segment[i] 3.return Update i (S, v) 1.Segment[i]=v Why is this algorithm incorrect?

4 4 Atomic snapshot simulation: key algorithmic ideas (Afek, Attiya, Dolev, Gafni, Merritt, Shavit, 1993) A scan collects all segments twice (double collect) If the two collects are identical, they are a legal view What if segments change while being collected? Then we try again and again until some segment undergoes “enough” changes (we can be sure its last update started after our scan) We then use a view embedded in that update (a helping mechanism) Timestamps used to distinguish between different writes of same value

5 5 A wait-free simulation of atomic snapshot Initially segment[i].ts=0, segment[i].data=v i, segment[i].view= Scan i (S) 1.for all j <> i: c[j]=Segment[j] 2.while true do 3. for all j: a[j] = Segment[j] 4. for all j: b[j] = Segment[j] 5. if, for all j, a[j]=b[j] ; Comparison includes timestamp! 6. return ; Direct scan 7. else if, for some j ≠ i, b[j].ts - c[j].ts ≥ 2 8. return b[j].view ; Indirect scan Update i (S, d) 1.view:=scan() 2.Segment[i]=

6 6 Linearization order A direct scan is linearized immediately after the last read of its first collect An indirect scan is linearized at the same point as the direct scan whose view it borrowed. An update is linearized when it writes to its segment.

7 7 A proof that the algorithm for atomic snapshot is wait-free and linearizable

8 8 A space-bounded simulation of atomic snapshot (this algorithm is not shown in class) Instead of the unbounded timestamp, we use a handshaking mechanism between each pair of processes Processes p i, p j interact via two shared SRSW handshaking bits: h i, h j. ; Handshaking procedures for the ordered pair (pi, pj) procedure tryHS i () ; process p i tries to handshake with p j 1.h i := h j procedure tryHS j () ; process p j tries to handshake with p i 1.h j := 1-h i procedure checkHS i () process p j checks whether a handshake occurred 1.return (h i ≠ h j ) procedure checkHS j () process p j checks whether a handshake occurred 1.return (h i = h j )

9 9 Handshaking properties Handshaking property 1 If a checkHS i returns true, then there exists a tryHS j whose write occurs between the read of the previous tryHS i and the read of the checkHS i. Handshaking property 2 If a checkHS i returns false, then there is no tryHS j whose read and write occurs between the write of the previous tryHS i and the read of the checkHS i.

10 10 The bounded-space algorithm Initially segment[i].data=v i, segment[i].view= Local variable shook[j]=0 for all j We add a toggle bit to each data element Scan i (S) 1.for all j <> i shook[j] := 0 2.while true do 3. for all j ≠ i tryHS i (i,j) 4. for all j ≠ i a[j] = Segment[j] 5. for all j ≠ i b[j] = Segment[j] 6.if, for some j ≠ i, checkHS i (i,j) or (a[j].toggle ≠ a[j].toggle) 7. if (shook[j]=2) return b[j].view ; Indirect scan 8. else shook[j]=shook[j]+1 9.else if, for all j, a[j]=b[j] 10. return ; Direct scan Update i (S, d) 1.view:=scan() 2.Segment[i]=<d, view, 1-Segment[i].toggle)

11 The Renaming Problem Processes start with unique names from a large domain Processes should pick new names that are still distinct but that are from a smaller domain Motivation: Suppose original names are serial numbers (many digits), but we'd like the processes to share an array whose size is proportional to the actual number of existing processes

12 Renaming Problem Definition Termination: Eventually every nonfaulty proc p i decides on a new name y i Uniqueness: If p i and p j are distinct nonfaulty procs, then y i ≠ y j. Anonymity: Processes cannot directly use their index, only their name.

13 Performance of Renaming Algorithm New names should be drawn from {1,2,…,M}. We would like M to be as small as possible. Uniqueness implies M must be at least n. Due to the possibility of failures, M will actually be larger than n.

14 Renaming Results Algorithm for wait-free case (f = n - 1) with M = n + f = 2n - 1. Algorithm for general f with M = n + f. Lower bound that M must be at least n + 1, for the wait-free case. –Proof similar to impossibility of wait-free consensus Stronger lower bound that M must be at least n + f, if f is the number of possible failures –Proof uses algebraic topology and is related to lower bound for set consensus

15 Wait-free renaming algorithm Processes communicate via snapshot object Each process iteratively stores its original name and a (suggested, tentative) new name If the name suggested by p is taken, it next suggests the k'th free name, where k is its original rank

16 Program for process i 1.newName := 1 ;Maybe I can get the smallest name 2.While true do ;While haven’t fixed my new name 3. S.update i ( ) ;Announce new suggestion 4.,…, := S.scan() ;obtain a view 5. if (newName = s j for some j ≠ i) ;ouch, there’s a clash ; select the r’th free name, where r is my rank 6. let r be the rank of oldName in {x j ≠ empty | 0≤j≤n-1} 7. let newName be r’th integer not in {s j ≠ empty | 0≤j ≠ i ≤n-1} 8. else 9. return newName Shared: Snapshot S, each entry is of the form, initially empty Local: int oldName ;this is p i ’s original name int newName ;this is p i ’s suggested name, initially 1 Wait-free renaming algorithm (cont’d)

17 The algorithm is a correct wait-free implementation of renaming that requires at most 2n-1 names

18 18 Renaming Results Algorithm for wait-free case (f = n - 1) with M = n + f = 2n - 1. Algorithm for general f with M = n + f. Lower bound that M must be at least n + 1, for the wait-free case. –Proof similar to impossibility of wait-free consensus Stronger lower bound that M must be at least n + f, if f is the number of possible failures –Proof uses algebraic topology and is related to lower bound for set consensus


Download ppt "Distributed Algorithms (22903) Lecturer: Danny Hendler The Atomic Snapshot Object The Renaming Problem This presentation is based on the book “Distributed."

Similar presentations


Ads by Google