Time and global states Time and global states Jerry Eriksson, VT-01 Jerry Eriksson, VT-01 Important issues in distributed Important issues in distributed systems systems � Timestamping Timestamping � files, transactions files, transactions � Algorithms depend upon clock Algorithms depend upon clock synchronization synchronization � Space and context is beyound the scope of Space and context is beyound the scope of this book (belongs to mobile computing) this book (belongs to mobile computing) Today Today � Physical clocks that can be approximately Physical clocks that can be approximately synchronized using message passing synchronized using message passing � Logical clocks Logical clocks � Algorithms whose purpose is to capture Algorithms whose purpose is to capture global states of distributed systems as they global states of distributed systems as they execute execute 1
Physical clocks Physical clocks � Clocks Clocks � Clock skew and clock drift Clock skew and clock drift � Coordinated Universial time Coordinated Universial time � International standard. Radio waves. GPS! International standard. Radio waves. GPS! Network Synchronizing physical clocks Synchronizing physical clocks � External sources External sources � External synchronization External synchronization � Internal synchronization Internal synchronization � Clocks does not have to be accurate to be Clocks does not have to be accurate to be correct correct � Easy in synchronous systems Easy in synchronous systems Christian´s method for Christian´s method for synchronizing clocks in intranets synchronizing clocks in intranets � Time server is used. Uses UTC Time server is used. Uses UTC � Round-trip delay must be sufficiently short Round-trip delay must be sufficiently short compared to accurary compared to accurary m r m t p Time server,S 2
Cristian’s method Cristian’s method � The client asks the server The client asks the server � The server answer in a message The server answer in a message � Minimum transmission time Minimum transmission time � Accuracy in the interval Accuracy in the interval � t+min, t + tround - min t+min, t + tround - min � Drawback: a single server can fail Drawback: a single server can fail The Berkeley algorithm The Berkeley algorithm � A coordinatior computer is chosen as A coordinatior computer is chosen as master, which poll the other computers master, which poll the other computers (slaves). (slaves). � The slaves sends back their clocks The slaves sends back their clocks � Fault-tolerant average is computed and sent Fault-tolerant average is computed and sent back to the slaves. back to the slaves. � A new master can be chosen if the current A new master can be chosen if the current ones chrashes. ones chrashes. The Network Time Protocol - The Network Time Protocol - on the internet on the internet � Provide a service enabling clients across the Provide a service enabling clients across the internet to be synchronized accurately internet to be synchronized accurately � Provide a reliable service that can survive Provide a reliable service that can survive lengthy losses of connectivity lengthy losses of connectivity � Enable clients to resynchronize sufficiently Enable clients to resynchronize sufficiently frequently to offset the rates of drift found frequently to offset the rates of drift found in most computers in most computers � Provide protection against interference Provide protection against interference 3
The Network Time Protocol - The Network Time Protocol - focus on the internet focus on the internet � Based on virtually hierarcial network of Based on virtually hierarcial network of servers servers � Primary server direct connected to UTC. Primary server direct connected to UTC. � Lowest level (leaf) is the users workstation Lowest level (leaf) is the users workstation 1 2 2 3 3 3 Note: Arrows denote synchronization control, numbers denote strata. NTP NTP � Fault-tolerant, re-building possible Fault-tolerant, re-building possible � Multicast mode, high-speed LAN Multicast mode, high-speed LAN � Procedure-call mode, similar to Chistian’s Procedure-call mode, similar to Chistian’s algorithm algorithm � Symmetric mode Symmetric mode � Uses UDP Uses UDP NTP NTP Server B T i-2 T i-1 Time m m' Time Server A T i- 3 T i 4
Logical time and logical clocks Logical time and logical clocks � Physical clocks cannot be used to order Physical clocks cannot be used to order events processes at different computers. events processes at different computers. � Two intuitive points Two intuitive points � If two events occured at the same process, then If two events occured at the same process, then they occured in the order in which the process they occured in the order in which the process observed them. observed them. � The event of sending occured before the The event of sending occured before the receiving the message receiving the message Happend-before relations Happend-before relations � 1: x->y 1: x->y � 2:send(m) -> receive(m) 2:send(m) -> receive(m) � 3: x->y and y->z, imply x->z 3: x->y and y->z, imply x->z p 1 a b m 1 p 2 Physical time c d m 2 p 3 e f Logical clocks Logical clocks � Software counter.Time-stamp denoted by L. Software counter.Time-stamp denoted by L. � HB-relation HB-relation � LC1: Li is incremented before each event is LC1: Li is incremented before each event is issued at p issued at p i ; L ; L i = L = L i + 1 + 1 � LC2a: When p LC2a: When p i sends sends m , it piggybacks on , it piggybacks on m the the value, t = L value, t = L i . � LC2b: On receiving (m, t), p LC2b: On receiving (m, t), p j computes L computes L j = = max(L j , t)+1 max(L , t)+1 � Observe L(b) > L(e), but b||e. Observe L(b) > L(e), but b||e. 5
Logical clocks Logical clocks � Totally ordered logical clocks Totally ordered logical clocks � Use identifiers of the processes Use identifiers of the processes 1 2 p 1 a b m 1 3 4 Physical p 2 time c d m 2 5 1 p 3 e f Vector clocks Vector clocks � Create totally ordered on eventes Create totally ordered on eventes � Use a vector Use a vector � Four rules Four rules � Compare vector timestamps Compare vector timestamps � More expensive More expensive Vector clocks Vector clocks (1,0,0) (2,0,0) p 1 a b m 1 (2,1,0) (2,2,0) Physical p 2 time c d m 2 (0,0,1) (2,2,2) p 3 e f 6
Global states Global states � Distributed garbage collection Distributed garbage collection � Distributed deadlock detection Distributed deadlock detection � Distributed termination detection Distributed termination detection � Distributed debugging Distributed debugging Global states; examples Global states; examples p 1 p 2 object reference message a. Garbage collection garbage object p 2 p 1 wait-for b. Deadlock wait-for p 2 p 1 activate passive passive c. Termination Global states and consistent cuts Global states and consistent cuts � Essential problem: Absence of global time Essential problem: Absence of global time � Construct a meaningful global state, using Construct a meaningful global state, using local state information local state information 7
Global states and consistent cuts Global states and consistent cuts 0 1 2 3 e 1 e 1 e 1 e 1 p 1 m 1 m 2 Physical p 2 time 0 1 2 e 2 e 2 e 2 Inconsistent cut Consistent cut Definitons Definitons � Run: total ordering of all events in a global Run: total ordering of all events in a global history that is consistent with each local history that is consistent with each local history history � Linearization: Run + consitent with HB- Linearization: Run + consitent with HB- relation relation � Predicate: Once ’true’, always ’true’ Predicate: Once ’true’, always ’true’ ’Snap-shot’-algorithm ’Snap-shot’-algorithm � Record a set of global state that are Record a set of global state that are consistent. Assumes that consistent. Assumes that � neither channels nor processes fail neither channels nor processes fail � channels are unidirectional and provide FIFO-ordering channels are unidirectional and provide FIFO-ordering message delivery message delivery � processes strongly connected processes strongly connected � any process may initiate a global snapshot at any time any process may initiate a global snapshot at any time � the process may continue their execution and send and the process may continue their execution and send and receive normal messages while the snapshot takes place receive normal messages while the snapshot takes place 8
Recommend
More recommend