Proving Weakly Consistent Applications Correct Alexey Gotsman - - PowerPoint PPT Presentation
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
Eventually consistent databases
- No synchronisation: process an update locally,
propagate effects to other replicas later
- Weakens consistency: deposit seen with a
delay
deposit(100)
balance = 100 balance = 100
balance ≥ 0
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0
balance ≥ 0
balance = 0
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0 balance = -100
balance ≥ 0
balance = 0
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0 balance = -100
balance ≥ 0
balance = 0
deposit(100)
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0 balance = -100
balance ≥ 0
balance = 0
deposit(100)
- Withdrawals strongly consistent
- Deposits eventually consistent
Tune consistency:
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
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
σ ⟦op⟧val Replica states: σ ∈ State
- p
Return value: ⟦op⟧val ∈ State ➞ Value
Operation semantics
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State) Replica states: σ ∈ State
- p
Return value: ⟦op⟧val ∈ State ➞ Value
Operation semantics
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State) Replica states: σ ∈ State
- p
Return value: ⟦op⟧val ∈ State ➞ Value
Operation semantics
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State) Replica states: σ ∈ State
- p
Return value: ⟦op⟧val ∈ State ➞ Value
Operation semantics
Effector
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State) Replica states: σ ∈ State
- p
Return value: ⟦op⟧val ∈ State ➞ Value
Operation semantics
Effector
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val ⟦balance()⟧eff(σ) = λσ. σ State = Z
- p
⟦balance()⟧val(σ) = σ
Operation semantics
σ σʹ ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val ⟦deposit(100)⟧eff(σ) = λσʹ. (σʹ + 100)
- p
Operation semantics
σ 50 ⟦op⟧eff(σ)(σʹ) ⟦op⟧eff(σ) ⟦op⟧val ⟦deposit(100)⟧eff(σ) = λσʹ. (σʹ + 100)
- p
Operation semantics
σ 50 150 ⟦op⟧eff(σ) ⟦op⟧val ⟦deposit(100)⟧eff(σ) = λσʹ. (σʹ + 100)
- p
Operation semantics
- 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
Ensuring eventual consistency
⟦deposit(100)⟧eff(σ) = λσʹ. (σʹ + 100)
σ ⟦op⟧eff(σ) ⟦op⟧val
- p
Operation semantics
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) = σʹ ⟦op⟧eff(σ)(σʹ)
σ ⟦op⟧eff(σ) ⟦op⟧val
- p
Operation semantics
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) = σʹ ⟦op⟧eff(σ)(σʹ)
σ ⟦op⟧eff(σ) ⟦op⟧val
- p
Operation semantics
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) = σʹ ⟦op⟧eff(σ)(σʹ)
σ ⟦op⟧eff(σ) ⟦op⟧val
- p
Operation semantics
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) = σʹ ⟦op⟧eff(σ)(σʹ)
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0 balance = 0
λσʹ. σʹ - 100
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) =
balance = 100 withdraw(100) : ✔ balance = 100 withdraw(100) : ✔ balance = 0 balance = -100 balance = 0
λσʹ. σʹ - 100
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) =
Strengthening consistency
- Token = {τ1, τ2, ...}
- Symmetric conflict relation ⋈ ⊆ Token × Token
Token system ≈ locks on steroids:
Strengthening consistency
- Token = {τ1, τ2, ...}
- Symmetric conflict relation ⋈ ⊆ Token × Token
Token system ≈ locks on steroids: Example - mutual exclusion lock: Token = {τ}; τ ⋈ τ
Strengthening consistency
- Token = {τ1, τ2, ...}
- Symmetric conflict relation ⋈ ⊆ Token × Token
Token system ≈ locks on steroids: Example - mutual exclusion lock: Token = {τ}; τ ⋈ τ
Each operation associated with a set of tokens: ⟦op⟧tok ∈ State ➞ P(Token)
balance = 100 withdraw(100) : ✔ balance = 100
{τ} τ ⋈ τ
Operations associated with conflicting tokens cannot be unaware of each other
balance = 100 withdraw(100) : ✔ balance = 100 Anything I don’t know about? withdraw(100) : ?
{τ} τ ⋈ τ {τ}
Operations associated with conflicting tokens cannot be unaware of each other
balance = 100 balance = 100 withdraw(100) : ✔ balance = 0 withdraw(100) : ?
τ ⋈ τ {τ} {τ}
Operations associated with conflicting tokens cannot be unaware of each other
balance = 100 withdraw(100) : ✘ balance = 0 balance = 100 withdraw(100) : ✔
τ ⋈ τ {τ} {τ}
Operations associated with conflicting tokens cannot be unaware of each other
balance = 100 withdraw(100) : ✘ balance = 0 deposit(100)
∅
balance = 100 withdraw(100) : ✔
τ ⋈ τ
No synchronisation
{τ} {τ}
Operations associated with conflicting tokens cannot be unaware of each other
balance = 100 withdraw(100) : ✘ balance = 0 deposit(100)
∅
balance = 100 withdraw(100) : ✔
τ ⋈ τ
No synchronisation
{τ} {τ}
Operations associated with conflicting tokens cannot be unaware of each other
Do we always have I = (balance ≥ 0)?
σʹ ⟦op⟧eff(σ)(σʹ) ∈ I ? ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
Effect applied in a different state!
σʹ ⟦op⟧eff(σ)(σʹ) ∈ I ? ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ) ⟦withdraw(100)⟧eff(σ) = ⟦op⟧eff(σ) = if P(σ) then f(σ) else if...
σʹ ⟦op⟧eff(σ)(σʹ) ∈ I ? ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
⟦op⟧eff(σ) = if P(σ) then f(σ) else if...
- 1. Effector safety: f preserves I when executed in
any state satisfying P
σʹ ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
⟦op⟧eff(σ) = if P(σ) then f(σ) else if... ⟦op⟧eff(σ)(σʹ) ∈ I ✔
- 1. Effector safety: f preserves I when executed in
any state satisfying P
σʹ ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
⟦op⟧eff(σ) = if P(σ) then f(σ) else if... ⟦op⟧eff(σ)(σʹ) ∈ I ✔ P(σʹ)?
- 1. Effector safety: f preserves I when executed in
any state satisfying P
σʹ ⟦
- p
⟧
e f f
( σ ) σ ∈ I
- p
⟦op⟧eff(σ) = if P(σ) then f(σ) else if... ⟦op⟧eff(σ)(σʹ) ∈ I ✔ P(σʹ)?
- 2. Precondition stability: P will hold when f is
applied at any replica
- 1. Effector safety: f preserves I when executed in
any state satisfying P
⟦op⟧eff(σ) = if P(σ) then f(σ) else if...
- 2. Precondition stability: P will hold when f is
applied at any replica
- 1. Effector safety: f preserves I when executed in
any state satisfying P
CISE tool: ‘Cause I’m Strong Enough
By Mahsa Najafzadeh (UPMC & INRIA) Discharges proof obligations using Z3 SMT solver
31
32
- 1. Effector safety: f preserves I when executed in
any state satisfying P
32
- 1. Effector safety: f preserves I when executed in
any state satisfying P ✔
33
- 2. Precondition stability: P is preserved by
concurrent operations
33
- 2. Precondition stability: P is preserved by
concurrent operations
33
- 2. Precondition stability: P is preserved by
concurrent operations
Bug: concurrent withdrawals may violate the invariant
34
- 2. Precondition stability: P is preserved by
concurrent operations
Add a token restricting concurrency
34
- 2. Precondition stability: P is preserved by
concurrent operations ✔
Add a token restricting concurrency
Conclusion
- First proof rule and tool for proving
invariants of weakly consistent applications
- Case studies: fragments of web applications,
replicated file system in progress
- Future work: other consistency models,