+ All Categories
Home > Documents > Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man,...

Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man,...

Date post: 03-Oct-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
42
Versioning, Consistency, and Agreement COS 461: Computer Networks Spring 2010 (MW 3:00‐4:20 in CS105) Mike Freedman hIp://www.cs.princeton.edu/courses/archive/spring10/cos461/ 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz, Brent Sheppard
Transcript
Page 1: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Versioning,Consistency,andAgreement

COS461:ComputerNetworksSpring2010(MW3:00‐4:20inCS105)

MikeFreedmanhIp://www.cs.princeton.edu/courses/archive/spring10/cos461/

1

Jenkins,ifIwantanotheryes‐man,I’llbuildone!

Lee Lorenz, Brent Sheppard

Page 2: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Timeanddistributedsystems

•  WithmulPpleevents,whathappensfirst?

A shoots B

B dies 2

Page 3: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Timeanddistributedsystems

•  WithmulPpleevents,whathappensfirst?

A dies

B shoots A

3

Page 4: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Timeanddistributedsystems

•  WithmulPpleevents,whathappensfirst?

A shoots B

B dies A dies

B shoots A

4

Page 5: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

JustusePmestamps?

•  Needsynchronizedclocks

•  ClocksynchviaaPmeserver

p Time server S

5

Page 6: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

•  Usesa!meservertosynchronizeclocks

•  TimeserverkeepsthereferencePme

•  ClientsaskserverforPmeandadjusttheirlocal

clock,basedontheresponse

–  Butdifferentnetworklatency→clockskew?

•  Correctforthis?Forlinkswithsymmetricallatency:

CrisPan’sAlgorithm

adjusted-local-time = server-timestamp t + (RTT / 2)

local-clock-error = adjusted-local-time – local-time

RTT = response-received-time – request-sent-time

6

Page 7: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Isthissufficient?

•  Serverlatencyduetoload?–  Ifcanmeasure:

•  adjusted‐local‐Pme=server‐Pmet+(RTT+lag)/2

•  Butwhataboutasymmetriclatency?– RTT/2notsufficient!

•  WhatdoweneedtomeasureRTT?– Requiresnoclockdrib!

•  Whatabout“almost”concurrentevents?– Clockshavemicro/milli‐secondprecision

7

Page 8: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

EventsandHistories

•  Processesexecutesequencesofevents

•  Eventscanbeof3types:–  local,send,andreceive

•  Thelocalhistoryhpofprocesspisthesequenceofeventsexecutedbyprocess

8

Page 9: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Orderingevents

•  ObservaPon1:– Eventsinalocalhistoryaretotallyordered

time!pi

9

Page 10: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Orderingevents

•  ObservaPon1:– Eventsinalocalhistoryaretotallyordered

•  ObservaPon2:– Foreverymessagem,send(m)precedesreceive(m)

time!

time!

time!

pi

pi

pj

m

10

Page 11: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Happens‐Before(Lamport[1978])

•  RelaPvePme?DefineHappens‐Before(→):–  Onthesameprocess:a→b,if!me(a)<!me(b)

–  Ifp1sendsmtop2:send(m)→receive(m)

–  Ifa→bandb→cthena→c

•  LamportAlgorithmusesforparPalordering:–  Allprocessesuseacounter(clock)withiniPalvalueof0–  Counterincrementedbyandassignedtoeachevent,as

itsPmestamp

–  Asend(msg)eventcarriesitsPmestamp

–  Forreceive(msg)event,counterisupdatedbyMax(receiver‐counter,message‐Pmestamp)+1

11

Page 12: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

EventsOccurringatThreeProcesses

12

Page 13: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

LamportTimestamps

1

1

2

3 4

5

13

Page 14: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

LamportLogicalTime

Host 1

Host 2

Host 3

Host 4

1

2

2

3

3

5

4

5

3

6

4

6

7

8

0

0

0

0

1

2

4

3 3

4

7

Physical Time

14

Page 15: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

LamportLogicalTime

Host 1

Host 2

Host 3

Host 4

1

2

2

3

3

5

4

5

3

6

4

6

7

8

0

0

0

0

1

2

4

3 3

4

7

Physical Time

Logically concurrent events!

15

Page 16: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

VectorLogicalClocks•  WithLamportLogicalTime

–  eprecedesf⇒Pmestamp(e)<Pmestamp(f),but

–  Pmestamp(e)<Pmestamp(f)⇒eprecedesf

16

Page 17: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

VectorLogicalClocks•  WithLamportLogicalTime

–  eprecedesf⇒Pmestamp(e)<Pmestamp(f),but

–  Pmestamp(e)<Pmestamp(f)⇒eprecedesf

•  VectorLogicalPmeguaranteesthis:–  Allhostsuseavectorofcounters(logicalclocks),ithelementistheclockvalueforhosti,iniPally0

–  Eachhosti,incrementstheithelementofitsvectoruponanevent,assignsthevectortotheevent.

–  Asend(msg)eventcarriesvectorPmestamp

–  Forreceive(msg)event,

Max(Vreceiver[j],Vmsg[j]), ifjisnotself

Vreceiver[j]+1 otherwiseVreceiver[j] =

17

Page 18: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

VectorTimestamps

18

Page 19: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

VectorLogicalTime

Host 1

Host 2

Host 3

Host 4

1,0,0,0

Physical Time

1,1,0,0

1,0,0,0

1,2,0,0

2,2,3,0

1,2,0,0

2,0,0,0

2,0,1,0 2,0,2,0

Vreceiver[j] =

2,0,2,1

Max(Vreceiver[j],Vmsg[j]), ifjisnotself

Vreceiver[j]+1 otherwise

19

Page 20: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

ComparingVectorTimestamps

•  a=b iftheyagreeateveryelement

•  a<b ifa[i]<=b[i]foreveryi,but!(a=b)•  a>b ifa[i]>=b[i]foreveryi,but!(a=b)•  a||b ifa[i]<b[i],a[j]>b[j],forsomei,j(conflict!)

•  Ifonehistoryisprefixofother,thenonevectorPmestamp<other

•  Ifonehistoryisnotaprefixoftheother,then(atleastbyexample)VTswillnotbecomparable.

20

Page 21: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

GivenanoPonofPme…

…What’sanoPonofconsistency?

21

Page 22: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

StrictConsistency

•  Strongestconsistencymodelwe’llconsider– AnyreadonadataitemXreturnsvaluecorrespondingtoresultofthemostrecentwriteonX

•  NeedanabsoluteglobalPme– “Mostrecent”needstobeunambiguous

x

WritextoaReadxreturnsa

22

Page 23: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Whatelsecanwedo?

•  Strictconsistencyistheidealmodel– Butimpossibletoimplement!

•  SequenPalconsistency– Slightlyweakerthanstrictconsistency– DefinedforsharedmemoryformulP‐processors

23

Page 24: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

SequenPalConsistency

•  DefiniPon:ResultofanyexecuPonisthesameasifall(readandwrite)operaPonsondatastorewereexecutedinsomesequenPalorder,andtheoperaPonsofeachindividualprocessappearinthissequenceintheorderspecifiedbyitsprogram

•  DefiniPon:Whenprocessesarerunningconcurrently:–  InterleavingofreadandwriteoperaPonsisacceptable,butallprocessesseethesameinterleavingofoperaPons

•  Differencefromstrictconsistency–  NoreferencetothemostrecentPme

–  AbsoluteglobalPmedoesnotplayarole24

Page 25: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

ValidSequenPalConsistency?

x 25

Page 26: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Linearizability

•  Linearizability– Weakerthanstrictconsistency–  StrongerthansequenPalconsistency

•  AlloperaPons(OP=read,write)receiveaglobalPme‐stampusingasynchronizedclock

•  Linearizability:–  RequirementsforsequenPalconsistency,plus

–  Iftsop1(x)<tsop2(y),thenOP1(x)shouldprecedeOP2(y)inthesequence

26

Page 27: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

CausalConsistency

•  NecessarycondiPon:– Writesthatarepoten&allycausallyrelatedmustbeseenbyallprocessesinthesameorder.

–  Concurrentwritesmaybeseeninadifferentorderondifferentmachines.

•  WeakerthansequenPalconsistency

•  Concurrent:Opsthatarenotcausallyrelated

27

Page 28: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

CausalConsistency

•  Allowedwithcausalconsistency,butnotwithsequenPalorstrictconsistency

•  W(x)bandW(x)careconcurrent–  Soallprocessesdon’tseetheminthesameorder

•  P3andP4readthevalues‘a’and‘b’inorderaspotenPallycausallyrelated.No‘causality’for‘c’.

28

Page 29: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

CausalConsistency

x

29

Page 30: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

CausalConsistency

•  Requireskeepingtrackofwhichprocesseshaveseenwhichwrites

– Needsadependencygraphofwhichopisdependentonwhichotherops

– …orusevectorPmestamps!

30

Page 31: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Eventualconsistency•  Ifnonewupdatesaremadetoanobject,abersomeinconsistencywindowcloses,allaccesseswillreturnthelastupdatedvalue

•  Prefixproperty:–  IfPihaswritewacceptedfromsomeclientbyPj–  ThenPihasallwritesacceptedbyPjpriortow

•  Usefulwhereconcurrencyappearsonlyinarestrictedform

•  AssumpPon:writeconflictswillbeeasytoresolve–  Eveneasierifwhole‐”object”updatesonly

31

Page 32: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Systemsusingeventualconsistency

•  DB:updatedbyafewproc’s,readbymany–  Howfastmustupdatesbepropagated?

•  Webpages:typicallyupdatedbysingleuser–  So,nowrite‐writeconflicts–  Howevercachescanbecomeinconsistent

32

Page 33: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Systemsusingeventualconsistency

•  DNS:eachdomainassignedtoanamingauthority–  Onlymasterauthoritycanupdatethenamespace–  OtherNSserversactas“slave”servers,downloadingDNSzonefilefrommasterauthority

–  So,write‐writeconflictswon’thappen

–  Isthisalwaystruetoday?

[email protected].( 18 ;serial 1200 ;refresh 600 ;retry 172800 ;expire 21600);minimum

33

Page 34: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

TypicalimplementaPonofeventualconsistency

•  Distributed,inconsistentstate– Writesonlygotosomesubsetofstoragenodes

•  Bydesign(forhigherthroughput)•  Duetotransmissionfailures

•  “AnP‐entropy”(gossiping)fixesinconsistencies– Usevectorclocktoseewhichisolder–  Prefixpropertyhelpsnodesknowconsistencystatus–  IfautomaPc,requiressomewaytohandlewriteconflicts

•  ApplicaPon‐specificmerge()funcPon•  Amazon’sDynamo:UsersmayseemulPpleconcurrent“branches”beforeapp‐specificreconciliaPonkicksin

34

Page 35: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Examples…•  Causalconsistency.Non‐causallyrelatedsubjecttonormaleventualconsistencyrules

•  Read‐your‐writesconsistency.

•  Sessionconsistency.Read‐your‐writesholdsiffclientsessionexists.Ifsessionterminates,noguaranteesbetweensessions.

•  Monotonicreadconsistency.Oncereadreturnsaversion,subsequentreadsneverreturnolderversions.

•  Monotonicwriteconsistency.Writesbysameprocessareproperlyserialized.Reallyhardtoprogramsystemswithoutthisprocess.

35

Page 36: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Evenread‐your‐writesmaybedifficulttoachieve

36

Page 37: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Whataboutstrongeragreement?

•  Two‐phasecommitprotocol

37

•  Marriageceremony

•  Theater

•  Contractlaw

Doyou?Ido.Inowpronounceyou…

Readyontheset?Ready!AcPon!

OfferSignatureDeal/lawsuit

Page 38: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Whataboutstrongeragreement?

•  Two‐phasecommitprotocol

38

LeaderAcceptorsAcceptorsAcceptors

PREPARE

READY

COMMIT

ACK

ClientWRITE

ACK

Allprepared?

Allack’d?

Page 39: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Whataboutfailures?

•  Ifanacceptorfails:– CansPllensurelinearizabilityif|R|+|W|≥N

– “read”and“write”quorumsoverlapinatleast1node

•  Iftheleaderfails?– Loseavailability:systemnotlonger“live”

•  Pickanewleader?– Needtomakesureeverybodyagreesonleader!– Needtomakesurethat“group”isknown

39

Page 40: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

ConsensusandPaxosAlgorithm•  “Consensus”problem

–  Nprocesseswanttoagreeonavalue–  IffewerthanFfaultsinawindow,consensusachieved

•  “Crash”faultsneed2F+1processes•  “Malicious”faults(calledByzanPne)need3F+1processes

•  CollecPonofprocessesproposingvalues–  Onlyproposedvaluemaybechosen

–  Onlysinglevaluechosen

•  Commonusage:–  Viewchange:defineleaderandgroupviaPaxos–  Leaderusestwo‐phasecommitforwrites

–  Acceptorsmonitorleaderforliveness.Ifdetectfailure,re‐execute“viewchange” 40

Page 41: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Paxos:Algorithm

ViewChangefromcurrentview

Viewi:V={Leader:N2,Group:{N1,N2,N3}}

Phase1(Prepare)•  Proposer:Sendpreparewithversion#jtomembersofViewi

•  Acceptor:ifj>vers#kofanyotherprepareitseen,respondwithpromisenottoacceptlower‐numberedproposals.Otherwise,

respondwithkandvaluev’accepted.

Phase2(Accept)•  Ifmajoritypromise,proposersendsacceptwith(versj,valuev)

•  Acceptoracceptsunlessithasrespondedtopreparewithhighervers#thanj.Sendsacknowledgementtoallviewmembers.

41

Page 42: Versioning, Consistency, and Agreement · 2013. 10. 10. · 1 Jenkins, if I want another yes‐man, I’ll build one! Lee Lorenz ... • Session consistency. Read‐your‐writes

Summary

•  GlobalPmedoesn’texistindistributedsystem

•  LogicalPmecanbeestablishedviaversion#’s

•  LogicalPmeusefulinvariousconsistencymodels–  Strict>Linearizability>SequenPal>Causal>Eventual

•  Agreementindistributedsystem–  Eventualconsistency:Quorums+anP‐entropy

–  Linearizability:Two‐phasecommit,Paxos

42


Recommended