distributed systems · • cap theorem. raft • proposed by ongaroand ousterhoutin 2014 • five...

26
Distributed Systems Day 12: Consistency “Got to Catch Them All…”

Upload: others

Post on 10-Oct-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

DistributedSystemsDay12:Consistency

“GottoCatchThemAll…”

Page 2: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Today

• RaftRecap

• Consensus

• CAPTheorem

Page 3: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Raft• Proposed byOngaro andOusterhout in2014

• Fivecomponents• Leaderelection• Logreplication• Safety• Clientprotocol• Membershipchanges

• Assumescrashfailures(sonobyzantinefailures)

• Nodependency ontimeforsafety• Butdepends ontimeforavailability

• Tolerates(N-1)/2failures

Page 4: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

RaftProperties• Safety:atmostoneleader

• Eachfollowervotesforatmostonecandidate• Acandidateneedsamajoritytobeleader

• Liveness:eventuallytherewillbealeader• Challenge:ifmultipletrytocallforelectionà splitvote• Timeout+randomness:randomnesshelpstoensurethatoneserverdetects

fasterthantheothers

• LogSafety: ifleadercommits,thendataisinallfutureleaders• ElectionModifications:followersonlyvoteforclientwithhigherterm/index• CommitModifications:NewLeaderdoesnotcommituntilentriesincurrent

termhavebeenagreedonbyfollowers

Page 5: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

HowdoyouChangeClusterSize?N=5

N=7

Goal:addtwonewserverstocluster

Challenge:consistentlygetallserverstoagreeonnewclustersize

Case:Duringclusterupdate,leaderfailsANDdifferentservershavedifferentnotionsofsizeàmultipleleaders

Page 6: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

HowdoyouChangeClusterSize?N=5

N=7

Goal:addtwonewserverstocluster

Challenge:consistentlygetallserverstoagreeonnewclustersize

Case:Duringclusterupdate,leaderfailsANDdifferentservershavedifferentnotionsofsizeàmultipleleaders

Solution:Needaprotocoltoconsistentlyupdatethecluster

Page 7: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ConfigurationChanges• Cannotswitchdirectlyfromoneconfigurationtoanother:conflictingmajoritiescouldarise

• SwitchingfromN=3toN=5Seethepaperfordetails

Cold Cnew

Server1Server2Server3Server4Server5

MajorityofCold

MajorityofCnew

time

Page 8: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Today

• RaftRecap

• Consensus

• CAPTheorem

Page 9: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol
Page 10: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol
Page 11: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ApproachestoReplication

PassiveReplication• Totalordering• Protocols:Zookeeper,Paxos,Chubby

ActiveReplication• FIFOordering• Toleratesbyzantinefailures

Lazyreplication• Causalordering• Protocols:Gossip,DynamoDB,

CassandraDB,VoldemortDB,MongoDB

ActiveReplication PassiveReplication LazyReplication

ServerB

ServerC

ServerA

FE

FEServerB(follower)

ServerC(Follower)

ServerA(leader)FE

FE FE ServerB

ServerC

ServerA

FE

Page 12: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ApproachestoReplication

PassiveReplication• Totalordering• Performanceissues:slowandlimitsparallelism

• Allservers processthesame request

Lazyreplication• Causalordering• Performance:faster

– Anyserver canprocessanyrequest– More parallelism˜

PassiveReplication LazyReplication

ServerB(follower)

ServerC(Follower)

ServerA(leader)FE

FE FE ServerB

ServerC

ServerA

FE

Page 13: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ThinkingAboutConsistency

• Allreplicasareoneserver

• Ifdifferentclientswriteandreadtothis’’one’’server,whatshouldweexpect?

ServerB(follower)

ServerC(Follower)

ServerA(leader)FE

FE

Get(c)

Get(c)

set(c=5)

set(c=7)

Get(c)

Get(c)

Get(c)

Get(c)

C1

C2

C3

C4

Page 14: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ConsistencySpectrum

StrictSerializability

Linearizable

Sequential

Causal+

Eventual

WEAKCONSISTENCY

STRONGCONSISTENCY

SLOWERBUTEASYTOPROGRAM

FASTBUTHARDERTOPROGRAM

Page 15: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Linearizable

• Totalorder+FIFO+“Time”• Recall:Totalorder– allserversoperateinsameorder• Linearizable isasubsetofTotalorder• OrderingmustbeFIFOandbasedontime

Get(c)

Get(c)

set(c=5)

set(c=7)

Get(c)

Get(c)

Get(c)

Get(c)

C1

C2

C3

C4

Initialc=3

Page 16: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Sequential

• Totalorder+FIFO

• SequentialisasubsetofTotalorder• OrderingmustbeFIFO• Requests fromdifferentclients canbereshuffled

Get(c)

Get(c)

set(c=5)

set(c=7)

Get(c)

Get(c)

Get(c)

Get(c)

C1

C2

C3

C4

Initialc=3

Page 17: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Causal+

• MustrespectCausality

• Needvectorclockstotrackandmaintaincausality

• Onlycausallyrelatedeventsneedtobeordered

• NOTOTALORDERING!!!!!

Get(c)

Get(c)

set(c=5)

set(c=7)

Get(c)

Get(c)

Get(c)

Get(c)

C1

C2

C3

C4

Initialc=3

Page 18: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Eventual

• AnythingCanhappen

• Ifnowritesà eventuallyallservers returnthesamedata

Get(c)

Get(c)

set(c=5)

set(c=7)

Get(c)

Get(c)

Get(c)

Get(c)

C1

C2

C3

C4

Initialc=3

Page 19: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ConsistencySpectrum• Linearizable:totalorder+realtime• Sequential:totalorder+clientorder• Causal+:causallyordered+eventuallyeveryoneagree• Eventual:eventuallyeveryoneagrees

StrictSerializability

Linearizable

Sequential

Causal+

Eventual

WEAKCONSISTENCY

STRONGCONSISTENCY

SLOWER

BUTEASYTOPROGRAM

FASTandParallel

BUTHARDERTOPROGRAM:needconflictresolution

Page 20: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Today

• RaftRecap

• Consensus

• CAPTheorem

Page 21: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

CAPTheorem

• ConsistencyModel:Howdoesyoursystemreactduringpartition

• C:Consistency(linearizable)• Allaccess islinearizable• Requires consensus

• A:Availability• Allclients canmakeprogress

• P:Partitiontolerance• CandAcanhappenduringapartition

Page 22: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

CAPTheorem

ServerB(follower)

ServerC(Follower)

ServerA(leader)

FE

FE

NetworkPartition

• ConsistencyModel:Howdoesyoursystemreactduringpartition

• C:Consistency(linearizable)• Allaccess islinearizable• Requires consensus

• A:Availability• Allclients canmakeprogress

• P:Partitiontolerance• CandAcanhappenduringapartition

Can’tcommit:• Nottheleader• Cantreachleader

Noavailability

Page 23: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

CAPTheorem

ServerB(follower)

ServerC(Follower)

ServerA(leader)

FE

FE

NetworkPartition

• ConsistencyModel:Howdoesyoursystemreactduringpartition

• C:Consistency(linearizable)• Allaccess islinearizable• Requires consensus

• A:Availability• Allclients canmakeprogress

• P:Partitiontolerance• CandAcanhappenduringapartition I’llcommit:thereWILL

BECONFLICTS

NOCONSISTENCY

availability

Page 24: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

ServerB(follower)

ServerC(Follower)

ServerA(leader)

FE

FE

NetworkPartition

I’llcommit: thereWILLBE CONFLICTS

NO CONSISTENCY

availability

ServerB(follower)

ServerC(Follower)

ServerA(leader)

FE

FE

NetworkPartition

Can’t commit:• Not theleader• Cant reach leader

No availability

Raft(linearizable):PassiveReplication:• Strongconsistency• Duringpartition---

• someclientswillmakenoprogress• Becauseleaderisunavailable

EventualConsistency:• Duringpartition---

• Someclientswillmakeprogress• Sinceclientscanchangesamedata

• Noconsistencygaurantees

Page 25: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

CAPTheorem

• C:Consistency(Linearizable)• A:Availability• P:Partitiontolerance

• Givena“Partition”,youmustpickbetween“Availability”and“Consistency”• PickConsistently:Someclients(notall)canchange“data consistently”• PickAvailability:Allclientscanchangedatabut“inconsistently”

Page 26: Distributed Systems · • CAP Theorem. Raft • Proposed by Ongaroand Ousterhoutin 2014 • Five components • Leader election • Log replication • Safety • Client protocol

Today

• RaftRecap• Challenges: howtochangethesizeofthecluster

• Consensus:ConsistencyModels• Definitions ofdifferentconsistencymodels• Differencesbetween themodels

• CAPTheorem:Given‘P’,youcanonlyhave“A”and“P”.• Whendesigning asystemthatmusttoleratepartitions, youmustpickbetween “A”and“P”.