Presentation is loading. Please wait.

Presentation is loading. Please wait.

Issues with Clocks. Problem Lack of global time –Need to compare different events in a distributed system.

Similar presentations


Presentation on theme: "Issues with Clocks. Problem Lack of global time –Need to compare different events in a distributed system."— Presentation transcript:

1 Issues with Clocks

2 Problem Lack of global time –Need to compare different events in a distributed system

3 Problem (Continued) Consider the problem of detecting insider trading in a stock exchange –Assume that no communication occurs outside the computer systems –Each entity is represented by a computer and they communicate among themselves –Whenever a process sends a message, it includes ALL the information it has learnt so far Lets not worry about the cost of implementing this –Each entity is required to follow the protocol you choose

4 Problem (Continued) Consider two events –An inside event, say e, that affects the company A –An event f, where an officer, X, of company A sells stock Question –Is it possible that X is guilty of insider trading?

5 Situation 1 Assume global time –Event e occurred at 8am –Event f occurred at 10am (same day) –Answer: –Event e occurred at 10am –Event f occurred at 8am (same day) –Answer:

6 Approach What we need is a way to define causality –Can event e affect event f? –This is defined as the happened before relation –Please do not confuse it with the English meaning of this

7 happened before Let a, b, c be events –An event can be a local event, send event or a receive event Definition : a  b (read as a happened before b) iff either one of the following condition is true –a and b are events on the same process and a occurred before b –a is a send event and b is the corresponding receive event –there exists event c such that a  c and c  b

8 Revisiting the Previous Problem Consider two events –An inside event, say e, that affects the company A –An event f, where an officer, X, of company A sells stock If e  f then X is guilty of insider trading

9 Logical Clocks Goal of logical clock is –Assign each event a timestamp –If e  f then the timestamp of e should be less than that of f. –To solve this, each process maintains a logical clock cl cl.j : clock value of process j cl.m : clock value of message m cl.a : clock value of event a

10 Program for Logical Timestamps Let a be a new event –If a is a local event at j cl.j := cl.j + 1 cl.a := cl.j –If a is a send event at j cl.j := cl.j + 1 cl.m := cl.j cl.a := cl.j –If a is a receive of message m at j cl.j := max(cl.j, cl.m) + 1 cl.a := cl.j

11 Properties of Logical Clocks If a  b then cl.a < cl.b

12 Proving Properties of Logical Clocks Theorem: At any time, the following statement is true for all events (that have occurred in the system so far) –  x, y :: x  y  cl.x < cl.y, –where x and y range over all the events, processes (latest event on the process) and messages (corresponding send event) Proof by induction Base case –No events created. Hence, trivially true –Show that whenever a new event is created

13 Invariant The predicate –a  b  cl.a < cl.b –Is called an invariant of the logical timestamp program. An invariant of a program is a predicate such that –If any step of the program is executed in a state where the invariant is true then the resulting state is also one where the invariant predicate is true –If the program execution starts in a state where the invariant is true then its execution is correct.

14 Logical Timestamps The time associated with an event is a pair, the clock and the process where the event occurred. For event a at process j, the timestamp ts.a is –ts.a = Lexicographical comparison iff x1 < y1  ( (x1 = y1)  (x2 < y2) )

15 Observation about Logical Clocks For any two distinct events a and b, either ts.a < ts.b  ts.b < ts.a The event timestamps form a total order.

16 So What? Consider two events –An inside event, say e, that affects the company A –An event f, where an officer, X, of company A sells stock Question –Is it possible that X is guilty of insider trading? Case 1 –cl.e = 8, cl.f = 10 –Answer: Case 2 –cl.e = 10, cl.f = 8 –Answer:

17 Problem Logical timestamps provide a partial information about causality. Extending logical timestamps for complete knowledge of causality


Download ppt "Issues with Clocks. Problem Lack of global time –Need to compare different events in a distributed system."

Similar presentations


Ads by Google