CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on...

28
CAP + Clocks Time keeps on slipping, slipping…

Transcript of CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on...

Page 1: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

CAP + Clocks

Time keeps on slipping, slipping…

Page 2: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Logistics

• Last week’s slides online• Sign up on Piazza now– No really, do it now

• Papers are loaded in HotCRP– Sign up for account at http://cs7780.ccs.neu.edu– I will make you a PC member so you can enter

“reviews”– Do review preferences

Page 3: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Logistics (2)

• Some changes to the schedule– NENS field trip– Moved other stuff down

• Don’t forget about project proposals– Details on content on the website

Page 4: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Logistics (3)

• Audit policy– You must present at least one paper– You must read all of them and contribute to the

discussion (no dead weight)– No project or project presentation requirement

Page 5: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

CAP “Theorem” and Implications

Page 6: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Desirable properties of data systems

• ACID transactions– Atomic: Either all of the transaction happens or

none– Consistent: After a transaction, all uniqueness

properties are maintained– Isolation: One transaction does not affect another – Durable: Once complete, the transaction remains

complete

Page 7: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Move to distributed environment

• CAP– Consistency: updates to data are applied to all or

none– Availability: must be able to access all data– Partitions: failures can partition network into

subtrees• Why should we want all three?• Is it possible?

Page 8: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Eric Brewer’s CAP “theorem”

• The Brewer Conjecture– No system can simultaneously achieve C and A and P– Implication: must perform tradeoffs to obtain 2 at the

expense of the 3rd – Never published, but widely recognized

Page 9: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

9

CAP Examples

Write (key, 1)

(key, 1)

Replicate(key, 2)

Read

Availability– Client can always read

• Impact of partitions– Not consistent

(key, 1)

Write (key, 1)

(key, 1)

Replicate(key, 2)

Read

Consistency Reads always return

accurate results Impact of partitions

No availability

Error: ServiceUnavailable

A+P

C+P

What about C+A?• Doesn’t really exist• Partitions are always possible• Tradeoffs must be made to cope with them

Page 10: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Proof of Theorem

• Strong proof when no clocks– No way to reliably stay consistent

• What changes with clocks?

Page 11: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Weak consistency

• Use clocks, impose partial ordering– Allows a form of “eventual consistency”

• Key result that drives many of today’s systems– “return most of the data most of the time”– “usually correct results”

• Where is this not ok?

Page 12: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

12 years later:Have the “rules” changed?

• What if partitions are rare?– Then most of the time C/A are maintained

• CAP don’t need to be binary properties

• Choosing between C or A is not a fixed decision, can change over time

Page 13: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

How long is the partition?

• We can’t “choose” to never have P– But we can put constraints on how the system

operates within some threshold time– Primary partitions enable partial availability– But require knowing invariants to reconcile

consistency after partition is done

Page 14: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

So what do you do when there is a partition?

• Detection• Enter “partition mode”– Why?

• Recover after partition is done– What are the challenges?

Page 15: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Recovery

• We’ve all done this– (CVS, SVN, git, hg)

• How does it work?– Commutative operations– Commutative replicated data types

• Special data types will come up again and again

Page 16: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Exercise

• Let’s match popular applications to consistency/availability models

Page 17: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Time and Clocks

Page 18: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Time

• It’s pretty important, eh?

• It marches on

• Only goes forward

• …

Page 19: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Time

• It defines a distributed system

“…message transmission time is not negligible compared to the time between events in a

single process”

Page 20: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Partial time ordering

• No way for all clocks to have exactly the same time all the time– Why?

• Instead, focus on a partial ordering– “happens before” relationship– use it to build a (arbitrary) total ordering– this does not use physical time• What is the difference?

Page 21: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Scalar Clocks

• General technique described by Leslie Lamport– Explicitly maps out time as a sequence of version

numbers at each participant (from 1978!!)• Key idea– Each process maintains a counter (“clock”)– When it sends a message, it includes the counter– When receiving message, each process updates its

clock to be greater than timestamp in message

21

Page 22: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Nice applications of Logical Clocks

• Fully distributed – Mutual exclusion– Fairness– Liveness

Page 23: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Physical clocks

• What do they give us?

Page 24: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Vector clocks

• The idea– A vector clock is a list of (node, counter) pairs– Every version of every object has one vector clock

• Detecting causality– If all of A’s counters are less-than-or-equal to all of B’s

counters, then A is ancestor of B, and can be forgotten– Intuition: A was applied to every node before B was

applied to any node. Therefore, A precedes B• Use vector clocks to perform syntactic

reconciliation

Page 25: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Simple Vector Clock Example

• Key features– Writes always succeed– Reconcile on read

• Possible issues– Large vector sizes– Need to be trimmed

• Solution– Add timestamps– Trim oldest nodes– Can introduce error

D1 ([Sx, 1])

D2 ([Sx, 2])

D3 ([Sx, 2], [Sy, 1])

D4 ([Sx, 2], [Sz, 1])

D5 ([Sx, 2], [Sy, 1], [Sz, 1])

Write by Sx

Write by Sx

Write by SzWrite by Sy

Read reconcile

25

Page 26: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Vector clock properties

• Isomorphic: Timestamps can be used to get causal ordering (and vice versa)

• Strong consistency• Event counting• Useful for distributed debugging, causal

ordering, etc

Page 27: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Matrix time

• Add another dimension– Everyone has a consistent view of everyone else’s

clock– Can be used to “prune” stale information

Page 28: CAP + Clocks Time keeps on slipping, slipping…. Logistics Last week’s slides online Sign up on Piazza now – No really, do it now Papers are loaded in.

Take-aways

• Consistency, Availability, Partitions– Can we do them all together?– Depends on goals, time

• Time is relative– Order matters– Logical ordering and causality can give us• total ordering• consistency