proving weakly consistent applications correct
play

Proving Weakly Consistent Applications Correct Alexey Gotsman - PowerPoint PPT Presentation

Proving Weakly Consistent Applications Correct Alexey Gotsman IMDEA Software Institute, Madrid, Spain Joint work with Hongseok Yang (Oxford), Carla Ferreira (U Nova Lisboa), Mahsa Najafzadeh, Marc Shapiro (INRIA) Eventually consistent


  1. Proving Weakly Consistent Applications Correct Alexey Gotsman IMDEA Software Institute, Madrid, Spain Joint work with Hongseok Yang (Oxford), Carla Ferreira (U Nova Lisboa), Mahsa Najafzadeh, Marc Shapiro (INRIA)

  2. Eventually consistent databases deposit(100) • No synchronisation: process an update locally, propagate effects to other replicas later • Weakens consistency: deposit seen with a delay

  3. balance ≥ 0 balance = 100 balance = 100

  4. balance ≥ 0 balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ balance = 0 balance = 0

  5. balance ≥ 0 balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ balance = 0 balance = 0 balance = -100

  6. balance ≥ 0 balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ balance = 0 balance = 0 balance = -100 deposit(100)

  7. balance ≥ 0 balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ balance = 0 balance = 0 balance = -100 Tune consistency: • Withdrawals strongly consistent deposit(100) • Deposits eventually consistent

  8. Consistency choices • Databases with multiple consistency levels: ‣ Commercial: Amazon DynamoDB, Basho Riak, Microsoft DocumentDB ‣ Research: Li + OSDI’12; Terry + SOSP’13; Balegas + EuroSys’15... • Pay for stronger semantics with latency, possible unavailability and money • Hard to figure out the minimum consistency necessary to maintain correctness - proof rule and tool

  9. Consistency model • Generic model - not implemented, but can encode many existing models that are: RedBlue consistency [Li + 2012], reservation locks [Balegas + 2015], parallel snapshot isolation [Sovran + 2011], ... • Causal consistency as a baseline: observe an update ➜ observe the updates it depends on • A construct for strengthening consistency on demand

  10. Operation semantics σ op ⟦ op ⟧ val Replica states: σ ∈ State Return value: ⟦ op ⟧ val ∈ State ➞ Value

  11. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) Replica states: σ ∈ State Return value: ⟦ op ⟧ val ∈ State ➞ Value Effector: ⟦ op ⟧ eff ∈ State ➞ (State ➞ State)

  12. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) Replica states: σ ∈ State Return value: ⟦ op ⟧ val ∈ State ➞ Value Effector: ⟦ op ⟧ eff ∈ State ➞ (State ➞ State)

  13. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ Effector ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) Replica states: σ ∈ State Return value: ⟦ op ⟧ val ∈ State ➞ Value Effector: ⟦ op ⟧ eff ∈ State ➞ (State ➞ State)

  14. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ Effector ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) Replica states: σ ∈ State Return value: ⟦ op ⟧ val ∈ State ➞ Value Effector: ⟦ op ⟧ eff ∈ State ➞ (State ➞ State)

  15. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) State = Z ⟦ balance() ⟧ val ( σ ) = σ ⟦ balance() ⟧ eff ( σ ) = λσ . σ

  16. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ deposit(100) ⟧ eff ( σ ) = λσʹ . ( σʹ + 100)

  17. Operation semantics σ op ⟦ op ⟧ eff ( σ ) 50 ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ deposit(100) ⟧ eff ( σ ) = λσʹ . ( σʹ + 100)

  18. Operation semantics σ op ⟦ op ⟧ eff ( σ ) 50 ⟦ op ⟧ val 150 ⟦ deposit(100) ⟧ eff ( σ ) = λσʹ . ( σʹ + 100)

  19. Ensuring eventual consistency • Effectors have to commute • Eventual consistency: replicas receiving the same messages in different orders end up in the same state • Replicated data types [Shapiro + 2011]: ready-made commutative implementations ⟦ deposit(100) ⟧ eff ( σ ) = λσʹ . ( σʹ + 100)

  20. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  21. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  22. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  23. Operation semantics σ op ⟦ op ⟧ eff ( σ ) σʹ ⟦ op ⟧ val ⟦ op ⟧ eff ( σ )( σʹ ) ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  24. balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ λσʹ . σʹ - 100 balance = 0 balance = 0 ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  25. balance = 100 balance = 100 withdraw(100) : ✔ withdraw(100) : ✔ λσʹ . σʹ - 100 balance = 0 balance = 0 balance = -100 ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  26. Strengthening consistency Token system ≈ locks on steroids: • Token = { τ 1 , τ 2 , ...} • Symmetric conflict relation ⋈ ⊆ Token × Token

  27. Strengthening consistency Token system ≈ locks on steroids: • Token = { τ 1 , τ 2 , ...} • Symmetric conflict relation ⋈ ⊆ Token × Token Example - mutual exclusion lock: Token = { τ }; τ ⋈ τ

  28. Strengthening consistency Token system ≈ locks on steroids: • Token = { τ 1 , τ 2 , ...} • Symmetric conflict relation ⋈ ⊆ Token × Token Example - mutual exclusion lock: Token = { τ }; τ ⋈ τ Each operation associated with a set of tokens: ⟦ op ⟧ tok ∈ State ➞ P (Token)

  29. Operations associated with conflicting tokens cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ }

  30. Operations associated with conflicting tokens cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ } withdraw(100) : ? { τ } Anything I don’t know about?

  31. Operations associated with conflicting tokens cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ } balance = 0 withdraw(100) : ? { τ }

  32. Operations associated with conflicting tokens cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ } balance = 0 withdraw(100) : ✘ { τ }

  33. Operations associated with conflicting tokens cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ } balance = 0 deposit(100) withdraw(100) : ✘ ∅ { τ } No synchronisation

  34. Operations associated with conflicting tokens Do we always have I = (balance ≥ 0)? cannot be unaware of each other τ ⋈ τ balance = 100 balance = 100 withdraw(100) : ✔ { τ } balance = 0 deposit(100) withdraw(100) : ✘ ∅ { τ } No synchronisation

  35. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ? Effect applied in a different state!

  36. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ? ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... ⟦ withdraw(100) ⟧ eff ( σ ) = if σ ≥ 100 then ( λσʹ . σʹ - 100) else ( λσʹ . σʹ )

  37. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ? ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... 1. Effector safety: f preserves I when executed in any state satisfying P

  38. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ✔ ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... 1. Effector safety: f preserves I when executed in any state satisfying P

  39. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f P( σʹ ) ? σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ✔ ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... 1. Effector safety: f preserves I when executed in any state satisfying P

  40. σ ∈ I o op p ⟦ ( σ ⟧ ) e f f P( σʹ ) ? σʹ ⟦ op ⟧ eff ( σ )( σʹ ) ∈ I ✔ ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... 1. Effector safety: f preserves I when executed in any state satisfying P 2. Precondition stability: P will hold when f is applied at any replica

  41. CISE tool: ‘Cause I’m Strong Enough Discharges proof obligations using Z3 SMT solver By Mahsa Najafzadeh (UPMC & INRIA) ⟦ op ⟧ eff ( σ ) = if P( σ ) then f( σ ) else if... 1. Effector safety: f preserves I when executed in any state satisfying P 2. Precondition stability: P will hold when f is applied at any replica

  42. 31

  43. 1. Effector safety: f preserves I when executed in any state satisfying P 32

  44. 1. Effector safety: f preserves I when executed in any state satisfying P ✔ 32

  45. 2. Precondition stability: P is preserved by concurrent operations 33

  46. 2. Precondition stability: P is preserved by concurrent operations 33

  47. 2. Precondition stability: P is preserved by concurrent operations Bug: concurrent withdrawals may violate the invariant 33

  48. 2. Precondition stability: P is preserved by concurrent operations Add a token restricting concurrency 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend