MayaArbel

advertisement
Atomic Snapshots
Abstract Data Types
• Abstract representation of data & set of
methods (operations) for accessing it
• Implement using primitives on base objects
data
236825
Introduction
2
Correctness: Linearizability
[Herlihy & Wing, 1990]
• For every concurrent execution there is a sequential
execution that
– Contains the same operations
– Is legal (obeys the specification of the ADTs)
– Preserves the real-time order of non-overlapping
operations
• Each operation appears to takes effect
instantaneously at some point between its invocation
and its response (atomicity)
236825
Introduction
3
Atomic Snapshot
• n components
• Update a single component
• Scan all the components
“at once” (atomically)
update
ok
scan
v1,…,vn
Provides an instantaneous view of the whole
memory
236825
Introduction
4
Atomic Snapshot Algorithm
[Afek, Attiya, Dolev, Gafni, Merritt, Shavit, JACM 1993]
Update(v,k)
A[k] = v,seqi,i
Linearize:
• Updates with their writes
• Scans inside the double collects
236825
double
Scan()
collect
repeat
read A[1],…,A[n]
read A[1],…,A[n]
if equal
return A[1,…,n]
Introduction
5
Atomic Snapshot: Linearizability
Double collect (read a set of values twice)
If equal, there is no write between the collects
– Assuming each write has a new value (seq#)
read A[1],…,A[n]
read A[1],…,A[n]
write A[j]
Creates a “safe zone”, where the scan can be
linearized
236825
Introduction
6
Liveness Conditions
• Wait-free: every operation completes within a finite
number of (its own) steps
no starvation for mutex
• Nonblocking: some operation completes within a finite
number of (some other process) steps
deadlock-freedom for mutex
• Obstruction-free: an operation (eventually) running solo
completes within a finite number of (its own) steps
– Also called solo termination
wait-free  nonblocking  obstruction-free
236825
Introduction
7
Wait-free Atomic Snapshot
[Afek, Attiya, Dolev, Gafni, Merritt, Shavit, JACM 1993]
• Embed a scan within the Update.
Update(v,k)
V = scan
A[k] = v,seqi,i,V
Linearize:
• Updates with their writes
• Direct scans as before
• Borrowed scans in place
236825
Scan()
direct
scan
repeat
read A[1],…,A[n]
read A[1],…,A[n]
if equal
return A[1,…,n]
else record diff
if twice pj
borrowed
scan
return Vj
Introduction
8
Atomic Snapshot: Borrowed Scans
Interference by process pj
And another one…
pj does a scan inbeteween
read A[j]
…
…
write A[j]
read A[j]
…
read A[j]
…
…
embedded scan
…
read A[j]
…
…
write A[j]
Linearizing with the borrowed scan is OK.
236825
Introduction
9
Complexity of Atomic Snapshots
• Scan needs O(n2) reads and writes, why?
• Update needs O(n2) reads and writes
©Hagit Attiya
236755 (2013) 04: R/W simulations
10
O(nlogn) Atomic snapshots
[Attiya, Rachman SIAM 1998]
• n components
• Scate - Update a single
component and Scan all the
components “at once”
(atomically)
scate
v1,…,vn
Provides an instantaneous view
of the whole memory
11
One-shot Atomic Snapshot
• Each processes execute at most
one scate operation.
• The size of a view 𝑉 is the
number of non-empty entries.
scate
v1,…,vn
12
One-shot Atomic Snapshot
• 𝑉1 dominates 𝑉2 , if for all 𝑖, if
𝑉1 𝑖 =⊥ then 𝑉2 𝑖 =⊥.
• union of a set {𝑉1 , … , 𝑉𝑙 },
denoted by ∪ 𝑉1 , … , 𝑉𝑙 is the
view that dominates all views
𝑉1 , … , 𝑉𝑙 .
scate
v1,…,vn
13
The Classifier Procedure
Local
knowledge
Classifier(K,Ii)
Write Ii to Ri
Read R1,…, Rn
If |∪{R1,…, Rn}|>K then
read R1,…, Rn
return Oi = ∪{R1,…, Rn}
Else
dominating
knowledge
return Oi = Ii
Original
knowledge
1, ⊥,⊥⊥
1,1,
1,1,1
K=2
⊥,⊥,
1,1
⊥
⊥,
1, ⊥, ⊥ ⊥, ⊥,
1, ⊥ ⊥,
Lemma: The output view of a
righty dominates the union of
the lefties outputs.
righties
lefties
14
Atomic Snapshot from Classifiers
𝑛
Classifier 2
𝑛
Classifier 4
1
3
Classifier
3𝑛
4
n−3
n−1
• Scate operation requires O(nlogn) operations on
single-writer multireader registers.
15
Atomic Snapshot from Classifiers
Scate(val)
Operations are ordered in the leaves :
• Operations arriving at different leaves
Si=(val)
are comparable.
For j=1 to n
• Operations arriving at the same leaf
currenti,1[j]=Sj
have exactly the same final knowledge.
v=root
For l=1 to log(n)
currenti,l+1=Classifier(label(v),currenti,l)
if righty then v = v.right
if lefty then v = v.left
Return currenti,log(n)+1
Lemma: Let 𝑜𝑝 be a scate operation that passes
Lemma : Let OP be the set of scate operations
through a node 𝑣 with level 𝑙 then
that pass through a node 𝑣 with level 𝑙 then
𝑛
|⋃OP|≤
𝑙𝑎𝑏𝑒𝑙 𝑣 + 2𝑙
𝑛
𝑛
𝑙𝑎𝑏𝑒𝑙(𝑣) − 2𝑙 < 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑜𝑝,𝑙 ≤ 𝑙𝑎𝑏𝑒𝑙 𝑣 + 2𝑙
16
Linearization
• The views returned by
the scate operations
are comparable and
ordered at the leaves
from left to right
1
3
scan
update
𝑘
n−3
n−1
17
Download