cs4513
play

CS4513 Dist ribut ed synchronizat ion needed f or t ransact ions - PDF document

I nt roduct ion Communicat ion not enough. Need cooperat ion Synchronizat ion CS4513 Dist ribut ed synchronizat ion needed f or t ransact ions (bank account via ATM) Dist ribut ed Comput er access t o shar ed r esour ce


  1. I nt roduct ion • Communicat ion not enough. Need cooperat ion � Synchronizat ion CS4513 • Dist ribut ed synchronizat ion needed f or – t ransact ions (bank account via ATM) Dist ribut ed Comput er – access t o shar ed r esour ce (net wor k pr int er ) Syst ems – ordering of event s (net work games where players have dif f erent ping t imes) Synchronizat ion (Ch 5) Clock Synchronizat ion Out line • When each machine has it s own clock, an event t hat occurred af t er anot her event may nevert heless be assigned • I nt ro (done) an earlier t ime • Consider make • Clock Synchronizat ion (next ) – Compiling machine compares t ime st amps • Global Time and St at e • Elect ion Algor it hms • Mut ual Exclusion • Dist ribut ed Transact ions • Same holds when using NFS mount • Can we set all clocks in a dist ribut ed syst em t o have t he same t ime? Physical Clocks Clock Synchronizat ion Algorit hms • “Exact ” t ime was comput ed by ast ronomers • Not ever y machine has UTC r eceiver – Take “noon” f or t wo days, divide by 24*60*60 � Mean solar second – I f one, t hen keep ot hers synchronized • • Comput er t imer s go of f H t imes/ sec, incr count er But … – Ear t h is slowing! (35 days over 300 million year s) • I deally, if H =60, 216,000 per hour ( d C / dt = 0) – Shor t t er m f luct uat ions (Magma cor e, and such) • But t ypical er r or s, 10 –5 , so 215,998 t o 216,002 – Could t ake many days f or aver age, but st ill er r oneous • Physicist s t ake over (J an 1, 1958) • Specs can give you – Count t r ansit ions of cesium 133 at om maximum dr if t r at e ( ρ ) • 9,192,631,770 == 1 solar second • Every ∆ t seconds, will – 50 cesium 133 clocks aver aged be at most 2 ρ∆ t apart • I nt er nat ional At omic Time ( TAI ) • I f want drif t of δ , r e- – To st op day f r om “shif t ing” (r emember , ear t h is synchronize every δ /2 ρ slowing) t r anslat e TAI int o Univer sal Coor dinat ed Time ( UTC ) � Various algs (next ) • UTC is br oadcast (short wave radio pulses) 1

  2. Crist ian' s Algorit hm Crist ian' s Algorit hm • Every δ /2 ρ , ask server f or t ime • What are t he problems? • Maj or – Client clock is f ast – What t o do? • Minor – Non-zero amount of t ime t o sender • Want one-way � (T 1 – T 0 )/ 2. Problems? – What t o do? – T 0 != T 1 ? I gnore. – Variance? Take average. Or smallest . – I ? C an subt ract , but need t o det ermine t ime. The Berkeley Algorit hm Decent ralized Algorit hms • Periodically (every R seconds), each machine br oadcast s cur r ent t ime • Collect t ime samples f or some t ime t ime ( S ) • Take average and set t ime • Can discard m so m f ault y clocks don’t hurt • Can improve by comput ing (T 1 – T 0 )/ 2 a) The t ime daemon asks all t he ot her machines f or t heir clock – Need probes t o obt ain values • Used by Net work Time Prot ocol (NTP) b) The machines answer c) The t ime daemon t ells everyone how t o adj ust t heir clock – Worldwide accuracy of 1-50 msec Crist ian’s and Berkeley’s are cent ralized . P roblems? Lamport Timest amps Out line • Often don’t need time, but ordering a � b ( happens before ) • I nt ro (done) • Clock Synchronizat ion (done) • Global Time and St at e (next ) • Elect ion Algor it hms • Mut ual Exclusion • Dist ribut ed Transact ions (impossible) a) Each processes wit h own clock wit h dif f erent rat es. b) Lamport ' s algorit hm correct s t he clocks. c) Can add machine I D t o break t ies 2

  3. Use Example: Tot ally-Or der ed Consist ent Global St at e Mult icast ing • Need for state of distributed system, say, for termination detection (+$100) (+1%) (San Francisco) (New York) • San Fran cust omer adds $100, NY bank adds 1% int erest – San Fran will have $1,111 and NY will have $1,110 • Updat ing a replicat ed dat abase and leaving it in an a) A consist ent cut inconsist ent st at e. • b) An inconsist ent cut Can use Lamport ’s t o t ot ally order • How do ensur e always a consist ent cut ? Consist ent Global St at e (2) Consist ent Global St at e (3) b) Pr ocess Q r eceives M f or t he f ir st t ime and r ecor ds it s local st at e. Sends M on all out going links c) Q r ecor ds all incoming messages d) Q r eceives M f or it s incoming channel and f inishes r ecor ding t he st at e of t he incoming • Pr ocesses all connect ed. Can init iat e st at e message channel ( M ) • Can t hen send st at e t o init iat ing pr ocess a) Or ganizat ion of a pr ocess and channels f or a dist r ibut ed snapshot • Syst em can st ill pr oceed nor mally Out line Elect ion Algorit hms • I nt ro (done) • Of t en need one process as a coordinat or • Clock Synchronizat ion (done) • All processes in dist ribut ed syst ems may • Global Time and St at e (done) be equal • Elect ion Algor it hms (next ) – Assume have some “I D” t hat is a number • Mut ual Exclusion • Need way t o “elect ” process wit h t he • Dist ribut ed Transact ions highest number as leader 3

  4. The Bully Algorit hm (1) The Bully Algor it hm (2) • Pr ocess 4 not ices 7 down • Pr ocess 4 holds an elect ion d) P rocess 6 t ells process 5 t o st op • e) P rocess 6 wins and t ells everyone Pr ocess 5 and 6 r espond, t elling 4 t o st op • Event ually “biggest ” (bully) wins • Now 5 and 6 each hold an elect ion • I f processes 7 comes up, st art s elect ions again A Ring Algorit hm Out line • Coor dinat or down, st ar t ELECTI ON – Send message down ring, add I D • I nt ro (done) – Once around, change t o COORDI NATOR (biggest ) • Clock Synchronizat ion (done) • Global Time and St at e (done) • Elect ion Algor it hms (done) • Mut ual Exclusion (next ) • Dist ribut ed Transact ions • Even if t wo ELECTI ONS st ar t ed at once, ever yone will pick same leader Mut ual Exclusion: A Dist ribut ed Algorit hm A Cent ralized Algorit hm a) P rocesses 0 and 2 want t o ent er t he same crit ical region a) Pr ocess 1 asks t he coor dinat or f or per mission t o ent er a cr it ical at t he same moment . r egion. Per mission is gr ant ed b) P rocess 1 doesn’t want t o, says “OK”. P rocess 0 has t he b) Pr ocess 2 t hen asks per mission t o ent er t he same cr it ical r egion. lowest t imest amp, so it wins. Queues up “OK” f or 2. The coor dinat or does not r eply. (Or , can say “denied”) c) When pr ocess 1 exit s t he cr it ical r egion, it t ells t he coor dinator, c) When process 0 is done, it sends an OK t o 2 so can now when t hen replies t o 2. ent er t he crit ical region. • But cent r alized, single point of f ailur e • (Again, can modif y t o say “denied”) 4

  5. A Token Ring Algorit hm Mut ual Exclusion Algorit hm Comparison Messages per Delay before entry (in Algorithm Problems entry/exit message times) 3 2 Coordinator crash Centralized Distributed 2 ( n – 1 ) 2 ( n – 1 ) Process crash Lost token, 1 to ∞ Token ring 0 to n – 1 process crash a) An unor der ed gr oup of pr ocesses on a net wor k. b) A logical r ing const r uct ed in sof t war e. • Cent ralized most ef f icient • Pr ocess must have t oken t o ent er . • Token ring ef f icient when many want t o use • I f don’t want t o ent er , pass t oken along. cr it ical r egion • I f host down, r ecover r ing. I f t oken lost , r egener at e t oken. I f in cr it ical sect ion long? Out line The Transact ion Model • I nt ro (done) • Gives you mut ual exclusion plus… • Clock Synchronizat ion (done) • Consider using PC (Quicken) t o: • Global Time and St at e (done) – Wit hdr aw $a f r om account 1 • Elect ion Algor it hms (done) – Depost $a t o account 2 • Mut ual Exclusion (done) • I f int errupt bet ween 1) and 2), $a gone! • Dist ribut ed Transact ions (next ) • Mult iple it ems in single, at omic act ion – I t all happens, or none – I f process backs out , as if never st art ed Example: Reserving Flight f rom Tr ansact ion Pr imit ives Whit e Plains t o Nairobi BEGIN_TRANSACTION BEGIN_TRANSACTION Primitive Description reserve WP -> JFK; reserve WP -> JFK; reserve JFK -> Nairobi; reserve JFK -> Nairobi; BEGIN_TRANSACTION Make the start of a transaction reserve Nairobi -> Malindi; reserve Nairobi -> Malindi full => END_TRANSACTION Terminate the transaction and try to commit END_TRANSACTION ABORT_TRANSACTION (a) (b) ABORT_TRANSACTION Kill the transaction and restore the old values READ Read data from a file, a table, or otherwise a) Tr ansact ion t o r eser ve t hr ee f light s commit s WRITE Write data to a file, a table, or otherwise b) Tr ansact ion abor t s when t hir d f light is unavailable • Above may be syst em calls, libr ar ies or st at ement s • The “all-or-not hing” is one pr oper t y. Ot her s: in a language (Sequent ial Quer y Language or SQL) 5

Recommend


More recommend