- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheat.c
More file actions
Latest commit
257 lines (225 loc) · 12.2 KB
/
Copy pathcheat.c
File metadata and controls
257 lines (225 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
points
virualsyncrhonioussystemcannotscale: succeptibletopartion
Paas: Yougetaccesstoflexiblecomputingandstorageinfrastructure, coupledwithasoftwareplatform (oftentightlycoupled)
GoogleAppEngine
Saas: Yougetaccesstosoftwareservices, whenyouneedthem. Often
saidtosubsumeSOA (ServiceOrientedArchitectures).GoogleDocs
Iaas:AmazonEWS :Virtualization
Haas:LeastSecure
####################
GlobalResourceManager (RM)
Scheduling
Per-serverNodeManager (NM)
Daemonandserver-specificfunctions
Per-application (job) ApplicationMaster (AM)
ContainernegotiationwithRMandNMs
Detectingtaskfailuresofthatjob
NMheartbeatstoRM
Ifserverfails, RMletsallaffectedAMsknow, andAMstakeaction
NMkeepstrackofeachtaskrunningatitsserver
Iftaskfailswhilein-progress, markthetaskasidleandrestartit
AMheartbeatstoRM
Onfailure, RMrestartsAM, whichthensyncsupwithitsrunningtasks
Whenyouhave120serversintheDC, themeantimetofailure (MTTF) ofthenextmachineis1month.
Whenyouhave12,000serversintheDC, theMTTFisaboutonceevery7.2hours!
DesirableProperties:CompletenEss,Accuracy,Speed,Scale
Gossip:Bandwidth_up:TimeToPropagte_down
####################
Paxossafety?
Ifsomeroundhasamajority (i.e., quorum) hearingproposedvaluev’ andacceptingit (middleofPhase2), thensubsequentlyateachroundeither : 1) theroundchoosesv’ asdecisionor2) theroundfails • Proof : – PotentialleaderwaitsformajorityofOKsinPhase1 – Atleastonewillcontainv’ (becausetwomajoritiesorquorumsalwaysintersect) – Itwillchoosetosendoutv’ inPhase2 • Successrequiresamajority, andanytwomajoritysetsintersectScale, On-demandaccess, data-intensive, newprogramming
WUE=AnnualWaterUsage / ITEquipmentEnergy (L/kWh) – lowisgood • PUE=TotalfacilityPower / ITEquipmentPower – lowisgood
(e.g., Google~1.11)
CLOCKSKEW| M / (2*MDR) |GivenamaximumacceptableskewMbetweenanypairofclocks, needtosynchronizeatleastonceevery:timeunits
ExternalSynchronizationwithD=>InternalSynchronizationwith2*D
----
|VectorTimeStamp:|Send:incrementitsithelement
|_Receive|Vi[i] =Vi[i] +1
Vi[j] =max(Vmessage[j], Vi[j]) forj ≠ i
|_VT1=VT2,
|_iff (ifandonlyif)
|_VT1[i] =VT2[i], foralli=1, … , N
|_VT1 ≤ VT2,
|_iffVT1[i] ≤ VT2[i], foralli=1, … , N
|_Twoeventsarecausallyrelatediff
|_VT1<VT2, i.e.,
|_iffVT1 ≤ VT2&
|_thereexistsjsuchthat
|_ :1 ≤ j ≤ N&VT1[j] <VT2 [j]
#SNAPSHOT_ALGORITHM_CHANDY_LAMPORT
WheneveraprocessPireceivesaMarkermessageonanincomingchannelCji
if (thisisthefirstMarkerPiisseeing)
Pirecordsitsownstatefirst
MarksthestateofchannelCjias “empty”
forj=1toNexcepti
PisendsoutaMarkermessageonoutgoingchannelCij
StartsrecordingtheincomingmessagesoneachoftheincomingchannelsatPi: Cji (forj=1toNexcepti)
else// already seen a Marker message
MarkthestateofchannelCjiasallthemessagesthathavearrivedonitsincerecordingwasturnedonforCji
______
AlltoAll:L=N/T
Gossip: N*logN/t(gossip) | N*log(N)/T
Ideal:[log(PM(T))/log(Pm)]/T
SWIM:e/(e-1)
Cristian :Errorisatmost (RTT-min2-min1)/2)|setTime:t+ (RTT+min2-min1)/2
NTP :o= (tr1 – tr2+ts2 – ts1)/2|
Lamport : max(localClock+messagTimestamp)
vector : Vi[i] =Vi[i] +1&&Vi[j] =max(Vmessage[j], Vi[j]) forj ≠ i
checkpointing : canrestartdistributedapplicationonfailure
Garbagecollectionofobjects : objectsatserversthatdon’thaveanyotherobjects (atanyservers) withpointerstothem
Deadlockdetection : Usefulindatabasetransactionsystems
Terminationofcomputation : UsefulinbatchcomputingsystemslikeFolding@Home, SETI@Home
FIFO:
NOMAX_increment_onlyWhileSending_receive_checkToDeliver!!!!
|_SendmulticastatprocessPj:
SetPj[j] =Pj[j] +1
IncludenewPj[j] inmulticastmessageasitssequencenumber
|_Receivemulticast:
IfPireceivesamulticastfromPjwithsequencenumberSinmessage
if (S==Pi[j] +1) then
delivermessagetoapplication
SetPi[j] =Pi[j] +1
elsebufferthismulticastuntilaboveconditionis true
|||CAUSAL
SendmulticastatprocessPj:
SetPj[j] =Pj[j] +1
IncludenewentirevectorPj[1…N] inmulticastmessageasitssequencenumber
Receivemulticast: IfPireceivesamulticastfromPjwithvectorM[1…N] (=Pj[1…N]) inmessage, bufferituntilboth:
ThismessageisthenextonePiisexpectingfromPj, i.e.,
M[j] =Pi[j] +1
Allmulticasts, anywhereinthegroup, whichhappened-beforeMhavebeenreceivedatPi, i.e.,
Forallk ≠ j: M[k] ≤ Pi[k]
i.e., Receiversatisfiescausality
Whenabovetwoconditionssatisfied, deliverMtoapplicationandsetPi[j] =M[j]
SRM (ScalableReliableMulticast)|UsesNAKs|Addsrandomdelays|exponentialbackoff2avoidNAKstorms
RMTP (ReliableMulticastTransportProtocol)|UsesACKs|
GossibStyleMulticast: #message : c*b*log(n)
#CHORD
Atnoden, sendqueryforkeyktolargestsuccessor/fingerentry <= k
ifnoneexist, sendquerytosuccessor(n)
ConsistentHashing=>withKkeysandNpeers, eachpeerstoresO(K/N) keys. (i.e., <c.K/N, forsomeconstantc)
r=2log(N)|lookupCorrectNess
NewPeersJoining:O((logN)*(logN))
#kelips:OnlyMetaInformation
Name,Memory,Lookup,#messagesForLookup
Napster,O(1)/O(N)@server,O(1),O(1)
Chord,log(N),log(N),log(N)
Kelips,O(rootN),o(1),disseminationtime(ologn)
Safety: Forallnon-faultyprocessesp: (p’selected= (q: aparticularnon-faultyprocesswiththebestattributevalue) orNull)
Liveness: Forallelectionruns: (electionrunterminates) &forallnon-faultyprocessesp: p’selectedisnotNull
Election:
Ring:election|elected|worst:Best=3n-1:2n
Bully:election|ok|coordinator|worst:best=o(n)sq:N-2(onemessageTransmissionTime)|LivenessNotGuranteed
GoogleChubby:live&safe|quoram|voteOnce|masterLease|MutualExclusion_locking
__Bandwidth|#msg sent in each enter and exit.
__Clientdelay|delayincurredbyaprocessateachenterandexitoperation (whennootherprocessisin, orwaiting)
__SynchDelay|timebetweenoneprocessexitingthecriticalsectionandthenextprocessenteringit (whenthereisonlyoneprocesswaiting
****MutualExclusion:enter(),AccessResource(),exit()
Safety|AtmostoneprocessexecuteCS
Liveness|EveryrequestforaCSisgrantedeventually
Ordering(desirable)|FIFO
CentralAlgorithm|safety+liveness|singlePointFailure|ordered@master
Bandwidth:clientdelay:syncDelay=2enter,1exit:2:2
RingBased|safe+live|noOrdering|
BW:CD:SD=1,1:0-N:1-(N-1)
Ricart_Agarwala|NoToken|Multicast|LamportTime|casuality|ordered
RickartAgarwala
||enter() atprocessPi
setstatetoWanted
multicast “Request” <Ti, Pi>toallprocesses, whereTi=currentLamporttimestampatPi
waituntilallprocessessendback “Reply”
changestatetoHeldandentertheCS
||OnreceiptofaRequest<Tj, Pj>atPi (i ≠ j):
if (state=Held) or (state=Wanted& (Ti, i) < (Tj, j))
addrequesttolocalqueue (ofwaitingrequests)
elsesend “Reply” toPj
||exit() atprocessPi
changestatetoReleasedand “Reply” toallqueuedrequests.
state"Wanted|Held|Released"|"Request|Reply"
BW:CD:SD=2(N-1),(N-1):1:1
Maekawa|voting_set_k|non_emptyIntersection|votesAtMostOnce|NeedsVoteFromAll
DOESNOTGURANTEELIVENESS|DEADLOCK|EACHWOULDVOTEFORITSELF
state"Wanted|Held|Released"|"VotedFlag"|"Request|Reply|Release"
WhenPireceivesaRequestfromPj:
if (state==HeldORvoted= true)
queueRequest
else
sendReplytoPjandsetvoted= true
WhenPireceivesaReleasefromPj:
if (queueempty)
voted= false
else
dequeueheadofqueue, sayPk
SendReplyonlytoPk
voted= true
BW:CD:SD=2rootN,rootN:(N-1),1:2
FLP:SchedulesCommutative|DisjointSchedulesarecommutative
s1={(p1,m1),(p2,m2),(p1,m1)}|s2={(p,m)}|pNotins1
Therealwaysexistsaninitialconfigthatisbivalent
startingfrombivalent,thereisalwaysanotherbivalentconfigreachable
|Routing|NetworkLayer
|_DistanceVectorRouting(RIP)|Proactive|
|_Link-State(OSPF)
|_TCP:connectionless|decomposition|reliable:acks|mult/demult|congestion|FIFO_order
|_DNS|Recursive:may_fail_
|_Iterative_LocalNameServerMostResponsibilty>BETTER|longerbutmorecontrol
RPC|CodeReuse|Dispatcher:inServer
|_LPC:exactlyOnce
|Concurrency|pessimistic|optimisitic
|_Pessimistic:locking(read|writeMode)|optimisticTwoPhaseLocking:serialEquivilance|GrowingPhase,ShrinkingPhase
|_Optimistic|firstCut,TimeStampOrder,MultiVersionControl
|_firstCutApproach:r/w@will-chk@commit-rollback:cascadingAborts
|_TimeStampOrder:read_if_lastW_by_lowerid,write_if_lastR_bylowerid
|_MultiVersionControl:multipleVers,readOnlyImmediatePrevious
EventualConsistency:Cassandra+Dynamo=lastWriteWins|
Riak=vectorClocks:sizeBased|TimeBasedPruning
#Replication|challenge|Transperancy+consistency
Why|Fault-tolerance|Loadbalancing|Replication=>HigherAvailability
Whatproblemisthis?Consensus!(It’salsocalledthe “AtomicCommitproblem”)
|1-f^k:K=#replica,f=probFailure:
|_Passive:Active=Master:treatAllSame
Transaction&Replication|NonReplicatedSystem:serialEquvilance
|_InReplicatedSys:serialEqui+OneCopySerializability:"""Theeffectoftransactionsperformedbyclientsonreplicatedobjectsshouldbethesameasiftheyhadbeenperformedoneatatimeonasinglesetofobjects"""
TransactionCommit:OnePhase|TwoPhase|Coordinator:Prepare+Yes/No+Commit<LOG>
#KeyValueStore
|_Cassandra|ReplicationStatergy|Simple,Network
|_Simple:Random,ByteOrder<rangeQueries>|
|_NetworkTopology<DCWide+withinDC_RACK>:Snitches:Simple|RackInferring<x.<DC>.<rack>.<node>|PropertyFile|ECS:ECSRegion<DC>+AvailabilityZone<rack>
|_Writes|HintedHandOff:replicasDown:Timeout|memTable<Append>Cache|SSTABLE_disk
|_Reads|slow:BLOOM+INDEX+SSTABLE+MULTIPLEREPLICA+MULTIPLE_sstables_rows
|_PHI:toSetLongerTimeoutForSlowerServers|log(CDForProbability(t_now – t_last))/log10
|_Quoram:W:Coordinator:waitsFor_W_toRepsond||asynchronous<FAST>Write&Return
ANY: anyserver (maynotbereplica)
Fastest: coordinatormaycachewriteandreplyquicklytoclient
ALL: allreplicas
Slowest, butensuresstrongconsistency
ONE: atleastonereplica|FasterthanALL, andensuresdurabilitywithoutfailuresQUORUM: quorumacrossallreplicasinalldatacenters (DCs)|Globalconsistency, butstillfast
LOCAL_QUORUM: quorumincoordinator’sDC|Faster: onlywaitsforquoruminfirstDCclientcontacts|
EACH_QUORUM: quorumineveryDC|LetseachDCdoitsownquorum: supportshierarchicalreplies
|_(W+N>N__W>N/2):
|_(W=1,R=1): veryfewwritesandreads
|_(W=N, R=1): greatforread-heavyworkloads
|_(W=N/2+1, R=N/2+1): greatforwrite-heavyworkloads
|_(W=1, R=N): greatforwrite-heavyworkloadswithmostlyoneclientwritingperkey
MongoDB|consistent,shardKey:Primary|collectionOfChunks
|_ReadPrefernce=primary/secondary/nearest
|_Write="acknowledged":primaryAcksImmediately|Journalled+replicaAck
|_Oplog:InMemory:JournalledToHarddisklater
HBASE:
ColFamily:someNameToColumNfamily|colQualifier:actualColumninColumnFamily
#GraphProcessing
|_Storm:MasterNode<NIMBUS>|DistribeCode+Assigntask+MonitorFailures
|_Worker<SuperVisor>:onServer|listenToWorkAssignedToMachines
|_Zookeeper|Coordinator|savesState
|_Pregel:Master|MaintainServerList/RestartonFailure/WebUI
|_Worker|Processesitsvertices
GraphPlotting:ForconsistentTime,Blocksize_shouldbelarger(fetchingtwice)
sensorOS:staticVsDynamic|predictableRunTime+noMethodcanCauseotherFailMemory
DSM:DownsideofInvalidate:FalseSharing:processShare
UpdateApproach:Allcanwriteatonce,sendonlythatpartofthepageupdated|multicast
InvalidateBetter:UpdateApproach|lotsofsharing|Writesaretosmallvariables|Pagesizeslarge
SelfStabilizing:Masking:TransparentToAPplicationLayer
holdTokenif "if" true: onthenexecutionpasstokentonextsuccessor
processjisx[j] {0, 1, 2, K-1}, whereK>N
p0ifx[0] =x[N-1] thenx[0] :=x[0] +1
pjj>0ifx[j] ≠ x[j-1] thenx[j] :=x[j-1]
One-copyupdatesemantics: whenfileisreplicated, itscontents, asvisibletoclients, arenodifferentfromwhenthefilehasexactly1replica