Atomic snapshots in O (log³ n) steps
description
Transcript of Atomic snapshots in O (log³ n) steps
1
Atomic snapshots in O(log³ n) steps
Snapshot Objects
p1 p2 pn…
…
update(v) scan
2
update your location
read all locations
3
Model
System of n processes, multi-writer registersAsynchronous schedule controlled by an adversaryCrash failures – require wait-free implementationsLinearizable implementations
p1 p2
R1
pn
R2 R…
…
read v write(v) ok
4
Snapshots - Step ComplexityUsing 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)
5
Pointer to array location
s1 s2 s3 s4
s1+s2 s3+s4
s1+...+s4
0
Tree structure, Updates help Scans
0 01 1
12
2 2
3
3
45
Array of views
5X
O(log n) steps?
6
Two Challenges
s1 s2 s3 s4
s1+s2 s3+s4
s1+...+s4
5
1. Coping with slow operations. Max-register: returns largest
value previously written
7
Two Challenges
s1 s2 s3 s4
s1+s2 s3+s4
s1+...+s4
5
2. Guaranteeing consistent views. Max-array: returns comparable
pairs of max-register values
8
Bounded/Randomized snapshot in O(log3n) steps
Bounded/Randomized 2-component max-arrayO(log2n) steps
Bounded/Randomized max-register in O(logn) steps
Ingredients
9
Max register
• Replace multi-writer registers with Max Registers
Max Register
WriteMax(v)ok
ReadMaxv
Maximal value previously
written
10
Max register – recursive construction
• 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”
MaxReg0
MaxReg0 MaxReg0
switchWriteMax 01 =1
ReadMax= ?
switch=0 : return 0
switch=1 : return 1
11
Max register – recursive construction
• 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/2 MaxRegk/2
MaxRegk
switchWriteMax tt < k/2 ?t t-k/2
ReadMax
=1
= ?
t tswitch=0 : return t
switch=1 : return t+k/2
12
MaxRegk unfolded
switch
MaxReg0 …
switch
switch switch
MaxReg0MaxReg0 MaxReg0MaxReg0
… …
MaxRegk
0 1 2 k-1
Complexity does not depend on n:WriteMax and ReadMax in O(logk) steps
O(logk)
13
Unbalanced tree
MaxReg0
…
switch
switch
switchswitch
MaxReg0 MaxReg0
Bentley and Yao [1976]
switch
switchswitch
MaxReg0 MaxReg0 MaxReg0 MaxReg0
Leaf i is at depth O(log i)
14
Unbounded max register
MaxReg0
…
switch
switch
Snapshot-based counter
switchswitch
MaxReg0 MaxReg0
WriteMax and ReadMax of vin O(min(log v, n)) steps
2-component max array
p1 p2 pn…
max 1 max 2
update(v,1)scan
15
update(v,2)
16
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
17
2-component max array
Simply reading one max register and then the other does not work
max 1 max 21. p1 read 02. p2 write(100)3. p3 read 100
4. p3 read 05. p2 write(100)6. p1 read 100
p1 returns(0,100)p3 returns(100,0)
18
2-component max array
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 pairIf you see (0,1) or (1,0) read again
max 1 max 21. p1 read 02. p2 write(100)3. p3 read 100
4. p3 read 05. p2 write(100)6. p1 read 100
19
A 2-component max array
MaxRegk/2 MaxRegk/2
MaxRegk
switch MaxRegl
MaxRegl MaxRegl
Write
Read
switch=0 :
switch=1 :
v,1v,2
x=ReadMax component 2
WriteMax(x,2) to left subtreeReturn (Read left subtree)
x=ReadMax component 2WriteMax(x,2) to right subtreeReturn (k/2,0)+(Read right subtree)
xx
= ?
20
A 2-component max array
MaxRegk/2 MaxRegk/2
MaxRegk
switch MaxRegl
MaxRegl MaxRegl
Write
Read
switch=0 :
switch=1 :
x=ReadMax component 2
WriteMax(x,2) to left subtreeReturn (Read left subtree)
x=ReadMax component 2WriteMax(x,2) to right subtreeReturn (k/2,0)+(Read right subtree)
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
21
A 2-component max array unfolded
switch
MaxReg0 …
switch
switch switch
MaxReg0MaxReg0 MaxReg0MaxReg0
… …
MaxRegk MaxRegl
MaxRegl
MaxRegl MaxRegl
MaxRegl MaxRegl MaxRegl MaxRegl MaxRegl
Complexity is O(logk logl) steps
22
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
23
Towards an Unbounded Max-Register
switch = 0
switch = 0 switch = 0
value 0 value 1
value v value v’
… ……
write(v)
switch = 1 read
24
Towards an Unbounded Max-Register
switch = 0
switch = 0 switch = 0
value 0 value 1
value v value v’
… ……
write(v)
switch = 1 read
write(v’)
switch = 1
write(v’’)
25
Randomized Max-Registerswitch = 0
switch = 0
switch = 0
…
…
write(v)
switch = 1
switch = 1
m-valued max register
26
Randomized Max-Registerswitch = 0
switch = 0
switch = 0
…
…
write(v)
switch = 1
switch = 1k-bounded increments:
value of write ≤ k + value of largest write
m-valued max register
O(log m + kn/m) = O(log n) steps per write
Assumption satisfied in snapshot tree for k=n
27
Writing to the Max-Register
0
…
…
write(v)
1
1…TS:
…HELP:
…POINTER:
write(v)pi
v', ts[j]TS[j]
pj (cyclic)
i
read
(random)size n3
read v’ = max(returned value, v)
28
Reading the Max-Register
0
…
…
read
1
1…TS:
…HELP:
…POINTER:
readpi
read (returns v, ts[j])
pj
read (returns i)
+1
(random)size n3
(logarithmic no. of steps)
if ts[j]==TS[j] return v
Main argument:many read steps
many fresh values in pointer array, whp
29
2-Component Max Array
write0(v)
read
update first max-register
read both max-registers
write1(v)update second max-register
30
Max Array Implementationswitch = 0
switch = 0 switch = 0
value 0 value 1
value v value v’
… ……
write0(v)
readMax1
Max1 Max1
Max1 Max1
Max1 Max1
write1(v) Max1
Max1
Max1
31
Randomized 2-Component Max Array
switch = 0
switch = 0
switch = 0
…
…
write(v)
switch = 1
switch = 1 Max1
Max1Max1
Max1
Max1 Max1
Max1
Max1
Max1
Problem: readers do not travel all the way
from root to valueMax1
Max1Max1
Solution: read Max at root instead of Max at
previous location
32
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