Lesle Laports e, locks & the Orderng of Events n a Dstrbuted Syste Joseph Sprng Departent of oputer Scence Dstrbuted Systes and Securty Overvew Introducton he artal Orderng Logcal locks Orderng the Events otally Anoalous Behavour hyscal locks oncluson Appendx Laports: e, locks and Events 1 Laports: e, locks and Events 2 Introducton Laports: e, locks and Events 3 Introducton oncepts: e Fundaental to our way of thnkng Derved fro ore basc concept of order n whch events occur eporal Orderng of Events ervades thnkng about systes Must be carefully exaned for Dstrbuted Systes Laports: e, locks and Events 4 Introducton Dstrbuted Syste: A collecton of dstnct processes whch are spatally separated and whch councate wth one another by exchangng essages E.g. ARA net opare to prevous defntons Includes sngle coputer entral control unt, eory unts, nput-output channels are separate processes aper concerned prarly wth systes of spatally separated coputers Soetes possble to say that one of two events occurred frst Laports: e, locks and Events 5 Introducton Dscusson nvolves happened before relaton a partal orderng of the events n a syste dstrbuted algorth for extendng happened before relaton to a consstent otal Orderng of all events Mechans for pleentng a dstrbuted syste Illustraton va synchronsaton proble Unexpected anoalous behavour can occur f orderng obtaned fro algorth s dfferent to that perceved by the user Avoded through ntroducton of real physcal clocks Descrbe ethod for synchronsaton of clocks Derve upper bound for drft Laports: e, locks and Events 6
Introducton he roble? he artal Orderng Laports: e, locks and Events 7 Laports: e, locks and Events 8 he Syste Assuptons Syste coposed of a collecton of processes Each process conssts of a sequence of events E.g. executon of a subprogra, executon of a sngle achne nstructon Events of a process for a sequence Event a occurs before b f a happens before b In other words: A sngle process s defned to be a set of events wth an a pror total orderng, (see footnote 1 regardng events) Sendng or recevng a essage s an event n a process Laports: e, locks and Events 9 he Happened Before Relaton Defnton he relaton " " on the set of events of a syste s the sallest relaton satsfyng the followng three condtons: 1. If a and b are events n the sae process, and a coes before b, then a b 2. If a s the sendng of a essage by one process and b s the recept of the sae essage by another process, then a b 3. If a b and b c then a c Laports: e, locks and Events 10 he Happened Before Relaton wo events a and b are sad to be concurrent f a b and b a Assuptons (contnued) a a for any event a We note that s an rreflexve partal orderng on the set of all events n the syste Laports: e, locks and Events 11 Space e Dagra Horzontal drecton space Vertcal drecton - te Up drecton postve, ndcatng later tes Dots denote events Vertcal lnes denote processes Wavy lnes denote essages We Note (assupton/set up odel (p.559)) Messages ay be receved out of order Sendng of several essages ay be consdered a sngle event Recept of a sngle essage does not concde wth the sendng or recept of any other essage Laports: e, locks and Events 12
Happened Before relaton a b eans that one can go fro a to b n the dagra by ovng forward n te along process and essage lnes Exaple p r 1 4 snce p q, by HB2; q q, by HB1; 1 2 2 4 q r, by HB2 and r r by HB1 4 3 3 4 Hence by repeated applcaton of HB3 p r 1 4 Laports: e, locks and Events 13 Happened Before relaton Alternatve vew of defnton a b eans that event a can causally affect event b wo events events are sad to be concurrent f nether can causally affect the other Exaple p and q 3 3 are concurrent, snce process cannot know what process Q dd at q the essage at p 4 3 untl t receves Laports: e, locks and Events 14 Happened Before relaton Note ror to event p Q was plannng to do at q 4 can at ost, know what 3 Space-e Dagra See Laports aper hs follows snce q 2 s the event recevng a essage fro, and ths ay or ay not reveal nforaton regardng q 3 Laports: e, locks and Events 15 Laports: e, locks and Events 16 Logcal locks Abstract locks he Model A clock s ust a way of assgnng a nuber to an event he nuber s nterpreted as the te at whch an event occurred Hence we ay eploy Logcal rather than hyscal clocks We proceed as follows: Laports: e, locks and Events 17 Laports: e, locks and Events 18
Logcal locks More precsely: We defne a clock for each process to be a functon whch assgns a nuber a to any event a n that process he entre syste of clocks s represented by a functon assgns to any event b n process nuber b = b Laports: e, locks and Events 19 the Logcal locks Note: No assupton s ade regardng any relaton between the < a > and physcal te We thnk of these clocks as Logcal rather than hyscal he logcal clocks ay be ncreented by counters wth no actual tng echans Laports: e, locks and Events 20 Logcal locks Queston: What does t ean for such a set of clocks to be correct? Answer: Snce we cannot base our defnton on physcal te we base t on the order n whch events occur Strongest reasonable assupton: If an event a occurs before event b then event a should happen at an earler te than event b Laports: e, locks and Events 21 lock ondton More forally we have: For any events a and b : f a b then ( a) < ( b) Note the converse doesn t hold! In the sense that: f a b then a = b Laports: e, locks and Events 22 lock ondton he clock condton s satsfed f the followng two condtons hold: 1 If a and b are events n process, and a coes before b, then ( a) < ( b) locks and the Space-e Dagra See Laports aper 2 If a s the sendng of a essage by process,and b s the recept of that essage by process () a < ( b), then Laports: e, locks and Events 23 Laports: e, locks and Events 24
locks and the Space-e Dagra See Laports aper locks and the Space-e Dagra See Laports aper Laports: e, locks and Events 25 Laports: e, locks and Events 26 Introducng locks nto rocesses Assue rocesses are now algorths Events represent actons durng the executon of the processes We consder how to ntroduce clocks nto the processes whch satsfy the clock condton Laports: e, locks and Events 27 Introducng locks nto rocesses We note: rocess 's clock s represented by regster, so a represents the value contaned by event a he value durng the wll change between events so that changng consttute an event doesn't Laports: e, locks and Events 28 Introducng locks nto rocesses We note: o guarantee the syste of clocks satsfes the clock condton we nsure that condtons are stsfed and 1 2 Introducng locks nto rocesses For condton 1 the followng pleentaton rule s obeyed: IR1. Each process ncreents between any two successve events Laports: e, locks and Events 29 Laports: e, locks and Events 30
Introducng locks nto rocesses For condton estaps 2 the use of s requred. Each essage contans a testap whch corresponds to the te the essage s sent. Upon recept of a essage wth testap a process ust advance ts clock to be later than. Laports: e, locks and Events 31 Introducng locks nto rocesses More precsely we have: IR2. a) If event a s the sendng of a essage by a process then the essage contans a testap b) Upon recevng a essage Laports: e, locks and Events 32 = a process sets greater than or equal to ts present value and greater than Note he pleentaton rules IR1 and IR2 Iply that the clock condton s satsfed Guarantee a correct syste of logcal clocks We now consder the concept of total orderng on the set of all syste events: Orderng he Events otally Laports: e, locks and Events 33 Laports: e, locks and Events 34 otal Orderng We acheve ths by: Orderng the events accordng to the tes at whch they occur Breakng tes by usng any arbtrary total orderng of the processes Laports: e, locks and Events 35 otal Orderng We defne a relaton as follows: If a s an event n process and and b s an event n process then a b f and only f ether: ) a < b or ) a = b and hs defnes a total orderng he clock condton ples that f a b then a b A copletng of the happened before partal orderng to a total orderng Laports: e, locks and Events 36
otal Orderng - Exaple he Mutual Excluson roble We seek an Algorth satsfyng: 1. A process whch has been granted a resource ust release the resource before t can be granted to another process 2. Dfferent requests for a resource ust be granted n the order n whch they are ade 3. If every process whch s granted a resource eventually releases t then every request s eventually granted Laports: e, locks and Events 37 otal Orderng - Exaple he Mutual Excluson roble We assue that the resource s ntally granted to one process o solve the proble a syste of clocks satsfyng IR1 and IR2 s pleented to defne a total orderng of all events, hence a total orderng of all requests and release operatons Laports: e, locks and Events 38 Mutual Excluson roble Splfyng Assuptons 1. For any two processes and we assue that essages sent fro to are receved n the sae order as sent 2. Every essage s receved hese are reasonable - the use of the ARQ protocol accoodates the splfcaton Laports: e, locks and Events 39 Mutual Excluson roble Splfyng Assuptons 3. A process ay send esages drectly to every other process 4. Every process antans ts own request queue, whch s not seen by other processes Assue request queues contan a sngle essage : requests resource where 0 0 0 s the process ntally granted the resource and value of any clock 0 s less than the ntal Laports: e, locks and Events 40 Mutual Excluson roble he Algorth (actons defned by each rule are assued to be a sngle event) 1. o request a resource, a process sends the essage : requests resource to every other process and puts that essage on ts request queue, s the testap of the essage 2. When process receves the essage : requests resource t places t on ts request queue and sends a (testaped) acknowledgeent essage to Laports: e, locks and Events 41 Mutual Excluson roble he Algorth 3. o release the resource, process reoves any : requests resource essage fro ts request queue and sends a (testaped) releases resource essage to every other process 4. When process receves a releases resource essage, t reoves any : requests resource essage fro ts request queue Laports: e, locks and Events 42
Mutual Excluson roble 5. b) has receved a essage fro every other process testaped later than Verfy that the algorth defned by these rules satsfes condtons 1), 2) and 3) of the Mutual Excluson roble Anoalous Behavour Laports: e, locks and Events 43 Laports: e, locks and Events 44 Strong lock ondton Exaple Request a s ssued on coputer A erson akng request at A phones frend at coputer B n another cty and gets frend to ssue a request b It s possble that the testap at B wll have a lower testap than that at A and be ordered before request a Laports: e, locks and Events 45 Strong lock ondton Let S denote the set of all syste events Let S = S {' relevant external events'} Let denote the 'happened before' relaton for S In the above exaple we have a b but a b No algorth based entrely on events n S whch does not relate the events to other events n S can guarantee that request a s ordered before request b Laports: e, locks and Events 46 Strong lock ondton wo ethods avalable: 1. Get frend at B to request a testap later than that of a 2. onstruct a syste of clocks that satsfy the 'Strong lock ondton' For any events a, b S f a b then a < b hyscal locks hs s stronger than the ordnary lock condton snce s stronger than It s not n general satsfed by logcal clocks Laports: e, locks and Events 47 Laports: e, locks and Events 48
Overvew We use physcal clocks to elnate anoalous behavour oncluson Laports: e, locks and Events 49 Laports: e, locks and Events 50 Overvew Introducton he artal Orderng Logcal locks Orderng the Events otally Anoalous Behavour hyscal locks hyscal locks oncluson Appendx Laports: e, locks and Events 51 Appendx Laports: e, locks and Events 52 Overvew Introducton he artal Orderng Logcal locks Orderng the Events otally Anoalous Behavour hyscal locks hyscal locks oncluson Appendx Laports: e, locks and Events 53 Suary Introducton he artal Orderng Logcal locks Orderng the Events otally Anoalous Behavour hyscal locks oncluson Appendx Laports: e, locks and Events 54