Slides for Chapter 11: Time and Global State From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, Pearson Education 2005 Edited and supplemented by Jonne Itkonen,! for TIE427 (2011)! Figure 11.1 Skew between computer clocks in a distributed system Network Kuva yrittää vain kertoa, että hajautetun järjestelmän kellot ovat aina eri ajassa. Nykyään, kun kaikki on nopeaa ja tehokasta, on järjettömän pieneltä tuntuvalla aikaerollakin merkitys. On jopa jouduttu siirtämään etäkoneita lähemmäs palvelimia, jotta bitin kulkuaika piuhassa pienenisi, latenssi vähenisi.
Figure 11.2 Clock synchronization using a time server m! r! m! t! p! Time server,s! Cristian s algorithm:! 1. p requests time in message m r.! 2. S returns time t in message m t.! 3. p records round-trip time T round! 4. p estimates time to change as t+t round /2," accuracy being ± (T round /2-min), where min is the" time between sending m r and inserting time to m t.! Algoritmi on arka palvelimen rikkoutumiselle ja huijaavalle palvelimelle.! Figure 11.3 An example synchronization subnet in an NTP implementation 1! Stratum 1 tietokone kiinni atomikellossa tai vastaavassa ajanlähteessä. 2! 2! 3! 3! 3! Note: Arrows denote synchronization control, numbers denote strata.
Figure 11.4 Messages exchanged between a pair of NTP peers Server B! T! i!-2! T! i-1! Tim m! m'! Server A! T! i!-!3! T! i! Tim NTP laskee näiden perusteella siirtymät (offset) o i ja viipeet d i jokaiselle viestiparille. Näitä suodattamalla, valikoimalla ja tallentamalla saadaan lasketuksi siirtymä o palvelinten kellojen välillä. Figure 11.5 Events occurring at three processes p 1 a b m 1 c d m 2 Physical time p 3 e Tapahtumien a ja e järjestystä ei voida määrittää tapahtui ennen -relaatiolla, joten niiden sanotaan olevan samanaikaisia (concurrent). f
Figure 11.6 Lamport timestamps[1978] for the events shown in Figure 11.5 1 2 p 1 a b m 1 3 4 c d m 2 Physical time p 3 1 e LC1:! L i is incremented before each event is issued at process p i : L i := L i + 1.! LC2:! (a) When a process p i sends a message m, it piggybacks on m the value t = L i.! (b) On receiving (m,t), a process p j computes L j := max(l j,t) and! then applies LC1 before timestamping the event receive(m).! f 5 Lamportin mallin ongelmat ja vektorikellot! Lamport: e! e L(e) < L(e ), mutta ei toisinpäin! Vektorikelloilla hoituu (Mattern [1989], Fidge [1991]): " VC1: Initially, V i [j] = 0, for i,j=1,2,,n. " VC2: Just before p i timestamps an event, it sets V i [i]:=v i [i]+1 " VC3: p i includes the value t=v i in every message it sends. " VC4: Whe pi receives a timestamp t in a message, it sets V i [j]:=max(v i [j],t[j]), for j=1,2,,n. Taking the componentwise maximum of two vector timestamps in this way is known as a merge operator.! V:n koko on huima isoilla prosessimäärillä " Korjaus: muutoksen siirto, Lamport-riittävä
Figure 11.7 Vector timestamps for the events shown in Figure 11.5 (1,0,0) (2,0,0) p 1 a b m 1 (2,1,0) (2,2,0) c d m 2 Physical time p 3 (0,0,1) e f (2,2,2) Figure 11.8 Detecting global properties p 1 a. Garbage collection object reference message garbage object p1 wait-for b. Deadlock wait-for p1 c. Termination passive activate passive
! Seuraavat kalvot käsittelevät tarkemmin globaalin tilan määrittelyä. Ne ovat mukana mielenkiinnon vuoksi, eivätkä kuulu tenttiin. Figure 11.9 Cuts 0! 1! 1! 1! 2! 1! 3! 1! p! 1! p! 2! m! 1! m! 2! 0! 2! 1! 2! 2! 2! Physical! tim Inconsistent cut! Consistent cut! Viestin m 1 :n lähettäminen ei sisälly leikkaukseen, joten leikkaus on epäyhtenäinen. Viestin m 2 :n vastaanotto ei sisälly leikkaukseen, mutta leikkaus on silti yhtenäinen.
Figure 11.10 Chandy and Lamport s snapshot algorithm Marker receiving rule for process p i! On p i s receipt of a marker message over channel c:!!if (p i has not yet recorded its state) it!!records its process state now;!!records the state of c as the empty set;!!turns on recording of messages arriving over other incoming channels;!!else!! p i records the state of c as the set of messages it has received over c!!since it saved its state.!!end if! Marker sending rule for process p i! After p i has recorded its state, for each outgoing channel c:!! p i sends one marker message over c!!(before it sends any other message over c).! Figure 11.11 Two processes and their initial states p c 1 2 c 1 $1000 (none) $50 2000 account widgets account widgets
Figure 11.12 The execution of the processes in Figure 11.11 1. Global state S 0 <$1000, 0> p 1 c 2 (empty) <$50, 2000> c 1 (empty) 2. Global state S 1 <$900, 0> p 1 c 2 (Order 10, $100), M <$50, 2000> c 1 (empty) 3. Global state S 2 <$900, 0> p 1 c 2 (Order 10, $100), M <$50, 1995> c 1 (five widgets) 4. Global state S 3 <$900, 5> p 1 c 2 (Order 10, $100) <$50, 1995> c 1 (empty) (M = marker message) Figure 11.13 Reachability between states in the snapshot algorithm actual execution 0!, 1!,...! S! recording! init! recording! S! final! begins! ends! pre-snap: S! snap! '! 0!,'! 1!,...'! R-1! post-snap: '! R!,'! R+1!,...!
Figure 11.14 Vector timestamps and variable values for the execution of Figure 11.9 p! 1! p! 2! (1,0)! (2,0)! (3,0)! (4,3)! x! 1! = 1! x! 1! = 100! x! 1! = 105! m! 1! m! 2! x! 2! = 100! x! 2! = 95! x! 2! = 90! (2,1)! (2,2)! (2,3)! Cut C! 1! x! 1! = 90! Cut C! 2! Physical! tim Figure 11.15 The lattice of global states for the execution of Figure 11.14 Level 0! 1! 2! 3! 4! 5! 6! 7! S! 00! S! 10! S! 20! S! 30! S! 21! S! 31! S! 22! S! 32! S! 23! S! 33! S! 43! Sij = global state after i events at process 1! and j events at process 2!
Figure 11.16 Algorithms to evaluate possibly! and definitely! Figure 11.17 Evaluating definitely!" Level 0 F 1 F 2 F F = (!(S) = False); T = (!(S) = True) 3 F T 4 F 5?