17
Atomic Snapshots

Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Embed Size (px)

Citation preview

Page 1: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Atomic Snapshots

Page 2: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 2

Abstract Data Types

• Abstract representation of data & set of methods (operations) for accessing it

• Implement using primitives on base objects

236825

data

Page 3: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 3

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

Page 4: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 4

Atomic Snapshot

• n components• Update a single component• Scan all the components

“at once” (atomically)

Provides an instantaneous view of the whole memory

236825

update

ok

scan

v1,…,vn

Page 5: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

5236825 Introduction

Atomic Snapshot Algorithm

Update(v,k)A[k] = v,seqi,i

Scan()repeat

read A[1],…,A[n]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]

Page 6: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 6

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

236825

read A[1],…,A[n] read A[1],…,A[n]

write A[j]

Page 7: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 7

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

Page 8: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 8

Wait-free Atomic Snapshot[Afek, Attiya, Dolev, Gafni, Merritt, Shavit, JACM 1993]

• Embed a scan within the Update.

236825

Update(v,k)V = scanA[k] = v,seqi,i,V

Scan()repeat

read A[1],…,A[n]read A[1],…,A[n]if equal

return A[1,…,n]

else record diffif twice pj

return Vj

Linearize:• Updates with their writes• Direct scans as before• Borrowed scans in place

direct scan

borrowedscan

Page 9: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Introduction 9

Atomic Snapshot: Borrowed Scans

Interference by process pj

And another one… pj does a scan inbeteween

Linearizing with the borrowed scan is OK.236825

write A[j]

read A[j]… …

read A[j]… …

embedded scan write A[j]

read A[j]… …

read A[j]… …

Page 10: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

© Hagit Attiya 236755 (2013) 04: R/W simulations 10

Complexity of Atomic Snapshots

• Scan needs O(n2) reads and writes, why?• Update needs O(n2) reads and writes

Page 11: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

11

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

scate

v1,…,vn

[Attiya, Rachman SIAM 1998]

Page 12: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

One-shot Atomic Snapshot

• Each processes execute at most one scate operation.

• The size of a view is the number of non-empty entries.

12

scate

v1,…,vn

Page 13: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

One-shot Atomic Snapshot

• dominates , if for all , if then • union of a set , denoted by is

the view that dominates all views .

13

scate

v1,…,vn

Page 14: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

The Classifier Procedure

14

Classifier(K,Ii)

Write Ii to Ri

Read R1,…, Rn

If |{R1,…, Rn}|>K then

read R1,…, Rn

return Oi = {R1,…, Rn}

Else return Oi = Ii

K=2

⊥ ,⊥,⊥1 ,⊥ ,⊥

1 ,⊥ ,⊥

⊥ ,1,⊥

1 ,1 ,⊥

⊥ ,1,1

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.

⊥ ,⊥,⊥⊥ ,⊥,⊥

Page 15: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Atomic Snapshot from Classifiers

15

1 3

Classifier Classifier

Classifier

n n−1

• Scate operation requires O(nlogn) operations on single-writer multireader registers.

Page 16: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Atomic Snapshot from ClassifiersScate(val)Si=(val)

For j=1 to n currenti,1[j]=Sj

v=rootFor l=1 to log(n)

currenti,l+1=Classifier(label(v),currenti,l)

if righty then v = v.rightif lefty then v = v.left

Return currenti,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.

Lemma: Let be a scate operation that passes through a node with level then

Lemma : Let OP be the set of scate operations that pass through a node with level then

|OP|

Page 17: Atomic Snapshots. Abstract Data Types Abstract representation of data & set of methods (operations) for accessing it Implement using primitives on base

Linearization

17

1 3 n n−1𝑘

scan

update

• The views returned by the scate operations are comparable and ordered at the leaves from left to right