Atomic Snapshots
Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base objects Introduction2 data
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) Introduction3
Atomic Snapshot n components Update a single component Scan all the components “at once” (atomically) Provides an instantaneous view of the whole memory Introduction4 update ok scan v 1,…,v n
236825Introduction5 Atomic Snapshot Algorithm Update(v,k) A[k] = v,seq i, i Scan() repeat read A[1],…,A[n] if equal return A[1,…,n] Linearize: Updates with their writes Scans inside the double collects double collect [Afek, Attiya, Dolev, Gafni, Merritt, Shavit, JACM 1993]
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#) Creates a “safe zone”, where the scan can be linearized Introduction6 read A[1],…,A[n] write A[j]
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 Introduction7
Wait-free Atomic Snapshot [Afek, Attiya, Dolev, Gafni, Merritt, Shavit, JACM 1993] Embed a scan within the Update Introduction8 Update(v,k) V = scan A[k] = v,seq i, i,V Scan() repeat read A[1],…,A[n] if equal return A[1,…,n] else record diff if twice p j return V j Linearize: Updates with their writes Direct scans as before Borrowed scans in place Linearize: Updates with their writes Direct scans as before Borrowed scans in place direct scan borrowed scan
Atomic Snapshot: Borrowed Scans Interference by process p j And another one… p j does a scan inbeteween Linearizing with the borrowed scan is OK Introduction9 write A[j] read A[j] …… …… embedded scan write A[j] read A[j] …… ……
© Hagit Attiya (2013) 04: R/W simulations10 Complexity of Atomic Snapshots Scan needs O(n 2 ) reads and writes, why? Update needs O(n 2 ) reads and writes
O(nlogn) Atomic snapshots n components Scate - Update a single component and Scan all the components “at once” (atomically) Provides an instantaneous view of the whole memory 11 scate v 1,…,v n [Attiya, Rachman SIAM 1998]
One-shot Atomic Snapshot 12 scate v 1,…,v n
One-shot Atomic Snapshot 13 scate v 1,…,v n
The Classifier Procedure 14 K=2 1,1,1 lefties righties Local knowledge Original knowledge dominating knowledge Lemma: The output view of a righty dominates the union of the lefties outputs.
Atomic Snapshot from Classifiers Scate operation requires O(nlogn) operations on single-writer multireader registers.
Atomic Snapshot from Classifiers Scate(val) S i =(val) For j=1 to n current i,1 [j]=S j v=root For l=1 to log(n) current i,l+1 =Classifier(label(v),current i,l ) if righty then v = v.right if lefty then v = v.left Return current i,log(n)+1 16 Operations are ordered in the leaves : Operations arriving at different leaves are comparable. Operations arriving at the same leaf have exactly the same final knowledge.
Linearization scan update The views returned by the scate operations are comparable and ordered at the leaves from left to right