Share
Embed
Transcript
75 slides
-
Invariant Safety for Distributed Applications 1 Sreeja Nair, Gustavo Petri,
Marc Shapiro Verification Seminar 15-03-2019 -
Invariant Safety for Distributed Applications • Applications are distributed due
to demands of low response time • CAP theorem depicts a tension between Consistency and Availability • Ideal world for developers = high availability + convergence + application safety • A modular and sequential proof to ensure this! 2 -
Auction application • State • Status • INVALID or ACTIVE
or CLOSED • Winner • Set of bids, each bid comprising • BidId • Placed • Amount 4 • Invariant • Bids can be placed only when the status is active • When auction is closed, there is a winner • Winner is the highest bid • Operations • Start auction • Place bid • Close auction -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Status Winner Bids -
Evolution of state 5 Alice/ Australia Bob/ Belgium Charlie/ Canada
Start auction Place bid Status Winner Bids -
Evolution of state 5 100 Alice/ Australia Bob/ Belgium Charlie/
Canada Start auction Place bid Status Winner Bids -
Evolution of state 5 100 Alice/ Australia Bob/ Belgium Charlie/
Canada Start auction Place bid Place bid Status Winner Bids -
Evolution of state 5 100 105 Alice/ Australia Bob/ Belgium
Charlie/ Canada Start auction Place bid Place bid Status Winner Bids -
Evolution of state 5 100 105 Alice/ Australia Bob/ Belgium
Charlie/ Canada Start auction Place bid Place bid Status Winner Bids -
Evolution of state 5 100 105 Alice/ Australia Bob/ Belgium
Charlie/ Canada Start auction Place bid Place bid Status Winner Bids ??? -
Evolution of state 5 100 105 Alice/ Australia Bob/ Belgium
Charlie/ Canada Start auction Place bid Place bid Status Winner Bids -
Evolution of state 5 100 105 Alice/ Australia Bob/ Belgium
Charlie/ Canada Start auction Place bid Place bid Status Winner Bids 100 105 Merge! -
Semi-lattice • Set of state should form a monotonic semi-lattice
• Equipped with a partial order function • Each update should inflate the state • Merge should be the Least Upper Bound 6 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid
Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid
Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid
Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid
Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid
Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Close auction
Place bid Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Close auction
Place bid Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Close auction
Place bid Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Close auction
Place bid Place bid Status Winner Bids Evolution of state 7 -
Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Close auction
Place bid Place bid Status Winner Bids Evolution of state 7 -
Safety in sequential executions • Each operation and merge must
satisfy the invariant • Ensured by preconditions 8 -
Precondition for merge? • It must hold true since merge
can happen at any time • Can be also called Concurrent Invariant • The weakest precondition to be upheld for the resulting state of merge to uphold the sequential invariant • Ensures all concurrent operations are still safe • Never block any merge!! 9 -
Safety in concurrent executions • A state in a replica
evolves with • A local update by operation • Merge • Merge is the only point of observable concurrency 10 Alice/ Australia Bob/ Belgium Charlie/ Canada Start auction Place bid Place bid -
Proof Rule for safety of distributed applications • Initial state
must satisfy the sequential invariant and concurrent invariant • Each update and merge should preserve both the sequential invariant and concurrent invariant 11 -
Proof Rule • Intuition • Merge is the only point
of external influence • Merge can happen any time • Properties • Modular • Each operation and merge reasoned in isolation • Sequential • Reasoning as if for a sequential application 12 -
Revisiting auction • Invariant • Bids can be placed only
when the status is active • When auction is closed, there is a winner • Winner is the highest bid 13 -
Safety of Auction 14 Invariant 1. Bids can be placed
only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid • Place bid • If auction concurrently closed in other replica, precondition of merge violated! -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid • Place bid • If auction concurrently closed in other replica, precondition of merge violated! -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid • Place bid • If auction concurrently closed in other replica, precondition of merge violated! • Close auction • Similar to place bid -
Safety of Auction • Start auction 14 Invariant 1. Bids
can be placed only when the status is active 2. When auction is closed, there is a winner 3. Winner is the highest bid • Place bid • If auction concurrently closed in other replica, precondition of merge violated! • Close auction • Similar to place bid -
Concurrency Control • Option 1: • Strong consistency of place
bid and close auction operations • Issue: each place bid need synchronisation • Option 2: • Concurrency control similar to readers-write lock • Place bids work without synchronisation • Closing auction needs synchronisation 16 -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Status Winner Bids
Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Status
Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Status
Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control No more bids can be placed!! -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Place bid Place
bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Close auction Place
bid Place bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
17 Alice/ Australia Bob/ Belgium Charlie/ Canada Close auction Place
bid Place bid Status Winner Bids Tokens Release token Release token Release token Evolution of state with Concurrency Control -
Tool Support - Soteria • Implemented on top of Boogie
• Input • Application state • Invariant • Partial Order function • Operations with preconditions • Merge operation with precondition 18 -
Soteria checks • Sanity checks • Convergence checks • Each
operation is monotonically non-decreasing • Merge is the least upper bound • Safety checks • Sequential safety -> each operation preserves the invariant • Concurrent safety -> each operation preserves the precondition of merge 19 -
Conclusion • A new proof rule for verification of distributed
applications • For applications using state-based CRDTs • A tool for design verification • Available at https://github.com/sreeja/soteria_tool 20