Scalable consistency for replicated data Anne3e Bieniusa - - PowerPoint PPT Presentation

scalable consistency for replicated data
SMART_READER_LITE
LIVE PREVIEW

Scalable consistency for replicated data Anne3e Bieniusa - - PowerPoint PPT Presentation

Scalable consistency for replicated data Anne3e Bieniusa Overview Replica:on Scalable consistency Limita:ons and Outlook Anne3e Bieniusa - Scalable


slide-1
SLIDE 1

Scalable ¡consistency ¡for ¡ replicated ¡data ¡

Anne3e ¡Bieniusa ¡

slide-2
SLIDE 2

Overview ¡

¡ Replica:on ¡ ¡ Scalable ¡consistency ¡ ¡ Limita:ons ¡and ¡Outlook ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 2 ¡

slide-3
SLIDE 3

Interac:ve ¡cloud-­‑backed ¡applica:ons ¡

  • Large ¡amounts ¡of ¡shared ¡mutable ¡data ¡
  • High ¡availability ¡expecta:ons ¡
  • Low ¡latency ¡business ¡cri:cal ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 3 ¡

slide-4
SLIDE 4

Server-­‑client ¡abstrac:on ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 4 ¡

slide-5
SLIDE 5

But ¡in ¡reality ¡... ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 5 ¡

slide-6
SLIDE 6

Replica:on! ¡ How ¡to ¡keep ¡the ¡replicas ¡consistent?! ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 6 ¡

slide-7
SLIDE 7

Strongly-­‑consistent ¡replica:on ¡

Update(x, ¡4) ¡

  • 1. Update(x,4) ¡
  • 2. Update(x,6) ¡
  • 3. .... ¡

Update(x,6) ¡

  • Requires ¡strong ¡synchroniza:on ¡
  • High ¡update ¡latency ¡
  • Not ¡scalable ¡
  • No ¡par::on-­‑tolerance ¡ ¡ ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 7 ¡

slide-8
SLIDE 8

Asynchronous ¡update-­‑propaga:on ¡

Update(x, ¡4) ¡ x ¡= ¡4 ¡ x ¡= ¡6 ¡ Update(x,6) ¡

? ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 8 ¡

  • Op:mis:c ¡
  • Low ¡update ¡latency ¡
  • High ¡availability ¡
  • ... ¡at ¡the ¡expense ¡of ¡weaker ¡consistency ¡

Read(x) ¡

? ¡

slide-9
SLIDE 9

Consistency

Adapted.from.Doug.Terry:.Cloud.Storage.Consistency.Explained.Through.Baseball..Dagstuhl.2013C02

Consistency.TradeCoffs

Strong.Consistency See.all.previous.writes.

.. .

Bounded.Staleness See.all.“old”.writes.

.. . .

  • Monotonic.Reads

See.increasing.subset.of.writes.

. .. . .. .

Read.My.Writes See.all.writes.performed.by.reader.

. . .

Consistent.Prefix See.iniNal.sequence.of.writes.

. .. . .. .

Eventual.Consistency See.subset.of.previous.writes.

.. . .. .

Performance Availability

9 ¡

slide-10
SLIDE 10

Limita:ons ¡

  • Fisher, ¡Lynch, ¡Pa3erson ¡(’85) ¡

Consensus ¡∩ ¡Determinis:c ¡∩ ¡Asynchronous ¡∩ ¡Faults ¡= ¡∅ ¡

¡

  • Brewer ¡(’00); ¡Gilbert ¡& ¡Lynch ¡(’06) ¡

Strongly-­‑consistent ¡∩ !Available ¡∩ ¡Par::on-­‑tolerant != !∅ ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 10 ¡

slide-11
SLIDE 11

Eventual ¡Consistency ¡

  • Availability ¡and ¡performance ¡
  • Crash-­‑recovery ¡fault-­‑model ¡
  • Update ¡each ¡replica ¡independently ¡

– Transport ¡to ¡other ¡replicas ¡and ¡apply ¡

  • Guaranteed ¡delivery: ¡eventually, ¡all ¡replicas ¡

receive ¡all ¡updates ¡ – But: ¡Order ¡of ¡updates ¡may ¡differ! ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 11 ¡

slide-12
SLIDE 12

Example: ¡Replicated ¡Integer ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 12 ¡

x ¡= ¡1 ¡ x ¡= ¡3 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ ??? ¡ ??? ¡ ??? ¡

  • Decentralized ¡conflict ¡resolu:on ¡

– ¡“conflict-­‑free ¡by ¡design” ¡ – No ¡user ¡interac:on ¡required ¡

  • How ¡are ¡updates ¡propagated? ¡
  • Generic ¡policy ¡vs. ¡data ¡type ¡specific ¡

– Seman:cs ¡of ¡concurrent ¡updates ¡based ¡on ¡abstract ¡data ¡type ¡

set(x,3) ¡ set(x,1) ¡

slide-13
SLIDE 13

Highest ¡:mestamp ¡wins ¡(LWW) ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡

x ¡= ¡3[12] ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡1[45] ¡ x ¡= ¡1[45] ¡

  • Generic ¡policy: ¡Symmetry ¡breaking ¡
  • Requires ¡total ¡order ¡on ¡updates ¡
  • Transmit ¡data ¡+ ¡:mestamp ¡(unique, ¡monotonically ¡growing) ¡
  • E.g. ¡global ¡clock ¡server, ¡synchronized ¡physical ¡clocks ¡
  • Widely ¡used: ¡file ¡systems, ¡key-­‑value ¡stores ¡

set(x,1); ¡t=45 ¡

x ¡= ¡3[12] ¡ x ¡= ¡1 ¡[45] ¡

set(x,3); ¡t=12 ¡ (x,3); ¡t=12 ¡ (x,3); ¡t=12 ¡ (x,1); ¡t=45 ¡

slide-14
SLIDE 14

Mul:-­‑value ¡registers ¡(MVR) ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡

x ¡= ¡3 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡{1,3} ¡ x ¡= ¡{1,3} ¡

  • Generic ¡policy ¡
  • No ¡automa:c ¡conflict ¡resolu:on, ¡requires ¡user ¡interac:on ¡
  • Widely ¡used ¡in ¡version ¡control ¡systems, ¡workflow ¡systems ¡

set(x,1) ¡

x ¡= ¡3 ¡ x ¡= ¡1 ¡

set(x,3) ¡ set(x,3) ¡ set(x,3) ¡ set(x,1) ¡ set(x,1) ¡

x ¡= ¡1 ¡

slide-15
SLIDE 15

Op-­‑based ¡counter ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡

x ¡= ¡3 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡0 ¡ x ¡= ¡4 ¡ x ¡= ¡4 ¡

  • Data-­‑type ¡specific: ¡Integer ¡ ¡-­‑> ¡Counter ¡ ¡
  • ADT ¡with ¡interface: ¡incrBy, ¡decrBy ¡
  • Send ¡opera:on ¡+ ¡params ¡to ¡other ¡replicas ¡

Re-­‑execute ¡opera:on ¡

  • Depending ¡on ¡communica:on ¡layer ¡

– Idempotence ¡ – Commuta:vity ¡ – Meta-­‑data ¡to ¡track ¡causality ¡

incrBy(x,1) ¡

x ¡= ¡3 ¡ x ¡= ¡1 ¡

incrBy(x,3) ¡ incrBy(x,3) ¡ incrBy(x,3) ¡ incrBy(x,1) ¡

slide-16
SLIDE 16

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡

update: ¡post ¡ She’s ¡coming! ¡ u:post ¡ Great! ¡ update: ¡post ¡ Let ¡me ¡call ¡her ¡ read ¡ read ¡ read ¡ update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ She’s ¡coming! ¡ update: ¡post ¡ Let ¡me ¡call ¡her ¡ u:post ¡ Great! ¡ update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ She’s ¡coming! ¡ update: ¡post ¡ Let ¡me ¡call ¡her ¡

!?! ¡

update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ Let ¡me ¡call ¡her ¡ read ¡ update: ¡post ¡ She’s ¡coming! ¡ u:post ¡ Great! ¡ read ¡ u:post ¡ Yay! ¡ u:post ¡ Yay! ¡ read ¡ read ¡ read ¡

16 ¡

slide-17
SLIDE 17

Causal ¡Consistency ¡

  • User-­‑friendly ¡
  • Subsumes ¡session ¡guarantees ¡read-­‑my-­‑writes, ¡monotonic ¡reads, ¡
  • etc. ¡
  • Strongest ¡always-­‑available ¡consistency ¡
  • Implementa:on: ¡ ¡VC, ¡graph. ¡ ¡Scale? ¡

+ ¡ + ¡ reads-­‑from ¡order ¡ transi:ve ¡closure ¡ client ¡invoca:on ¡order ¡

update: ¡post ¡ Jen ¡skips ¡the ¡party ¡ update: ¡post ¡ Let ¡me ¡call ¡her ¡ read ¡ update: ¡post ¡ She’s ¡coming! ¡ u:post ¡ Great! ¡ read ¡ u:post ¡ Yay! ¡ read ¡ read ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 17 ¡

slide-18
SLIDE 18

Vector ¡clocks ¡

  • Vi[j] ¡= ¡#events ¡of ¡j ¡observed ¡by ¡i ¡
  • Vi[j] ¡– ¡Vi’[j] ¡= ¡events ¡of ¡j ¡that ¡i’ ¡should ¡transmit ¡to ¡i ¡
  • V(a) ¡< ¡V(b) ¡= ¡a ¡happened ¡before ¡b ¡
  • V(a) ¡< ¡V(b) ¡∧ ¡V(b) ¡< ¡V(a) ¡= ¡a ¡concurrent ¡with ¡b ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 18 ¡

[0,0,0] ¡ [0,0,0] ¡ [0,0,0] ¡ [1,0,0] ¡ [0,0,1] ¡ [1,1,0] ¡ [1,2,0] ¡ [1,2,1] ¡ [1,2,1] ¡

slide-19
SLIDE 19

State-­‑based ¡counter ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡

[0,0,3] ¡ [0,0,0] ¡ [0,0,0] ¡ ¡ [0,0,0] ¡ ¡ [1,0,3] ¡ [1,0,3] ¡

  • Send ¡payload ¡(state, ¡VC) ¡+ ¡merge ¡
  • Don't ¡go ¡backwards ¡⟹ ¡par:al ¡order ¡
  • Apply ¡each ¡update ¡once ¡⟹ ¡idempotent ¡
  • Merge ¡in ¡any ¡order ¡⟹ ¡commuta:ve ¡
  • Merge ¡contains ¡several ¡updates ¡⟹ ¡associa:ve ¡

incrBy(x,1) ¡

[0,0,3] ¡ [1,0,0] ¡

incrBy(x,3) ¡ incrBy(x,3) ¡ incrBy(x,3) ¡ incrBy(x,1) ¡

[0,0,0] ¡ [1,0,0] ¡ [1,0,1] ¡ [1,0,1] ¡ [0,0,1] ¡ [0,0,0] ¡ [0,0,0] ¡ [0,0,1] ¡

slide-20
SLIDE 20

Specifica:on: ¡State-­‑based ¡Counter ¡

payload ¡integer[n] ¡P ¡ ¡ ¡initial ¡[0, ¡0, ¡..., ¡0] ¡ ¡ ¡ update ¡increment() ¡ ¡ ¡let ¡g ¡= ¡myID() ¡ ¡ ¡P[g] ¡:= ¡P[g] ¡+ ¡1 ¡ ¡ query ¡value() ¡: ¡integer ¡v ¡ ¡ ¡let ¡v ¡= ¡︎∑ ¡P[i] ¡ ¡ ¡ compare ¡(X,Y) ¡: ¡boolean ¡b ¡ ¡ ¡let ¡b ¡= ¡(∀i ¡∈ ¡[0, ¡n−1] ¡: ¡X.P[i] ¡≤ ¡Y.P[i]) ¡ ¡ merge ¡(X,Y) ¡: ¡payload ¡Z ¡ ¡ ¡let ¡∀i ¡∈ ¡[0, ¡n−1] ¡: ¡Z ¡.P ¡[i ¡] ¡= ¡max ¡(X.P[i], ¡Y.P[i]) ¡ ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 20 ¡

slide-21
SLIDE 21

Specifica:on: ¡State-­‑based ¡CRDT ¡

record ¡(’pl, ¡’ua, ¡’qa, ¡’r) ¡ ¡stateBasedType ¡= ¡ ¡ ¡t ¡compare ¡ ¡ ¡ ¡:: ¡” ¡’pl ¡⇒ ¡’pl ¡⇒ ¡bool ¡” ¡ ¡t ¡merge ¡ ¡ ¡:: ¡” ¡’pl ¡⇒ ¡’pl ¡⇒ ¡’pl ¡” ¡ ¡t ¡initial ¡ ¡ ¡:: ¡” ¡’pl ¡” ¡ ¡ ¡t ¡update ¡ ¡ ¡:: ¡” ¡’ua ¡⇒ ¡replicaId ¡⇒ ¡’pl ¡⇒ ¡’pl ¡” ¡ ¡ ¡ ¡ ¡t ¡query ¡ ¡ ¡ ¡ ¡ ¡:: ¡” ¡’qa ¡⇒ ¡’pl ¡⇒ ¡’r ¡” ¡ ¡ ¡

  • Compare ¡func:on ¡defines ¡par:al ¡order ¡ ¡
  • Updates ¡monotonically ¡increase ¡the ¡payload ¡ ¡
  • Merge ¡func:on ¡computes ¡least ¡upper ¡bound ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 21 ¡

slide-22
SLIDE 22

State-­‑based ¡Sets ¡

add(c) {c} merge({c}) {a, b, c} add(b) {a, b} add(a) {a} merge({a, b}) {a, b, c} replica 1 replica 2 {a} ∅ {b} {c} {a, c} {a, b} {b, c} {a, b, c}

Occasionally ¡send ¡local ¡ state ¡to ¡other ¡replicas ¡ Merge ¡received ¡state ¡by ¡type-­‑ specific ¡func:on, ¡e.g. ¡set ¡union ¡

contains(a)|T {a}

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 22 ¡

slide-23
SLIDE 23

Designing ¡for ¡conflict-­‑freedom ¡

replica j rem(b) {a, b} add(b) {a, b} merge({a, b}) {a, b, b} rem(a) {a, b} add(a) {a} add(b) {a, b} contains(b)|true {a, b, b} merge({a, b}) {a, b, b} merge({a}) {a} contains(a)|false {a, b, b} rem(b) {} ? add(b) {a, b} merge() {b} ? rem(a) {b} ? add(a) {a} add(b) {a, b} contains(b)|true {b} ? merge() {b} ? merge({a}) {a} contains(b)|true {b} ? merge() ?? contains(b)|?? ?? merge() ?? contains(b)|?? ?? replica i

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 23 ¡

{a}.add(a) ¡= ¡{a, ¡a} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡– ¡adds ¡unique ¡instance ¡of ¡a ¡(unique ¡color) ¡ {a, ¡b}.remove(a) ¡= ¡{a, ¡b} ¡ ¡ ¡ ¡– ¡set ¡hide ¡marker ¡on ¡known ¡instances ¡of ¡a ¡ {a, ¡a}.contains(a) ¡| ¡true ¡ ¡ ¡ ¡ ¡ ¡ ¡– ¡true ¡if ¡any ¡visible ¡instance ¡of ¡a ¡is ¡present ¡ {a, ¡b}.merge({b, ¡c}) ¡= ¡{a, ¡b, ¡c} ¡ ¡ ¡– ¡set ¡union, ¡preserving ¡hide ¡marker ¡ par@al ¡order ¡of ¡semi-­‑laDce ¡– ¡set ¡inclusion ¡on ¡elements ¡and ¡markers ¡

slide-24
SLIDE 24

Set ¡seman:cs ¡

Sequen:al ¡specifica:on ¡of ¡Set: ¡ {true} ¡add(e) ¡{e ¡∈ ¡S} ¡ ¡ ¡ ¡ ¡{true} ¡rmv(e) ¡{e ¡∉ ¡S} ¡ Commuta:ve ¡(e ¡≠ ¡f): ¡ {true} ¡ ¡add(e) ¡|| ¡add(e) ¡{e ¡∈ ¡S} ¡ ¡ ¡{true} ¡rmv(e) ¡|| ¡rmv(e) ¡{e ¡∉ ¡S} ¡ ¡ ¡{true} ¡add(e) ¡|| ¡add(f) ¡{e,f ¡∈ ¡S} ¡ ¡ ¡{true} ¡rmv(e) ¡|| ¡rmv(f) ¡{e,f ¡∉ ¡S} ¡ ¡ ¡{true} ¡add(e) ¡|| ¡rmv(f) ¡{e ¡∈ ¡S, ¡f ¡∉ ¡S} ¡ ¡ What ¡about: ¡ ¡ ¡{true} ¡add(e) ¡|| ¡rmv(e) ¡{????} ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 24 ¡

slide-25
SLIDE 25

{true} ¡ ¡add(e) ¡|| ¡rmv(e) ¡{?} ¡

  • 1. linearisable? ¡
  • 2. last ¡writer ¡wins?

¡ ¡ {add(e) ¡< ¡rmv(e) ¡⇒ ¡e ¡∉ ¡S ¡∧ ¡rmv(e) ¡< ¡add(e) ¡⇒ ¡e∈ ¡S ¡} ¡

  • 3. error ¡state? ¡ ¡ ¡ ¡ ¡ ¡ ¡{⊥e ¡∈ ¡S} ¡
  • 4. add ¡wins?

¡ ¡{e ¡∈ ¡S} ¡

  • 5. remove ¡wins? ¡{e ¡∉ ¡S} ¡
  • Determinis:c ¡
  • Independent ¡of ¡order ¡of ¡delivery ¡
  • Independent ¡of ¡local ¡state ¡
  • No ¡synchronisa:on ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 25 ¡

slide-26
SLIDE 26

Designing ¡for ¡conflict-­‑freedom: ¡add-­‑wins ¡set ¡

{a}.add(a) ¡= ¡{a, ¡a} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡– ¡adds ¡unique ¡instance ¡of ¡a ¡(unique ¡color) ¡ {a, ¡b}.remove(a) ¡= ¡{a, ¡b} ¡ ¡ ¡ ¡– ¡set ¡hide ¡marker ¡on ¡known ¡instances ¡of ¡a ¡ {a, ¡a}.contains(a) ¡| ¡true ¡ ¡ ¡ ¡ ¡ ¡ ¡– ¡true ¡if ¡any ¡visible ¡instance ¡of ¡a ¡is ¡present ¡ {a, ¡b}.merge({b, ¡c}) ¡= ¡{a, ¡b, ¡c} ¡ ¡ ¡– ¡set ¡union, ¡preserving ¡hide ¡marker ¡ par@al ¡order ¡of ¡semi-­‑laDce ¡– ¡set ¡inclusion ¡on ¡elements ¡and ¡markers ¡

replica j rem(b) {a, b} add(b) {a, b} merge({a, b}) {a, b, b} rem(a) {a, b} add(a) {a} add(b) {a, b} contains(b)|true {a, b, b} merge({a, b}) {a, b, b} merge({a}) {a} contains(a)|false {a, b, b} rem(b) {} ? add(b) {a, b} merge() {b} ? rem(a) {b} ? add(a) {a} add(b) {a, b} contains(b)|true {b} ? merge() {b} ? merge({a}) {a} contains(b)|true {b} ? merge() ?? contains(b)|?? ? ? merge() ?? contains(b)|?? ?? replica i

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 26 ¡

slide-27
SLIDE 27

Specifica:on: ¡State-­‑based ¡OR-­‑Set ¡

payload ¡set ¡E, ¡set ¡T ¡ ¡ ¡initial ¡∅, ¡∅ ¡ ¡ query ¡contains ¡(element ¡e) ¡: ¡boolean ¡b ¡ ¡ ¡let ¡b ¡= ¡(∃n ¡: ¡(e, ¡n) ¡∈ ¡E ¡∧ ¡(e, ¡n) ¡∉ ¡T ¡) ¡ ¡ update ¡add ¡(element ¡e) ¡ ¡ ¡let ¡n ¡= ¡unique() ¡ ¡in ¡ ¡E ¡:= ¡E ¡∪{(e, ¡n)} ¡ ¡ update ¡remove ¡(element ¡e) ¡ ¡ ¡let ¡R ¡= ¡{(e,n) ¡: ¡(e,n) ¡∈ ¡E ¡∧ ¡e ¡= ¡e ¡} ¡ ¡in ¡ ¡T ¡:= ¡T ¡∪ ¡R ¡ ¡ compare ¡(A,B) ¡: ¡boolean ¡b ¡ ¡ ¡let ¡b ¡= ¡(A.E ¡⊆ ¡B.E) ¡∧ ¡(A.T ¡⊆ ¡B.T) ¡ ¡ merge ¡(B) ¡ ¡ ¡E ¡:= ¡E ¡∪ ¡B.E ¡ ¡ ¡T ¡:= ¡T ¡∪ ¡B.T ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 27 ¡

slide-28
SLIDE 28

Correctness ¡of ¡CRDTs ¡

¡

  • 1. ¡Convergence ¡

¡If ¡two ¡replicas ¡have ¡seen ¡the ¡same ¡set ¡of ¡updates, ¡ ¡

¡do ¡they ¡have ¡the ¡same ¡state? ¡

  • 2. Seman@cs ¡

¡If ¡a ¡replica ¡has ¡seen ¡a ¡given ¡set ¡of ¡updates, ¡

¡what ¡is ¡the ¡state ¡of ¡the ¡replica? ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 28 ¡

slide-29
SLIDE 29

Challenges: ¡Programming ¡model ¡

Specifica:on ¡(add-­‑wins-­‑set): ¡ ¡ “Remove ¡opera@on ¡deletes ¡only ¡elements ¡from ¡the ¡ set ¡that ¡have ¡been ¡observed ¡at ¡the ¡replica ¡issuing ¡the ¡ remove ¡opera@on. ¡ ︎When ¡concurrently ¡adding ¡the ¡element ¡(again), ¡it ¡ will ¡remain ¡in ¡the ¡set.” ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 29 ¡

slide-30
SLIDE 30

Challenge: ¡Programming ¡model ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 30 ¡

slide-31
SLIDE 31

1.Approach: ¡Concurrent ¡Specifica:ons ¡

  • Problem: ¡Not ¡every ¡execu:on ¡can ¡be ¡expressed ¡as ¡a ¡

combina:on ¡of ¡parallel ¡and ¡sequen:al ¡opera:ons. ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 31 ¡

c a d

merge ¡

c a d

merge ¡

?? ¡

b

a; (c||d)

slide-32
SLIDE 32
  • 2. ¡Approach: ¡Merge ¡Specifica:on ¡

⇒ ¡Not ¡possible ¡to ¡specify ¡merge ¡completely, ¡ when ¡pre-­‑condi:ons ¡depend ¡only ¡on ¡visible ¡ state ¡of ¡S1 ¡and ¡S2 ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 32 ¡

{x / ∈ S1 ∧ x / ∈ S2} S = merge(S1, S2) {x / ∈ S} {x ∈ S1 ∧ x ∈ S2} S = merge(S1, S2) {?}

slide-33
SLIDE 33
  • 2. ¡Approach: ¡Merge ¡Specifica:on ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 33 ¡

Add ¡more ¡informa:on ¡to ¡precondi:on: ¡

  • use ¡internal, ¡unique ¡iden:fier ¡i ¡for ¡elements. ¡
  • use ¡common ¡pre-­‑state ¡S1⊓2 ¡

¡ Disadvantages: ¡

  • Closer ¡to ¡implementa:on ¡
  • State ¡S1⊓2 ¡might ¡not ¡exist ¡in ¡execu:on ¡ ¡

¡

{xi ∈ S1 ∧ xi ∈ S2 ∧ xi ∈ S1u2} S = merge(S1, S2) {xi ∈ S} {(xi / ∈ S1 ∨ xi / ∈ S2) ∧ xi ∈ S1u2} S = merge(S1, S2) {xi / ∈ S} {(xi ∈ S1 ∨ xi ∈ S2) ∧ xi / ∈ S1u2} S = merge(S1, S2) {xi ∈ S} {xi / ∈ S1 ∧ xi / ∈ S2 ∧ xi / ∈ S1u2} S = merge(S1, S2) {xi / ∈ S}

slide-34
SLIDE 34
  • 3. ¡Specifica:on ¡based ¡on ¡history ¡

¡

  • E: ¡set ¡of ¡all ¡visible ¡events ¡
  • op(e): ¡opera:on ¡executed ¡at ¡event ¡e ¡
  • a ¡≺ ¡b: ¡Event ¡a ¡happened ¡before ¡event ¡b ¡ ¡
  • Merges ¡are ¡only ¡indirectly ¡visible ¡(via ¡≺) ¡ ¡
  • A ¡specifica:on ¡in ¡this ¡form ¡can ¡be ¡turned ¡into ¡an ¡

implementa:on ¡by ¡recording ¡the ¡events ¡and ¡happens-­‑ before ¡rela:on ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 34 ¡

x 2 S $ ✓ 9ea∈E. op(ea) = add(x) ^ (@er∈E. ea er ^ op(er) = remove(x)) ◆

slide-35
SLIDE 35

Verifica:on ¡of ¡State-­‑based ¡CRDTs ¡in ¡ Isabelle/HOL ¡(Zeller ¡et ¡al. ¡FORTE ¡’14) ¡

  • Idea: ¡Provide ¡invariant ¡rela:ng ¡the ¡payload ¡of ¡a ¡replica ¡

with ¡the ¡visible ¡update ¡history ¡

  • Show ¡that ¡invariant ¡implies ¡specifica:on ¡for ¡all ¡queries, ¡

holds ¡for ¡ini:al ¡payload ¡and ¡under ¡no ¡events, ¡and ¡is ¡ preserved ¡by ¡updates ¡and ¡merges ¡

  • Verified ¡CRDTs: ¡

– Counter ¡(Increment-­‑only ¡Counter, ¡PN-­‑Counter ¡) ¡ ¡ – Mul:-­‑Value ¡Register ¡ – Sets ¡(Grow-­‑only-­‑Set, ¡2-­‑phase ¡Set, ¡Observed-­‑Remove ¡Set ¡ (Simple, ¡op:mized)) ¡

  • Found ¡minor ¡bug ¡in ¡an ¡MV-­‑register ¡implementa:on ¡

(Assigning ¡the ¡empty ¡set ¡was ¡not ¡an ¡increasing ¡update) ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 35 ¡

slide-36
SLIDE 36

Related ¡work: ¡ Understanding ¡Eventual ¡Consistency ¡

(Burckhardt, ¡Gotsman, ¡Yang ¡[TR ¡’13, ¡POPL’14]) ¡ ¡

  • General ¡framework ¡for ¡formal ¡and ¡declara:ve ¡

specifica:on ¡of ¡seman:cs ¡using ¡axioms ¡

  • Opera:on ¡context ¡C ¡= ¡(op, ¡V, ¡ar, ¡vis) ¡
  • Data ¡type ¡specifica:on ¡Fτ(C) ¡specifies ¡return ¡

value ¡ ¡

  • Correctness ¡proofs ¡via ¡replica:on-­‑aware ¡

simula:ons ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 36 ¡

slide-37
SLIDE 37

Related ¡work: ¡Verifying ¡Eventual ¡Consistency ¡of ¡ Op:mis:c ¡Replica:on ¡Systems ¡ ¡

(Bouajjani, ¡Enea, ¡Hamza ¡[POPL ¡’14]) ¡

  • Based ¡on ¡traces, ¡i.e. ¡poset ¡of ¡opera:ons, ¡where ¡
  • pera:ons ¡submi3ed ¡to ¡one ¡site ¡are ¡totally ¡
  • rdered ¡
  • Specifica:on ¡associates ¡return ¡values ¡of ¡
  • pera:ons ¡with ¡posets ¡of ¡opera@ons ¡(-­‑> ¡local ¡

interpreta@on) ¡

  • Covers ¡addi:onally ¡specula:ve ¡execu:ons ¡and ¡

rollbacks ¡ ¡

  • Liveness: ¡Correct ¡local ¡interpreta:ons ¡

convergence ¡eventually ¡(-­‑> ¡global ¡interpreta@on) ¡

  • Verifica:on ¡by ¡reachability ¡and ¡model ¡checking ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 37 ¡

slide-38
SLIDE 38

Opera:on-­‑based ¡updates ¡

  • All ¡replicas ¡have ¡equivalent ¡state ¡in ¡the ¡end ¡
  • Sufficient ¡condi:on ¡

– Reliable ¡causal ¡delivery ¡⇒ ¡Vector ¡clocks ¡ – Concurrent ¡opera:ons ¡commute ¡

¡

add(c) {a, c} add(c) {a, b, c} add(b) {a, b} add(a) {a} add(b) {a, b, c} replica i replica j add(a) {a}

Send ¡update ¡to ¡other ¡replicas ¡ Replay ¡(re-­‑execute) ¡every ¡update ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 38 ¡

slide-39
SLIDE 39

CHALLENGES ¡AND ¡LIMITATIONS ¡ WHEN ¡PROGRAMMING ¡WITH ¡CRDTS ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 39 ¡

slide-40
SLIDE 40

Challenges: ¡Causality ¡tracking ¡

  • Tracking ¡causality ¡requires ¡in ¡general ¡meta-­‑

data ¡O(#clients) ¡

  • High ¡churn ¡is ¡typical: ¡Clients ¡might ¡crash ¡and ¡

never ¡return ¡

  • Garbage ¡collec:ng ¡obsolete ¡informa:on ¡only ¡

a{er ¡consensus ¡

  • Trick ¡(see ¡work ¡by ¡Baquero ¡et ¡al.): ¡Employ ¡

informa:on ¡from ¡transport ¡layer ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 40 ¡

slide-41
SLIDE 41

Challenges: ¡Atomic ¡updates ¡

  • Scenario: ¡Friendship ¡management ¡

– Requests ¡shouldn’t ¡get ¡lost ¡

  • Scenario: ¡Virtual ¡wallet ¡

– User ¡can ¡exchange ¡(virtual) ¡currency ¡for ¡vouchers, ¡ game ¡items, ¡... ¡ – No ¡money ¡lost! ¡ – No ¡voucher ¡used ¡twice! ¡

  • ︎ ¡Opera:on ¡should ¡be ¡atomic ¡across ¡keys ¡(-­‑> ¡

transac:ons) ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 41 ¡

slide-42
SLIDE 42

Challenges: ¡Bounded ¡divergence ¡

  • Scenario: ¡Ad ¡coun:ng ¡

– ︎ ¡ ¡Adver:sement ¡should ¡be ¡displayed ¡a ¡limited ¡ number ¡of ¡:mes ¡to ¡users ¡in ¡a ¡certain ¡area ¡/ ¡ country ¡

  • ︎Keeping ¡track ¡of ¡how ¡o{en ¡it ¡is ¡displayed ¡

requires ¡counters ¡to ¡deal ¡with ¡high ¡conten:on ¡

  • ︎Es:mated ¡count ¡of ¡delivered ¡ads ¡should ¡not ¡

diverge ¡too ¡much ¡from ¡actual ¡number ¡

  • ︎For ¡a ¡wallet: ¡No ¡divergence! ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 42 ¡

slide-43
SLIDE 43

Summary ¡

  • ReplicaKng ¡data ¡requires ¡consistency ¡

handling ¡

  • High ¡availability ¡precludes ¡strong ¡

synchroniza:on ¡

  • Tame ¡eventual ¡consistency ¡by ¡determinis:c, ¡

sound ¡“conflict” ¡handling ¡

  • Replicated ¡Data ¡Types ¡with ¡state-­‑based ¡/ ¡op-­‑

based ¡update ¡propaga:on ¡

– Counters, ¡Registers, ¡Sets, ¡Maps, ¡Graphs ¡ ¡

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 43 ¡

slide-44
SLIDE 44

Anne3e ¡Bieniusa ¡-­‑ ¡Scalable ¡Consistency ¡ 44 ¡

slide-45
SLIDE 45

Acknowledgements ¡

Marek ¡Zawirski ¡ ¡Inria ¡& ¡UPMC-­‑LIP6 ¡ Nuno ¡Preguiça ¡ ¡U. ¡Nova ¡de ¡Lisboa ¡ Sérgio ¡Duarte ¡ ¡U. ¡Nova ¡de ¡Lisboa ¡ ¡ Valter ¡Balegas ¡ ¡U. ¡Nova ¡de ¡Lisboa ¡ Carlos ¡Baquero ¡U. ¡do ¡Minho ¡& ¡HASLab ¡ Marc ¡Shapiro ¡ ¡Inria ¡& ¡LIP6 ¡ Peter ¡Zeller ¡ ¡TU ¡Kaiserslautern ¡ Chris ¡Meiklejohn ¡Basho ¡ ¡ And ¡probably ¡a ¡few ¡more... ¡