Fall 2000: CS 771/871 Operating Systems

[ Home | Class Roster | Syllabus | Status | Glossary | Search | Course Notes]


 

Lecture 5 - Global Clock/State

Lack of Global Clock: 

(see also here)

Solutions:

QUESTION: why need to common notion of time? figure 5.1

Need to know causality

coherent view: all observations of different processes are made at same phyical time

complete view: local state of all processes plus messages in transit = global state

Question: what is state? what is observable?


Lamports' Logical Clocks

event: any action which changes the state of a process or transfers that state (in a message) to another process.
Could be a single instruction or a set of function calls.

Message sending events have a special significance in a distributed system - they provide the observation points of a computation.

Computation:  set of interacting processes used to produce a desired result

Happened before relationship

a -> b, if "a" and "b" are in the same process and "a" occurred before "b"

a -> b, if "a" is the event of sending a message and "b" is the event of receiving that message

IF a->b and b->c, then a->c (happened before is transitive)

casually related events:  event "a" casually affects "b" if a-> b

concurrent events: denoted a || b if !(a->b) AND !(b->a)

Show space-time diagram

QUESTION: what are the event relationships below?

 

Let "C" be a monotonically increasing function that assigns a timestamp to an event

for any events "a" and "b"

        if a -> b then C(a) < C(b)

[IR1] Clock Ci is incremented between any two successive events.

[IR2] If "a" is the event of sending a message in process "Pi", then that message is assigned the timestamp Ci(a).
Upon receiving a message with timestamp (Tm), process Pj will set it's clock to max(Cj,Tm+d) (d > 0)

"happened before" defines a irreflexive partial order among events which can be totally ordered by breaking ties using process ID or some such tie breaking mechanism.

Limitations of logical clocks: Vector Clocks

if a ->b then C(a) < C(b), but the reverse is not necessarily true. (figure 5.4)

That is does not distinguish local events from message passing ones.

Question:  is it sufficient to only timestamp message events?

However the scheme proposed in ISIS can resolve this.
Assign a vector of length n = number of communicating process for each process, where the i-th location contains that processes current understanding of the value of Pi's logical clock.

Assertion: for-all i,j: Ci[i] >= Cj[i].

QUESTION: What other assertions can be made?

fg 5.5


At-Most-Once Message Delivery

But what if receiver crashes and loses message number tables?
When message tables be purged?

 

Message Ordering

NOTE: message arriving out of order mean that the receive events have a different -> relationship than the corresponding send events.

Use vector clocks as a message counter.

Algorithm 1: Go over Birman-etal algorihtm p. 107 - uses broadcast messages

Consider Figure 5-6

Timestamp for Send(M1) event is (1,0,0)

Timestamp for second send from P1 is (2,0,0)

Timestamp for first send of P3 is (0,0,1)

Timestamp for Send(M2) is (2,1,1)

When message M2 is received by P3 (with timestamp (2,1,1), since P3 knows that P1 has sent 2 messages but since only one has been received, it delays the delivery of M2.

Question: How does P3 "know" that M1 is for it? and therefore needs to delay?

Algorithm 2: Schipper -etal does not use broadcast

Consider figure 5-6 again.


Global State

Coherent is impossible - what about "consistent"
Consider Figure 5.7: need to record state of communications channel

Question: what is meant by a consistent global state?

Question: What is the invariant here?

consistent state requires that all information exchanged between be accounted for.
if n is the number of messages sent by process A when its local state was recorded and n' is the number of messages sent by A as recorded in the channel in its local state, then the global state may be inconsistent if n < n' or if n > n'.
Hence a consistent global state requires n = n'.

Similarly for the receiver (using m and m') for the number of messages received. that is m = m' for a consistent state.

Since n' >= m, we get that in a consistent global state n >= m.

Question: what is the local state of a process?

send(Mij) in LSi iff time(send(Mij)) < time(LSi)
rec(Mij) in LSj iff time(rec(Mij)) < time(LSj)

Transit; transit(LSi,LSj) = { Mij | send(Mij) in LSi AND rec(Mij) NOT in LSj}
Inconsistent: inconsisten(LSi,LSj) = {Mij | send(Mij) NOT in LSi AND rec(Mij) in LSj}

A global state is a collection of local states of all processes

consistent global state: a global state = {LS1, LS2,...,LSn} is consistent iff

FORALLi,j: 1 <=i,j <=n :: inconsistent(LSi,LSj)  is empty

Transitless global state: iff 

FORALLi,j: 1 <=i,j <=n :: transit(LSi,LSj)  is empty

strongly consistent global state iff consistent and transitless

How cuts in figure 5.8


Go over 5.6.1 with an example

Questions: 


Theorem: Fig 5.9 illustrates that there is a permutation of the sequence of actions which actually occurred which goes through a recorded state (which may not have ever existed in real time) 


Cuts of a Distributed System

consistent cut: let Ek be an event at site(process) Sk, A cut C = {C1,C2,...,Cn} is consistent iff

FORALL Si, Sj, there does not exist a Ei,Ej such that (Ei -> Ej) AND (Ej ->Cj) AND (NOT Ei -> Ci)

Theorem 5.1:  A cut is consistent iff no two cut events are causally related.

Theorem 5,2:a cut is consistent iff no cut has a vector time stamp that is componentwise less than  any other cut's vector time stamp


Huang's Termination Detection Algorithm

Problem: how to know when all processes have finished a computation (need consistent global view of this computation, be it an election, deadlock detection or resolution, token generation, etc).

A process is either IDLE or ACTIVE in the computation. A computation message is sent to initiate a computation.
DEFINITION: a computation is terminated iff all processes are idle and there are no messages in transit.

There is a controlling agent which initially has weight = 1.
Weight is used to coordinate work sent and results received.
Let B(DW) be a computation request message sent with weight DW
and C(DW) be an acknowledgement message with weight DW.

 


Huang's Termination Detection Algorithm 2

 


Correctness of Huang's Termination Detection Algorithm

Let
A : set of weights of all active processes
B : set of weights of all computation messages in transit
C : set of weights of all control messages in transit
Wc: weight of controlling agent

Then the following invariants hold:

I1: Wc + SUM{over union of A,B and C} = 1 (conservation of weight)

I2: for-all W in union of A,B and C) W > 0 (weights are never negative)

------

By I1, Wc = 1 implies SUM{over union of A,B and C} = 0

By P2, SUM{over union of A,B and C} = 0 implies UNION A,B and C is empty

A UNION B = empty implies termination.

if assume message sending is finite and reliable, then eventually C will become empty and Wc = 1 so noting the termination

QUESTION: In what way related to two phase commit
and
Distributed Mutual Exclusion Algorithm (Ricart and Agrawala)


Termination Detection: Example

EXAMPLE: three processes (P1, P2, P3) and one controlling process (CP). Let P1 be the "start" process.
Let CM = computation message

Huang's Termination detection algorithm: (go over proof and example)

 

 

Assignment 4: Pick any two of the problems 5.1 to 5.7 to solve

 

Guidelines for Assignments: Assignments must be posted on your web sites. Obviously you should not copy another student's assignment and treat it as your own. Assignments are an extension of the class dialog. Basically you get credit for doing an assignment and no credit for not doing it. Really exception answers get extra credit.
Most assignments require only short answers - but they should be well thought out answers showing insight into the problem.

 


Copyright chris wild 1996.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: August 29, 1996.