Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala With Cats: Case Study: CRDTs

Kurochan
August 07, 2018
150

Scala With Cats: Case Study: CRDTs

Kurochan

August 07, 2018
Tweet

More Decks by Kurochan

Transcript

  1. CRDTs • Commutative Replicated Data Types • or Conflict-free Replicated

    Data Types • ݁Ռ੔߹ੑͷ͋Δσʔλߏ଄ • ϞϊΠυ͕ͲͷΑ͏ʹ໾ཱ͔ͭͷྫͱͯ͠CRDTsΛ঺հ
  2. Eventual Consistency • લϖʔδͷྫͩͱ੔߹ੑ͕อͯΔ͕ɺ1ͭͷૢ࡞ͷͨΊʹશ୆ ͱಉظΛͱΔͷͰϨΠςϯγ͕ѱԽ͢Δ • ωοτϫʔΫো֐ʹΑΔ෼அ΋ൃੜ͢Δ • ੔߹ੑΛอͭͨΊʹ͸ૢ࡞Λڋ൱͢Δ͔͠ͳ͍ •

    ݁Ռ੔߹ੑͷ͋ΔγεςϜͰ͸֤Ϛγϯ͕Ұ࣌తʹҟͳΔ
 ঢ়ଶΛ࣋ͭࣄΛڐ༰͢Δ • ݁Ռతʹ੔߹ੑ͕औΕΕ͹͍͍ͷͰૢ࡞ʹର͢ΔԠ౴͸
 ૣ͘ͳΔ • ωοτϫʔΫো֐ʹΑΔ෼அ͕ൃੜͯ͠΋ॲཧΛܧଓͰ͖Δ
  3. 11.2.3 Exercise: GCounter Implementation • G-CounterΛ࣮૷ͯ͠Έ·͠ΐ͏ • counter: Map[String, Int]

    • key͕machine id, value͕Χ΢ϯτ • increment: GCounter • ࢦఆͨ͠machineͷΧ΢ϯτΛࢦఆͨ͠
 amount͚ͩ଍͢ • merge: GCounter • 2ͭͷGCounterΛϚʔδ͢Δ
  4. Generalisation • ͖͞΄ͲͷG-CounterΛந৅Խ͍ͯ͘͠ • G-Counter͸ • Ճࢉ: ΠϯΫϦϝϯτ͞Εͨ߹ܭ஋Λ࣋ͭ • ࠷େ஋:

    Ϛʔδ࣌͸࠷େ஋Λ࣋ͭ • ॳظ஋͸ 0 • => ϞϊΠυͰ͋Δ • (a + b) + c == a + (b + c) • 0 + a == a + 0 == a • a max a = a (mergeͷૢ࡞͸ႈ౳ੑ͕͋Δ)
  5. Generalisation • ͖͞΄ͲͷG-CounterΛந৅Խ͍ͯ͘͠ • increment: monoid • total: monoid +

    Մ׵ • merge: monoid + ႈ౳ + Մ׵ • => ༗ք൒ଋͱݴ͏