reasoning about consistency choices in distributed systems
play

Reasoning about consistency choices in distributed systems Hongseok - PowerPoint PPT Presentation

Reasoning about consistency choices in distributed systems Hongseok Yang University of Oxford Joint work with Alexey Gotsman (IMDEA, Spain), Carla Ferreira (U Nova Lisboa), Mahsa Najafzadeh, Marc Shapiro (INRIA) Global-scale Internet service


  1. Reasoning about consistency choices in distributed systems Hongseok Yang University of Oxford Joint work with Alexey Gotsman (IMDEA, Spain), Carla Ferreira (U Nova Lisboa), Mahsa Najafzadeh, Marc Shapiro (INRIA)

  2. Global-scale Internet service

  3. Geo-replicated databases • Every data centre stores a complete replica of data • Purpose: Minimising latency. Fault tolerance.

  4. Geo-replicated databases • Every data centre stores a complete replica of data • Purpose: Minimising latency. Fault tolerance.

  5. Geo-replicated databases ✘ • Every data centre stores a complete replica of data • Purpose: Minimising latency. Fault tolerance.

  6. Weakly consistent DBs {(A,4)} ✘ {(A,4)} {(A,4)} First update. Propagate later.

  7. Weakly consistent DBs cart.rem(A,2) cart.read() : {A} {(A,4)} ✘ {(A,4)} {(A,2)} First update. Propagate later.

  8. Weakly consistent DBs cart.rem(A,2) cart.read() : {A} {(A,4)} ✘ {(A,4)} {(A,2)} First update. Propagate later.

  9. Weakly consistent DBs cart.rem(A,2) cart.read() : {A} {(A,4)} ✘ {(A,2)} {(A,2)} First update. Propagate later.

  10. Weakly consistent DBs cart.rem(A,2) cart.count(A): 4 {(A,4)} ✘ {(A,2)} {(A,2)} Issue 1: Anomalies First update. Propagate later.

  11. Weakly consistent DBs cart.rem(A,2) cart.count(A): 4 cart.remAll(A) {(A,0)} ✘ {(A,2)} {(A,2)} Issue 2: Conflicting updates First update. Propagate later.

  12. Weakly consistent DBs cart.rem(A,2) cart.count(A): 4 rem(A,2) cart.remAll(A) {(A,0)} ✘ remAll(A) {(A,2)} {(A,2)} Issue 2: Conflicting updates First update. Propagate later.

  13. How to develop correct programs running on top of weakly consistent distributed databases?

  14. How to develop correct programs running on top of weakly consistent distributed databases? 1. Strengthen consistency selectively. 2. Use rely-guarantee reasoning.

  15. How to develop correct programs running on top of weakly consistent distributed databases? 1. Strengthen consistency selectively. 2. Prove the correctness of a program.

  16. Simple bank account class account { // invariant: amount >= 0 var amount = 0 def query() = { return amount } def inc() = { amount = amount+1; return true } def dec() = { if (amount > 0) { amount = amount-1; return true } else { return false } } }

  17. Distributed bank account class account { // invariant: amount >= 0 var[dis] amount = 0 def query() = { return (amount, (a)=>a) } def inc() = { amount = amount+1; return (true, (a)=>a+1) } def dec() = { if (amount > 0) { amount = amount-1; return (true, (a)=>a-1) } else { return (false, (a)=>a) } } }

  18. Alice dec() in Korea Bob inc() dec() in UK Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  19. Alice dec() in Korea Bob inc() dec() in UK Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  20. Alice dec() in Korea Bob inc() dec() in UK Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  21. Alice dec() in Korea a++ Bob inc() dec() in UK a++ Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  22. Alice dec() in Korea a— a++ Bob inc() dec() in UK a++ a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  23. Alice dec() in Korea a— a++ Bob inc() dec() in UK a++ a— skip Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  24. Alice dec() in Korea Bob inc() dec() in UK Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  25. Alice dec() in Korea a++ Bob inc() dec() in UK a++ Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  26. Alice dec() in Korea a++ Bob inc() dec() in UK a++ a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  27. Alice dec() in Korea a++ Bob inc() dec() in UK a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  28. Alice dec() in Korea a++ Bob inc() dec() in UK a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  29. Alice dec() in Korea a++ Bob inc() dec() in UK a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  30. How to write correct prog.? 1. Strengthen consistency selectively. 2. Prove the correctness of a program.

  31. Causal consistency • Message delivery preserves the dependency of events. Axiom: HB is transitive.

  32. Alice dec() in Korea a++ Bob inc() dec() in UK a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  33. Alice dec() in Korea a++ Bob inc() dec() in UK a++ a— a— Carol query() in USA Not causally consistent. [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  34. use causality class account { // invariant: amount >= 0 var[dis] amount = 0 def query() = { return (amount, (a)=>a) } def inc() = { amount = amount+1; return (true, (a)=>a+1) } def dec() = { if (amount > 0) { amount = amount-1; return (true, (a)=>a-1) } else { return (false, (a)=>a) } } }

  35. Token system • ( T , 💕 ) where 💕 is a symmetric rel. on T . • Examples: 1. T = {lock}, 💕 = {(lock,lock)} 2. T = {rd,wr}, 💕 = {(rd,wr), (wr,wr), (wr,rd)}

  36. On-demand consistency using a token system ( T , 💕 ) • Each operation acquires a set of tokens. • Operations with conflicting tokens cannot be run concurrently.

  37. Alice dec() in Korea a— a++ Bob inc() dec() in UK a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  38. {lock} T = {lock} Alice dec() 💕 = {(lock, lock)} in Korea a— a++ {} {lock} Bob inc() dec() in UK {} a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  39. {lock} T = {lock} Alice dec() 💕 = {(lock, lock)} in Korea a— a++ {} {lock} Bob inc() dec() in UK {} a++ a— a— Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  40. {lock} T = {lock} Alice dec() 💕 = {(lock, lock)} in Korea a++ {} {lock} a— Bob inc() dec() in UK {} a++ a— a— skip Carol query() in USA [Q] What cannot be the result of query()? (a) 0 (b) -1 (c) -2 (d) all possible

  41. use causality class account { // invariant: amount >= 0 var[dis] amount = 0 use-token-system({lock},{(lock,lock)}) def query() with {} = { return (amount, (a)=>a) } def inc() with {} = { amount = amount+1; return (true, (a)=>a+1) } def dec() with {lock} = { if (amount > 0) { amount = amount-1; return (true, (a)=>a-1) } else { return (false, (a)=>a) } } }

  42. How to write correct prog.? 1. Strengthen consistency selectively. 2. Prove the correctness of a program.

  43. Our proof rule • Based on rely-guarantee. • Incorporates guarantees from causal and on-demand consistency.

  44. To prove that I is an invariant 9 G 0 2 P ( State ⇥ State ) , G 2 Token ! P ( State ⇥ State ) such that S1. � init 2 I S2. G 0 ( I ) ✓ I ^ 8 ⌧ . G ( ⌧ )( I ) ✓ I S3. 8 o, � , � 0 . ( � 2 I ^ ( � , � 0 ) 2 ( G 0 [ G (( F tok o ( � )) ? )) ⇤ ) ) ( � 0 , F e ff o ( � )( � 0 )) 2 G 0 [ G ( F tok = o ( � ))

  45. To prove that I is an invariant 9 G 0 2 P ( State ⇥ State ) , G 2 Token ! P ( State ⇥ State ) such that S1. � init 2 I S2. G 0 ( I ) ✓ I ^ 8 ⌧ . G ( ⌧ )( I ) ✓ I S3. 8 o, � , � 0 . ( � 2 I ^ ( � , � 0 ) 2 ( G 0 [ G (( F tok o ( � )) ? )) ⇤ ) ) ( � 0 , F e ff o ( � )( � 0 )) 2 G 0 [ G ( F tok = o ( � ))

  46. To prove that I is an invariant 9 G 0 2 P ( State ⇥ State ) , G 2 Token ! P ( State ⇥ State ) such that S1. � init 2 I S2. G 0 ( I ) ✓ I ^ 8 ⌧ . G ( ⌧ )( I ) ✓ I S3. 8 o, � , � 0 . ( � 2 I ^ ( � , � 0 ) 2 ( G 0 [ G (( F tok o ( � )) ? )) ⇤ ) ) ( � 0 , F e ff o ( � )( � 0 )) 2 G 0 [ G ( F tok = o ( � ))

  47. To prove that I is an invariant 9 G 0 2 P ( State ⇥ State ) , G 2 Token ! P ( State ⇥ State ) such that S1. � init 2 I S2. G 0 ( I ) ✓ I ^ 8 ⌧ . G ( ⌧ )( I ) ✓ I S3. 8 o, � , � 0 . ( � 2 I ^ ( � , � 0 ) 2 ( G 0 [ G (( F tok o ( � )) ? )) ⇤ ) ) ( � 0 , F e ff o ( � )( � 0 )) 2 G 0 [ G ( F tok = o ( � ))

Recommend


More recommend