Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps.

Similar presentations


Presentation on theme: "Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps."— Presentation transcript:

1 Logical Clocks (2)

2 Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps

3 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. 558-565. 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. 56-66, February 1988.

4 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

5 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

6 Example Application:Bulletin Board r The Internet’s electronic bulletin board service (network news) 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 be doing this?

7 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 r Ordering: Bulletin board: os.interesting Item FromSubject 23A.HanlonMach 24G.JosephMicrokernels 25A.HanlonRe: Microkernels 26T.L’HeureuxRPC performance 27M.WalkerRe: Mach end Figure 11.13 Colouris total (makes the numbers the same at all sites) FIFO (gives sender order) causal (makes replies come after original message)

8 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 Totally-ordered multicasting is too strong in this case. 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.

9 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.

10 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.

11 Fidge’s Algorithm 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

12 Fidge’s Algorithm r The Fidge’s logical 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 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] ); v p [p] = v p [p] + 1;

13 Fidge’s Algorithm 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.

14 Example P2 a b P1 c d e f g h i P3 j k l [1,0,0] [2,0,0] [3,0,0] [4,0,0] [0,1,0] [2,2,0] [2,3,2] [2,4,2] [4,5,2] [0,0,1] [0,0,2] [0,0,3]

15 Causality and Modified Vector Timestamps r What I just presented is the original Fidge’s vector timestamp. r With a slight adjustment, vector timestamps can be used to guarantee causal message delivery. r We will illustrate this adjustment, the definition of causality and the motivation through an example.

16 Example Application: Bulletin Board r Vector timestamps can be used to guarantee causal message delivery. 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.

17 Example Application: Bulletin Board r Vector timestamps are assumed to be updated only when posting or receiving articles i.e., when a message is sent or received. r Let V q be piggybacked on the message sent by process P q to process P p ; When process P p receives the message, then P p does the following: For i = 1 to n do V p [i] = max(V p [i], V q [i] ); Thus if process q knows that process i sent 5 messages (V q [i] =5 and V p [i] = 3) then process p didn’t know about the latest two messages sent by process i.

18 Example Application: Bulletin Board r When p sends a message, it does the following: V p [p] = V p [p] + 1; r This is basically saying that the number of messages process p has sent is incremented by one.

19 Example Application: Bulletin Board r When a process P i posts (sends) an article, 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 as well.

20 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. 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

21 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]

22 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

23 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.


Download ppt "Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps."

Similar presentations


Ads by Google