Presentation on theme: "Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps."— Presentation transcript:
Logical Clocks (2)
Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps
Readings r Van Steen and Tanenbaum: 5.2 r Coulouris: 10.4 r L. Lamport, “Time, Clocks and the Ordering of Events in Distributed Systems,” Communications of the ACM, Vol. 21, No. 7, July 1978, pp r C.J. Fidge, “Timestamps in Message-Passing Systems that Preserve the Partial Ordering”, Proceedings of the 11 th Australian Computer Science Conference, Brisbane, pp , February 1988.
Problems with Lamport Clocks r Lamport timestamps do not capture causality. r With Lamport’s clocks, one cannot directly compare the timestamps of two events to determine their precedence relationship. m If C(a) < C(b) is not true then a b is also not true. m Knowing that C(a) < C(b) is true does not allow us to conclude that a b is true. m Example: In the first timing diagram, C(e) = 1 and C(b) = 2; thus C(e) < C(b) but it is not the case that e b
Problems with Lamport Clocks r Why is this important? r For the banking example, it doesn’t matter what order operations are executed at each replica. r It only matters that all replicas execute the operations in the same order. This is total order. r Causal order is used when a message received by a process can potentially affect any subsequent message sent by that process. Those messages should be received in that order at all processes. Unrelated messages may be delivered in any order. r Do Lamport timestamps support causal order? m NO
Example Application:Bulletin Board r The Internet’s electronic bulletin board (or Google’s Groups or any chat service) r Users (processes) join specific groups (discussion groups). r Postings, whether they are articles or reactions, are multicast to all group members. r Could use a totally-ordered multicasting scheme. m Should we be doing this?
Display from a Bulletin Board Program r Users run bulletin board applications which multicast messages r One multicast group per topic (e.g. os.interesting) r Require reliable multicast - so that all members receive messages (more on this later) r Ordering: Bulletin board: os.interesting Item FromSubject 23A.HanlonMach 24G.JosephMicrokernels 25A.HanlonRe: Microkernels 26T.L’HeureuxRPC performance 27M.WalkerRe: Mach end Figure Colouris total (makes the numbers the same at all sites) FIFO (gives sender order) causal (makes replies come after original message)
Example Application: Bulletin Board r A totally-ordered multicasting scheme does not imply that if message B is delivered after message A, that B is a reaction to A. r The receipt of an article precedes the posting of a reaction. r The receipt of the reaction to an article should always follow the receipt of the article.
Example Application: Bulletin Board r If we look at the bulletin board example, it is allowed to have items 26 and 27 in different order at different sites. r Items 25 and 26 may be in different order at different sites.
Problem with Lamport Clocks r The main problem is that a simple integer clock cannot order both events within a process and events in different processes. r C. Fidge developed an algorithm that overcomes this problem. r Fidge’s clock is represented as a vector [v 1,v 2,…,v n ] with an integer clock value for each process (v i contains the clock value of process i). This is a vector timestamp.
Vector Timestamps r Properties of vector timestamps m v i [i] is the number of events that have occurred so far at P i m If v i [j] = k then P i knows that k events have occurred at P j
Vector Timestamps r A vector clock is maintained as follows: Initially all clock values are set to the smallest value (e.g., 0). The local clock value is incremented at least once before each event of interest (in our case this will be a send event) in a process, q i.e., v q [q] = v q [q] +1 m Let v q be piggybacked on the message sent by process q to process p; We then have: For i = 1 to n do v p [i] = max(v p [i], v q [i] );
Vector Timestamp r For two vector timestamps, v a and v b m v a v b if there exists an i such that v a [i] v b [i] m v a ≤ v b if for all i v a [i] ≤ v b [i] m v a < v b if for all i v a [i] ≤ v b [i] AND v a is not equal to v b r Events a and b are causally related if v a < v b or v b < v a. r Vector timestamps can be used to guarantee causal message delivery.
Example Application: Bulletin Board r Each process P i has an array V i where V i [j] denotes the number of events that process P i knows have taken place for P j. m In this application “events” refers to the sending of a message. m Thus if V i [j] = 6 then P i knows that P j has sent 6 messages.
Example Application: Bulletin Board r Let V i be piggybacked on the message sent by process P i to process P j ; When process P j receives the message, then P j does the following: For k = 1 to n do V j [k] = max(V i [k], V j [k] ); Thus if process i knows that process k sent 5 messages (V i [k] =5 and V j [k] = 3) then process j didn’t know about the latest two messages sent by process k.
Example Application: Bulletin Board r When process i sends a message, it does the following: V i [i] = V i [i] + 1; r This is basically saying that the number of messages process i has sent is incremented by one.
Example Application: Bulletin Board r When a process P i posts (sends) an article, a, it multicasts that article with timestamp V i r Process P j posts a reaction. Let’s call this message r. Assume that the value of the timestamp is V j r Note that V j > V i r Message r may arrive at P k before message a. r P k will postpone delivery of r to the display of the bulletin board until all messages that causally precede r have been received.
Example Application: Bulletin Board r Message r (from P j ) is delivered to P k iff the following conditions are met: m V j [j] = V k [j]+1 This condition is satisfied if r is the next message that P k was expecting from process P j Assume that V k [j]=5. This means that P k knows P j sent 5 messages and that it should be waiting for the 6 th message. If V j [j] = 8 then messages 6,7 are lost or not yet arrived. m V j [i] ≤ V k [i] for all i not equal to j This condition is satisfied if P k has seen at least as many messages as seen by P j when it sent message r. Assume for some i that V j [i] = 2 and V k [i] =1 and thus V j [i] > V k [i] for some i. This indicates that P i sent a message that was received by P j but not P k
Example Application: Bulletin Board P2 a P1 c d P3 e g [1,0,0] [1,0,1] Post a r: Reply a Message a arrives at P2 before the reply r from P3 does b [1,0,1] [0,0,0]
Example Application: Bulletin Board P2 a P1P3 d g [1,0,0] [1,0,1] Post a r: Reply a Buffered c [1,0,0] The message a arrives at P2 after the reply from P3; The reply is not delivered right away. b [1,0,1] [0,0,0] Deliver r
Summary r No notion of a globally shared clock. r Local (physical) clocks must be synchronized based on algorithms that take into account network latency. r Knowing the absolute time is not necessary. r Logical clocks can be used for ordering purposes.