just right consistency closing the cap gap
play

Just-Right Consistency Closing the CAP Gap Christopher S. Meiklejohn - PowerPoint PPT Presentation

Just-Right Consistency Closing the CAP Gap Christopher S. Meiklejohn (@cmeik), Peter Lash LIGHT ONE Outline: Closing the CAP Gap Just-Right Consistency Available as possible, and consistent when necessary 2 Outline: Closing the CAP


  1. Fælles Medicinkort • FMK [production] / FMKe [synthetic workload] 
 Danish National Joint Medicine Card; operating 24x7 since 2013 for 6 million Danish citizens • Lifecycle management for prescriptions 
 Involves patient, pharmacy, and doctor management around active prescriptions in Denmark • Assumed correct in isolation 
 “Correct-Individually”, C in ACID, each operation ensures application-level invariants 15

  2. Fælles Medicinkort • create-prescription 
 Create prescription for patient, doctor, pharmacy • FMK [production] / FMKe [synthetic workload] 
 Danish National Joint Medicine Card; operating 24x7 • update-prescription-medication 
 since 2013 for 6 million Danish citizens Add or increase medication to prescription • Lifecycle management for prescriptions 
 Involves patient, pharmacy, and doctor management • process-prescription 
 around active prescriptions in Denmark Deliver a medication by a pharmacy • Assumed correct in isolation 
 • get-*-prescriptions 
 “Correct-Individually”, C in ACID, each operation ensures application-level invariants Query functions to return information about prescriptions 15

  3. FMKe Invariants • Relative order [referential integrity] 
 Create a prescription and reference it by a patient 16

  4. FMKe Invariants • Relative order [referential integrity] 
 Create a prescription and reference it by a patient • Joint update [atomicity] 
 Create prescription, then update doctor, patient, and pharmacy 16

  5. FMKe Invariants • Relative order [referential integrity] 
 Create a prescription and reference it by a patient • Joint update [atomicity] 
 Create prescription, then update doctor, patient, and pharmacy • Precondition check [if, then] 
 Medication should not be over delivered 16

  6. Invariants AP-compatible 17

  7. AP-compatible • No synchronization 
 Updates occur locally without blocking, no synchronization in the critical path 18

  8. AP-compatible • No synchronization 
 Updates occur locally without blocking, no synchronization in the critical path • Asynchronous operation 
 Updates are fast, available, and exploit concurrency 18

  9. AP-compatible • No synchronization 
 Updates occur locally without blocking, no synchronization in the critical path • Asynchronous operation 
 Updates are fast, available, and exploit concurrency • Compatible invariants 
 Relative order and joint update invariants can be preserved 18

  10. AP-compatibe Data Model 19

  11. RA RB

  12. set(1) RA 1 RB

  13. set(1) set(2) RA 1 2 RB 3 set(3)

  14. set(1) set(2) RA 1 2 3 RB 2 3 set(3) Concurrent assignments don’t commute!

  15. set(1) set(2) RA 1 2 3 Assignment requires CP . RB 2 3 set(3) Concurrent assignments don’t commute!

  16. Can we find a suitable data model for AP systems? 24

  17. Can we find a suitable data model for AP systems? Can we make non-commutative updates commutative? 24

  18. How do we deterministically pick a value to keep? set(1) set(2) RA 1 2 ? RB ? 3 set(3)

  19. How do we deterministically pick a value to keep? set(1) set(2) RA 1 2 ? RB ? 3 set(3) Do we use a timestamp? (like Cassandra, and drop a value?)

  20. Timestamps make concurrent How do we deterministically pick operations commute a value to keep? but fail to capture intent. set(1) set(2) RA 1 2 ? RB ? 3 set(3) Do we use a timestamp? (like Cassandra, and drop a value?)

  21. Can we be smarter about the merge function? 26

  22. Deterministic conflict resolution function. set(1) set(2) max(2,3) RA 1 2 3 max(2,3) RB 3 3 set(3)

  23. Deterministic conflict resolution function. set(1) set(2) max(2,3) RA 1 2 3 max(2,3) RB 3 3 set(3) CRDTs generalize this framework.

  24. Conflict-Free 
 Replicated Data Types • Replicated abstract data types 
 Extension of sequential data type that encapsulates deterministic merge function 28

  25. Conflict-Free 
 Replicated Data Types • Replicated abstract data types 
 Extension of sequential data type that encapsulates deterministic merge function • Many existing designs 
 Sets, counters, registers, flags, maps 28

  26. AP-compatibe Relative Order 29

  27. RA RB

  28. Maintain program order implication invariant. RA RB

  29. Maintain program order implication invariant. RA RB For instance, P => Q.

  30. true(Q) RA Q RB Make Q true.

  31. true(Q) true(P) RA Q P RB Make P true.

  32. Program order implies ordering relationship. true(Q) true(P) RA Q P RB

  33. true(Q) true(P) RA Q P RB Ordering is respected at other replicas.

  34. true(Q) true(P) RA Q P RB Out of order propagation violates invariant!

  35. true(Q) true(P) RA Q P RB P is true, Q is NOT true!

  36. Let’s look at a concrete example. 37

  37. RA RB

  38. true(Q) RA Q RB Change default administrator password.

  39. true(Q) true(P) RA Q P RB Enable administrator login.

  40. Replica A is secure. true(Q) true(P) RA Q P RB

  41. true(Q) true(P) RA Q P RB Replica B is secure.

  42. true(Q) true(P) RA Q P RB Reordering allows default password to be used to login!

  43. Causal Consistency • Respect causality 
 Ensure updates are delivered in the causal order 
 [Lamport 78] 44

  44. Causal Consistency • Respect causality 
 Ensure updates are delivered in the causal order 
 [Lamport 78] • Strongest available model 
 Always able to return some compatible version for an object 44

  45. Causal Consistency • Respect causality 
 Ensure updates are delivered in the causal order 
 [Lamport 78] • Strongest available model 
 Always able to return some compatible version for an object • Referential integrity 
 Causal consistency is sufficient for providing referential integrity in an AP database 44

  46. Causal consistency means… …relative order invariants are preserved transparently! 45

  47. AP-compatibe Joint Update 46

  48. RA RB C1 Client performing reads.

  49. Create prescription. create Rx RA Rx RB C1

  50. Add reference in doctor record. create Rx update Dr(Rx) RA Rx Dr RB C1

  51. Add reference in patient record. create Rx update Dr(Rx) update Pt(Rx) RA Rx Dr Pt RB C1

  52. Add reference in pharmacy record. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA Rx Dr Pt Ph RB C1

  53. Updates are causally consistent. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA Rx Dr Pt Ph RB C1

  54. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA Rx Dr Pt Ph RB C1 Client can read inconsistent state.

  55. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA Rx Dr Pt Ph RB C1 Client is missing update to pharmacy.

  56. Can we ensure updates are All-or-Nothing? 55

  57. Group updates into an atomic transaction. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA T1 RB C1

  58. Updates reflect “All-Or-Nothing” property through snapshots. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA T1 RB C1

  59. Transactions are delivered in causal order. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA T1 T2 RB C1

  60. Therefore, snapshots are causally consistent. create Rx update Dr(Rx) update Pt(Rx) update Ph(Rx) RA T1 T2 RB C1

  61. AP-compatible transactions provide the “A” in ACID 60

  62. Transactional Causal Consistency Strongest model that is available (AP) 61

  63. Invariants CAP-sensitive 62

  64. What about preventing over delivery of prescriptions? 63

  65. Three replicas each with two available medications. RA(2) ? RB(2) ? RC(2) ?

  66. Replica A checks precondition and delivers medication. pp(1) RA(2) 1 1 RB(2) 1 RC(2) 1

Recommend


More recommend