320 likes | 478 Views
Atomic snapshots in O (log³ n) steps. Snapshot Objects. …. update( v ). scan. r ead all locations. update your location. p 1. p 2. p n. …. Model. R 1. R 2. R. …. read. v. write( v ). ok. p 1. p 2. p n. …. System of n processes, multi-writer registers
E N D
Snapshot Objects … update(v) scan read all locations update your location p1 p2 pn …
Model R1 R2 R … read v write(v) ok p1 p2 pn … System of nprocesses, multi-writer registers Asynchronous schedule controlled by an adversary Crash failures – require wait-free implementations Linearizable implementations
Snapshots - Step Complexity Using multi-writer registers: can be done in O(n)steps [Inoue and Chen, WDAG 1994] and requires Ω(n) steps [Jayanti, Tan, and Toueg, SICOMP 1996] Goal: a faster snapshot implementation (polylog) Limited-use: O(log3(n)) steps per operation, for polynomially many update operations Randomized unbounded: O(log3(n)) steps per operation, with high probability (without a usage bound)
Tree structure, Updates help Scans O(log n) steps? Array of views Pointer to array location X 5 2 1 0 4 3 5 s1+...+s4 1 2 0 0 2 3 1 s1+s2 s3+s4 s1 s2 s3 s4
Two Challenges 1. Coping with slow operations. Max-register: returns largest value previously written 5 s1+...+s4 s1+s2 s3+s4 s1 s2 s3 s4
Two Challenges 2. Guaranteeing consistent views. Max-array: returns comparable pairs of max-register values 5 s1+...+s4 s1+s2 s3+s4 s1 s2 s3 s4
Ingredients • Bounded/Randomized max-register in O(logn)steps • Bounded/Randomized 2-component max-array • O(log2n) steps • Bounded/Randomized snapshot in O(log3n)steps
Max register Max Register WriteMax(v) Maximal value previously written ok ReadMax v Replace multi-writer registers with Max Registers
Max register – recursive construction MaxReg0 =1 0 1 WriteMax = ? switch ReadMax switch=0 : return 0 MaxReg0 MaxReg0 switch=1 : return 1 • MaxReg0: Max register that supports only the value 0 • WriteMax is a no-op, and ReadMax returns 0 • MaxReg1 supports values in {0,1} • Built from two MaxReg0 objects • and one additional multi-writer register “switch”
Max register – recursive construction =1 t t WriteMax < k/2 ? switch = ? t t-k/2 ReadMax t t switch=0 : return t MaxRegk/2 MaxRegk/2 switch=1 : return t+k/2 • MaxRegk • MaxRegk supports values in {0,…,k-1} • Built from two MaxRegk/2 objects with values in {0,…,k/2-1} • and one additional multi-writer register “switch”
MaxRegk unfolded MaxRegk switch • Complexity does not depend on n: • WriteMaxand ReadMaxinO(logk)steps … … switch O(logk) switch switch MaxReg0 MaxReg0 MaxReg0 MaxReg0 MaxReg0 … 0 1 2 k-1
Unbalanced tree switch Bentley and Yao [1976] MaxReg0 switch switch switch MaxReg0 MaxReg0 switch … Leaf i is at depth O(log i) switch switch MaxReg0 MaxReg0 MaxReg0 MaxReg0
Unbounded max register switch MaxReg0 switch • WriteMax and ReadMax of vin O(min(log v, n)) steps switch switch MaxReg0 MaxReg0 … Snapshot-based counter
2-component max array max 1 max 2 update(v,1) update(v,2) scan p1 p2 pn …
Cannot Simply Read Both Locations • We need to make sure that pairs of values that are read from sibling nodes are comparable • As in a snapshot • In general, snapshots are linear • However, we only need to take a snapshot of two max registers
2-component max array 4. p3 read 0 1. p1 read 0 max 1 max 2 5. p2 write(100) 2. p2 write(100) 6. p1 read 100 3. p3 read 100 p1returns(0,100) p3returns(100,0) Simply reading one max register and then the other does not work
2-component max array 4. p3 read 0 1. p1 read 0 max 1 max 2 5. p2 write(100) 2. p2 write(100) 6. p1 read 100 3. p3 read 100 Read max registers again to see if they change • Might change many times • What if they were only binary? (0,0) and (1,1) are comparable with any pair If you see (0,1) or (1,0) read again
A 2-component max array v,2 Write v,1 = ? Read switch MaxRegl x x=ReadMax component 2 x switch=0 : WriteMax(x,2) to left subtree MaxRegk/2 MaxRegk/2 Return (Read left subtree) switch=1 : • MaxRegk MaxRegl MaxRegl x=ReadMax component 2 WriteMax(x,2) to right subtree Return (k/2,0)+(Read right subtree)
A 2-component max array Write Read switch MaxRegl x=ReadMax component 2 • Key idea: a reader going right at the switch always sees a value for component 2 that is at least as large as any value that a reader going left sees switch=0 : WriteMax(x,2) to left subtree MaxRegk/2 MaxRegk/2 Return (Read left subtree) switch=1 : • MaxRegk MaxRegl MaxRegl x=ReadMax component 2 WriteMax(x,2) to right subtree Return (k/2,0)+(Read right subtree)
A 2-component max array unfolded MaxRegl MaxRegk switch Complexity isO(logklogl)steps … … MaxRegl switch MaxRegl MaxRegl switch switch MaxReg0 MaxReg0 MaxReg0 MaxReg0 MaxReg0 … MaxRegl MaxRegl MaxRegl MaxRegl MaxRegl
Summary of the Bounded Snapshot For k which is polynomial in n we get: A max-register with O(logn) steps per operation A 2-component max-array with O(log2n) steps per operation A bounded snapshot object, supporting a polynomial number of update operations, with O(log3n) steps per operation
Towards an Unbounded Max-Register switch = 0 switch = 1 read switch = 0 switch = 0 … … value 0 value 1 value v value v’ … write(v)
Towards an Unbounded Max-Register switch = 0 switch = 1 read switch = 0 switch = 1 switch = 0 … … value 0 value 1 value v value v’ … write(v) write(v’) write(v’’)
Randomized Max-Register switch = 0 switch = 1 switch = 0 switch = 1 … m-valued max register switch = 0 … write(v)
Randomized Max-Register k-bounded increments:value of write ≤ k + value of largest write switch = 0 switch = 1 switch = 0 switch = 1 Assumption satisfied in snapshot tree for k=n … m-valued max register switch = 0 … O(log m + kn/m) = O(log n) steps per write write(v)
Writing to the Max-Register pj(cyclic) 1 TS: read 1 v’ = max(returned value, v) read write(v) pi … HELP: 0 v', ts[j]TS[j] (random) … size n3 POINTER: i write(v)
Reading the Max-Register pj read 1 TS: +1 1 read (logarithmic no. of steps) pi … HELP: 0 read (returns v, ts[j]) Main argument: many read stepsmany fresh values in pointer array, whp (random) … size n3 POINTER: read (returns i) if ts[j]==TS[j] return v
2-Component Max Array write1(v) write0(v) update second max-register update first max-register read read both max-registers
MaxArray Implementation Max1 Max1 switch = 0 write1(v) read switch = 0 Max1 Max1 switch = 0 Max1 … … value 0 Max1 value 1 Max1 value v value v’ Max1 Max1 Max1 … write0(v)
Randomized 2-Component Max Array Problem: readers do not travel all the way from root to value switch = 0 switch = 1 Max1 Max1 Max1 switch = 1 switch = 0 Max1 Max1 Max1 Max1 Max1 … Max1 switch = 0 Max1 Max1 Solution: read Max at root instead of Max at previous location … Max1 write(v)
Summary of the Unbounded Snapshot A randomized max-register with O(logn) steps per operation, with high probability, under the bounded-increments assumption A randomized 2-component max-array with O(log2n) steps per operation, with high probability, under the bounded-increments assumption An randomized unbounded snapshot object, supporting a polynomial number of update operations, with O(log3n) steps per operation, with high probability