570 likes | 709 Views
Logic and Lattices for Distributed Programming. Neil Conway , William R. Marczak, Peter Alvaro, Joseph M. Hellerstein UC Berkeley. David Maier Portland State University. Distributed Programming: Key Challenges. Partial Failure. Asynchrony. Dealing with Disorder. Enforce global order
E N D
Logic and Lattices for Distributed Programming Neil Conway, William R. Marczak, Peter Alvaro, Joseph M. Hellerstein UC Berkeley David Maier Portland State University
Distributed Programming: Key Challenges Partial Failure Asynchrony
Dealing with Disorder Enforce global order • Paxos, Two-Phase Commit, GCS, … • “Strong Consistency” Tolerate disorder • Programmer must ensure correct behavior for many possible network orders • “Eventual Consistency” • Typical goal: replicas converge to same final state
Dealing with Disorder Enforce global order • Paxos, Two-Phase Commit, GCS, … • “Strong Consistency” Tolerate disorder • Programmer must ensure correct behavior for many possible network orders • “Eventual Consistency” • Typical goal: replicas converge to same final state
Goal:Make it easier to writeprogramson top ofeventual consistency
This Talk • Prior Work • Convergent Modules (CRDTs) • Monotonic Logic (CALM) • BloomL • Case Study
Write: {Alice, Bob, Carol} Read: {Alice, Bob} Students{Alice, Bob, Carol} Students{Alice, Bob} Client0 How to resolve? Write: {Alice, Bob, Dave} Read: {Alice, Bob} Students{Alice, Bob, Dave} Students{Alice, Bob} Client1
Students{Alice, Bob, Carol, Dave} Client0 Merge = Set Union Students{Alice, Bob, Carol, Dave} Client1
Commutative Operations • Common design pattern • Formalized as CRDTs: Convergent and Commutative Replicated Data Types • Shapiro et al., INRIA (2009-2012) • Based on join semilattices
Lattices hS,t,?iis a bounded join semilatticeiff: • S is a set • t is a binary operator (“least upper bound”) • Associative, commutative, and idempotent • Induces a partial order on S: x·Sy if xty = y • Informally, “merge function” for elements of S • ? is the “least” element in S • 8x2S: ?t x= x
Time IncreasingInteger(LUB = Max) Set (LUB = Union) Boolean(LUB = Or)
Students{Alice, Bob, Carol} Students{Alice, Bob, Carol, Dave} Read: {Alice, Bob, Carol, Dave} Client0 Teams{<Alice, Bob>} Teams{<Alice, Bob>,<Carol, Dave>} Teams{<Alice, Bob>,<Carol, Dave>} Read: {<Alice,Bob>} Write: {<Alice,Bob>, <Carol,Dave>} Replica Synchronization Students{Alice, Bob, Carol} Students{Alice, Bob, Carol, Dave} Remove: {Dave} Client1 Teams{<Alice, Bob>,<Carol, Dave>} Teams{<Alice, Bob>} Teams{<Alice, Bob>,<Carol, Dave>}
Students{Alice, Bob, Carol, Dave} Students{Alice, Bob, Carol} Read: {Alice, Bob, Carol} Client0 Teams{<Alice, Bob>} Teams{<Alice, Bob>} Read: {<Alice,Bob>} Replica Synchronization Nondeterministic Outcome! Students{Alice, Bob, Carol} Students{Alice, Bob, Carol, Dave} Remove: {Dave} Client1 Teams{<Alice, Bob>} Teams{<Alice, Bob>}
Possible Solution:Encapsulate all distributedstate in a single CRDT Hard to design,verify, and test Doesn’t scale with application size
Solution: … Datalog? • Concurrent work: distributed programming using Datalog • P2 (2006-2010) • Bloom (2010-2012) • Monotonic logic: building block for convergent distributed programs
Monotonic Logic • As input set grows, output set does not shrink • “Retraction-free” • Order independent • e.g., map, filter, join, union, intersection Non-Monotonic Logic • New inputs might retract previous outputs • Order sensitive • e.g., aggregation, negation
Monotonicity and Determinism Agents learn strictly more knowledge over time Different learning order, same final outcome Result:Program is deterministic!
CALM Analysis All monotone programs are deterministic Simple syntactic test for monotonicity Result: Whole-program static analysis foreventual consistency ConsistencyAs LogicalMonotonicity
Problem:CALM only applies to programs over growing sets Version Numbers Timestamps Threshold Tests
Quorum Vote • A coordinator accepts votes from agents • Count # of votes • When Count(Votes) > k, send “success” message
Quorum Vote • A coordinator accepts votes from agents • Count # of votes • When Count(Votes) > k, send “success” message Aggregation isnon-monotonic!
Monotone Functions f : ST is a monotone function iff 8a,b2S : a·Sb) f(a)·Tf(b)
Time Monotone function fromset increase-int Monotone functionfromincrease-intboolean size() >= 5 IncreasingInteger(LUB = Max) Set(LUB = Union) Boolean(LUB = Or)
Quorum Vote in BloomL QUORUM_SIZE=5 RESULT_ADDR="example.org" classQuorumVote includeBud state do channel :vote_chn, [:@addr, :voter_id] channel :result_chn, [:@addr] lset:votes lmax:vote_cnt lbool:got_quorum end bloom do votes <=vote_chn {|v|v.voter_id} vote_cnt<=votes.size got_quorum<=vote_cnt.gt_eq(QUORUM_SIZE) result_chn<~got_quorum.when_true { [RESULT_ADDR] } end end Annotated Ruby class Communication interfaces Program state Lattice state declarations Monotonic CALM Accumulate votesinto set Monotone function: set ! max Monotone function: max !bool Program logic Merge function for set lattice Threshold test on bool (monotone)
BloomL Features • Generalizes logic programming to lattices • Integration of relational-style queries and functions over lattices • Efficient incremental evaluation scheme • Library of built-in lattices • Booleans, increasing/decreasing integers, sets, multisets, maps, … • API for defining custom lattices
Case Studies Key-Value Store • Object versioning via vector clocks • Quorum replication Replicated Shopping Cart • Using custom lattice types to encode domain-specific knowledge
Case Studies Key-Value Store • Object versioning via vector clocks • Quorum replication Replicated Shopping Cart • Using custom lattice types to encode domain-specific knowledge
Perspectives on Shopping • CRDTs • Individual server replicas converge • Bloom • Checkout is non-monotonic requires distributed coordination • Built-in BloomL lattice types • Checkout is not a monotone function of any of the built-in lattices
Observation:Once a checkoutoccurs, no more shopping actionscan be performed
Observation:Each client knowswhena checkout can beprocessed“safely”
Monotone Checkout OPS = [1,2,3]Complete OPS = [2,3]Incomplete OPS = [1,2]Incomplete OPS = [2]Incomplete OPS = [3]Incomplete OPS = [1]Incomplete
Shopping Takeaways • Checkout summary is a monotone function of client’s activities • Custom lattice type captures application-specific notion of “forward progress” • “Unsafe” state hidden behind ADT interface
Recap • How to build eventually consistent systems • Write disorderlyprograms • Disorderly state • Lattices • Disorderly computation • Monotone functions over lattices • BloomL • Type system for deterministic behavior • Support for custom lattice types
Strong Consistency in Industry “… there was a single overarching theme within the keynote talks… strong synchronization of the sort provided by a locking service must be avoided like the plague… [the key] challenge is to find ways of transforming services that might seem to need locking into versions that … can operate correctly without locking.” -- Birman et al.,“Toward a Cloud Computing Research Agenda” (LADIS, 2009)