73
Replicated Data Types: Specification,Verification, Optimality Hongseok Yang University of Oxford Joint work with Sebastian Burckhardt (Microsoft Research), Alexey Gotsman (IMDEA) and Marek Zawirski (UPMC & INRIA)

Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Replicated Data Types: Specification, Verification, Optimality

Hongseok Yang University of Oxford

Joint work with Sebastian Burckhardt (Microsoft Research), Alexey Gotsman (IMDEA) and Marek Zawirski (UPMC & INRIA)

Page 2: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

What is it like writing programs running on top of weakly consistent distributed stores?

Page 3: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of
Page 4: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Information about each customer

Page 5: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

Bob in UK

Alice in Korea

Page 6: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

Bob in UK

Alice in Korea

add(A,4)

Page 7: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1)Bob in UK

Alice in Korea

add(A,4)

Page 8: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)Bob in UK

Alice in Korea

add(A,4)

Page 9: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Page 10: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)

[Q] What cannot be the result of count(A)? (a) 1 (b) 3 (c) 5 (d) all possible

Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Page 11: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)

[Q] What cannot be the result of count(A)? (a) 1 (b) 3 (c) 5 (d) all possible

Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Page 12: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)

[Q] What cannot be the result of count(A)? (a) 1 (b) 3 (c) 5 (d) all possible

Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Page 13: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)

[Q] What cannot be the result of count(A)? (a) 1 (b) 3 (c) 5 (d) all possible

Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Page 14: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart (Shapiro et al.)

rem(A,1) count(A)

[Q] What cannot be the result of count(A)? (a) 1 (b) 3 (c) 5 (d) all possible

Bob in UK

Alice in Korea

add(A,4) rem(A,2)

Because of weak consistency of the store.

Page 15: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Geo-replicated databases

• Every data centre stores a complete replica of data

• Purpose: Minimising latency. Fault tolerance.

Page 16: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Geo-replicated databases

• Every data centre stores a complete replica of data

• Purpose: Minimising latency. Fault tolerance.

Page 17: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Geo-replicated databases

• Every data centre stores a complete replica of data

• Purpose: Minimising latency. Fault tolerance.

Page 18: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

Page 19: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

cart.add(A,4) cart.read() : {A}

Page 20: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

cart.add(A,4) cart.read() : {A}

Page 21: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

cart.add(A,4) cart.read() : {A}

Page 22: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

cart.add(A,4) cart.read() : {A}

Page 23: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.add(A,4) cart.read() : {A}

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

cart.count(A) : 4 cart.write({B})

Page 24: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.add(A,4) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

cart.count(A) : 4 cart.write({B})

Page 25: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.add(A,4) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,3)}

{(A,4)}

{(A,4)}

cart.count(A) : 4 cart.rem(A,1)

Issue 1: Latency

Page 26: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.add(A,4) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,3)}

{(A,4)}

{(A,4)}

cart.count(A) : 4 cart.rem(A,1)

Issue 2: Cannot tolerate network partition

Page 27: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistency

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,4)}

Page 28: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.read() : {A}

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,2)}

Page 29: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.read() : {A}

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,4)}

{(A,2)}

Page 30: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.read() : {A}

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,2)}

{(A,2)}

Page 31: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,4)}

{(A,2)}

{(A,2)}Issue 1: Anomalies

Page 32: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,3)}

{(A,2)}

{(A,2)}Issue 2: Conflicting updates

cart.rem(A,1)

Page 33: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Data consistencycart.rem(A,2) cart.count(A): 4

• Do data centre stores behave as if a single store?

• Strong consistency: Yes. Block until all get updated.

• Weak consistency: No. First update. Then propagate.

{(A,3)}

{(A,2)}

{(A,2)}Issue 2: Conflicting updates

cart.rem(A,1)

{(A,3)}

{(A,2)}

Page 34: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Popularity of weak consistency

• Dynamo/Simple DB (Amazon), Riak, Cassandra (Facebook/Twitter), CouchDB, Google Doc,etc

• Due to better responsiveness and availability.

• But created a programming challenge.

Page 35: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Shopping cart

• Map from book ids to natural numbers.

• Initially, constant-0 function.

• add : {0,…,N-1} × Nat ⟶ Unit

• rem : {0,…,N-1} × Nat ⟶ Unit

• count : {0,…,N-1} ⟶ Nat

Page 36: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Sequential data typeclass Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Page 37: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Sequential data typeclass Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Page 38: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Sequential data typeclass Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Page 39: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Sequential data typeclass Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Page 40: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Sequential data typeclass Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Page 41: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Sequential data typeReplicated

cart cart

Page 42: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b); map(b) = m+n } def rem(b,n) = { val m = map(b); map(b) = max(m-n,0) } def count(b) = { val m = map(b); return m } }

Sequential data typeReplicated

cart cart

Things to be added: 1. Asynchronous message sending & receiving. 2. Conflict detection and resolution.

Page 43: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Primitive replicated data types (AKA CRDT) [Shapiro+ 2011]

• Designed for weakly consistent replicated stores.

• Send & receive update messages asynchronously.

• Detect and resolve conflicts.

• Register, set, dag, graph, etc.

• Conceptually, implement a weak shared memory on top of a replicated store.

Page 44: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking the union.

Page 45: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

Page 46: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

Page 47: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

x.get() // {1,2}

Page 48: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

x.get() // {1,2}

x.set(3)

Page 49: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

x.get() // {1,2}

x.set(3)

Page 50: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

x.get() // {1,2}

x.set(3)

x.get() // {3}

Page 51: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Multi-valued registerset : T ⟶ Unit get : Unit ⟶ Set[T]

• Implements a memory cell of type T.

• Resolves conflicts by taking union.

x.set(1) x.set(2)

x.get()

x.set(3)

x.get() // {3}

Page 52: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new Array[Nat](N) ! def add(b,n) = { val m = map(b) map(b) = m+n } def rem(b,n) = { val m = map(b) map(b) = max(m-n,0) } def count(b) = { val m = map(b) return m } }

Shopping cart for replicated stores

Page 53: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new Array[MVRegister[Nat]](N) for(i <- 0 until N) map(i) = new MVRegister[Nat] def add(b,n) = { val m = map(b).get() map(b).set(m+n) } def rem(b,n) = { val m = map(b).get() map(b).set(max(m-n,0)) } def count(b) = { val m = map(b).get() return m } }

Shopping cart for replicated stores

1. Use MVRegister. 2. Add conflict resolution.

Page 54: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new array[MVRegister[Nat]](N) for(i <- 0 until N) map(i) = new MVRegister[Nat] ! def add(b,n) = { val m = sum(map(b).get()) map(b).set(m+n) } def rem(b,n) = { val m = sum(map(b).get()) map(b).set(max(m-n,0)) } def count(b) = { val m = sum(map(b).get()) return m } }

Shopping cart for replicated stores

1. Use MVRegister. 2. Add conflict resolution.

Page 55: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

class Cart { val map = new array[MVRegister[Nat]](N) for(i <- 0 until N) map(i) = new MVRegister[Nat] ! def add(b,n) = { val m = max(map(b).get()) map(b).set(m+n) } def rem(b,n) = { val m = max(map(b).get()) map(b).set(max(m-n,0)) } def count(b) = { val m = max(map(b).get()) return m } }

Shopping cart for replicated stores

1. Use MVRegister. 2. Add conflict resolution.

Page 56: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Semantics of replicated data types

Dag[Op] = Set of Op-labelled finite dags

F : Dag[Op] x Op ⟶partial Value

set(2)

set(4)

set(3) Fm( , get() ) = {4}

Page 57: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Fm( , get() ) = {4}

Semantics of replicated data types

Dag[Op] = Set of Op-labelled finite dags

F : Dag[Op] x Op ⟶partial Value

set(2)

set(4)

set(3)

Page 58: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Semantics of replicated data types

Dag[Op] = Set of Op-labelled finite dags

F : Dag[Op] x Op ⟶partial Value

set(2)

set(4)

set(3) Fm( , get() ) = {4}

Page 59: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Semantics of replicated data types

Dag[Op] = Set of Op-labelled finite dags

F : Dag[Op] x Op ⟶partial Value

set(2)

set(4)

set(3) Fm( , get() ) = {4}

Page 60: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Semantics of replicated data types

Dag[Op] = Set of Op-labelled finite dags

F : Dag[Op] x Op ⟶partial Value

set(2)

set(4)

set(3) Fm( , get() ) = {3,4}

Page 61: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

m(Fs( , count()))= ?

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

Page 62: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

m(Fs( , count()))= ?

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

Page 63: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

max(Fm( , get()))= ?

Page 64: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

max(Fm( , get()))= ?

Page 65: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

get() // 0

set(4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

max(Fm( , get()))= ?

Page 66: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

get() // 4

set(3)

get() // 0

set(4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,2)

max(Fm( , get()))= ?

Page 67: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

max(Fm( , get()))= ?

get() // 4

get() // 4

set(3)

set(2)

get() // 0

set(4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

Page 68: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

max(Fm( , get()))= 3

get() // 4

get() // 4

set(3)

set(2)

get() // 0

set(4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

Page 69: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

m(Fs( , count()))= 3

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

Page 70: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

m(Fs( , count()))= 3

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)3 copies

Page 71: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

m(Fs( , count()))= 3

add(A,4)

val map = new array[MVRegister[Nat]](N) . . . . . def add(b,n)={ val m = max(map(b).get()); map(b).set(m+n) } def rem(b,n)={ val m = max(map(b).get()); map(b).set(max(m-n,0)) } def count(b)={ val m = max(map(b).get()); return m }

rem(A,1)

rem(A,2)

2 copies

3 copies

Page 72: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Semantics

• Developed F-based semantics of distributed programs with weak transactions.

• It is equivalent to a more standard semantics.

• The details are in our tech report. Email me if you are interested.

Page 73: Replicated Data Types: Specification, Verification, Optimality · 2014. 7. 30. · Replicated Data Types: ! Specification, Verification, Optimality Hongseok Yang! University of

Take-home message

Developing a good programming model for weakly consistent distributed stores is a big challenge.