140 likes | 153 Views
This presentation discusses the atomic snapshot object and the renaming problem in distributed algorithms, based on the book "Distributed Computing" by Hagit Attiya and Jennifer Welch. It covers the atomic snapshot object, algorithmic ideas, simulation of atomic snapshot, wait-free simulation, and the renaming problem with its algorithm and results.
E N D
DistributedAlgorithms (22903) The Atomic Snapshot Object The Renaming Problem Lecturer: Danny Hendler This presentation is based on the book “Distributed Computing” by Hagit attiya & Jennifer Welch.
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: • Updatei(v), by pi, updates pi’s segment to value v. • 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 Updatei 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
A trivial (and wrong) algorithm Initially segment[i]=vi Updatei(S, v) • Segment[i]=v Scani(S) • for i=1 to n • tmp[i]=Segment[i] • return < tmp[1], …, tmp[n] > Why is this algorithm incorrect?
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
A wait-free simulation of atomic snapshot Initially segment[i].ts=0, segment[i].data=vi, segment[i].view=<v0, …, vn-1> Updatei(S, d) • view:=scan() • Segment[i]=<segment[i].ts+1, d, view> Scani(S) • for all j <> i: c[j]=Segment[j] • while true do • for all j: a[j] = Segment[j] • for all j: b[j] = Segment[j] • if, for all j, a[j]=b[j] ; Comparison includes timestamp! • return <b[0].data, …, b[n-1].data> ; Direct scan • else if, for some j ≠ i, b[j].ts - c[j].ts ≥ 2 • return b[j].view ; Indirect scan
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.
A proof that the algorithm for atomic snapshot is wait-free and linearizable
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
Renaming Problem Definition Termination: Eventually every nonfaulty proc pidecides on a new name yi Uniqueness:If pi and pj are distinct nonfaulty procs, then yi ≠ yj. Anonymity:Processes cannot directly use their index, only their name.
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.
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
Wait-free renaming algorithm (cont’d) Shared:Snapshot S, each entry is of the form <x,s>, initially emptyLocal:int oldName ;this is pi’s original nameint newName;this is pi’s suggested name, initially 1 Program for process i • newName := 1 ;Maybe I can get the smallest name • While true do ;While haven’t fixed my new name • S.updatei(<oldName,newName>) ;Announce new suggestion • <x0,s0>,…,<xn-1,sn-1> := S.scan() ;obtain a view • if (newName = sj for some j ≠ i) ;ouch, there’s a clash ; select the r’th free name, where r is my rank • let r be the rank of oldName in {xj ≠ empty | 0≤j≤n-1} • let newName be r’th integer not in {sj ≠ empty | 0≤j ≠ i ≤n-1} • else • return newName
The algorithm is a correct wait-free implementation of renaming that requires at most 2n-1 names
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