190 likes | 340 Views
Advance OS (CS G623). LECTURE 3. Theoretical Aspects. Limitations of Distributed Systems Logical Clocks Causal Ordering Global State Recording Termination Detection. 2. Limitations. Absence of Global clock Absence of Shared Memory. S1:A. S1:A. S1:A. S2:A. S2:A. S2:A.
E N D
Advance OS (CS G623) LECTURE 3
Theoretical Aspects Limitations of Distributed Systems Logical Clocks Causal Ordering Global State Recording Termination Detection 2
Limitations • Absence of Global clock • Absence of Shared Memory
S1:A S1:A S1:A S2:A S2:A S2:A Communication Channel Communication Channel Communication Channel $200 $200 $250 $450 $500 $500 (a) (b) (c) Example
Happened before relation: a -> b : Event a occurred before event b. Events in the same process. a -> b : If a is the event of sending a message m in a process and b is the event of receipt of the same message m by another process. a -> b, b -> c, then a -> c. “->” is transitive. Causally Ordered Events a -> b : Event a “causally” affects event b Concurrent Events a || b: if a !-> b and b !-> a Lamport’s Logical Clock 5
Space-time Diagram e12 e14 Space e11 e13 P1 Internal Events Messages P2 e21 e22 e23 e24 Time 6
Logical Clocks Conditions satisfied: Ci is clock in Process Pi. If a -> b in process Pi, Ci(a) < Ci(b) Let a: sending message m in Pi; b : receiving message m in Pj; then, Ci(a) < Cj(b). Implementation Rules: R1: Ci = Ci + d (d > 0); clock is updated between two successive events. R2: Cj = max(Cj, tm+ d); (d > 0); When Pj receives a message m with a time stamp tm (tm assigned by Pi, the sender; tm = Ci(a), a being the event of sending message m). A reasonable value for d is 1 7
Space-time Diagram e13 e16 e12 e14 e15 e17 Space e11 P1 (6) (7) (1) (3) (5) (2) (4) (1) (3) (4) (7) (2) P2 / e21 e22 e23 e25 e24 Time 8
Limitation of Lamport’s Clock e12 Space e11 e13 P1 (2) (1) (3) (1) (3) (4) P2 e21 e22 e23 e31 e32 e33 P3 (1) (2) Time C(e11) < C(e32) but not causally related. This inter-dependency not reflected in Lamport’s Clock. 9
Vector Clocks Keep track of transitive dependencies among processes for recovery purposes. Ci[1..n]: is a “vector” clock at process Pi whose entries are the “assumed”/”best guess” clock values of different processes. Ci[j] (j != i) is the best guess of Pi for Pj’s clock. Vector clock rules: Ci[i] = Ci[i] + d, (d > 0); for successive events in Pi For all k, Cj[k] = max (Cj[k],tm[k]), when a message m with time stamp tm is received by Pj from Pi. : For all 10
Vector Clocks Comparison • ta = tb iff for all i, ta[i] = tb[i]; • ta != tb iff there exists an i, ta[i] != tb[i]; • ta <= tb iff for all i, ta[i] <= tb[i]; • ta !(<=) tb iff there exists an i, ta[i] > tb[i]; • ta < tb iff [ta <= tb and ta != tb] • ta !< tb iff ! [ta <= tb and ta != tb] • ta || tb iff [ta !< tb and tb < ta] 11
Vector Clock … e12 e13 Space e11 P1 (2,0,0) (1,0,0) (3,4,1) (0,1,0) (2,3,1) (2,4,1) (2,2,0) P2 e21 e22 e23 e24 e31 e32 P3 (0,0,2) (0,0,1) Time 12
Causal Ordering of Messages Send(M1) Space P1 Send(M2) P2 (1) P3 (2) Time 13
Message Ordering … Not really worry about maintaining clocks. Order the messages sent and received among all processes in a distributed system. (e.g.,) Send(M1) -> Send(M2), M1 should be received ahead of M2 by all processes. This is not guaranteed by the communication network since M1 may be from P1 to P2 and M2 may be from P3 to P4. Message ordering: Deliver a message only if the preceding one has already been delivered. Otherwise, buffer it up. 14
BSS Algorithm BSS: Birman-Schiper-Stephenson Protocol Broadcast based: a message sent is received by all other processes. Deliver a message to a process only if the message preceding it immediately, has been delivered to the process. Otherwise, buffer the message. Accomplished by using a vector accompanying the message. 15
BSS Algorithm ... • Process Pi increments the vector time VTpi[i], time stamps, • and broadcasts the message m. VTpi[i] - 1 denotes the number • of messages preceding m. • 2. Pj != Pi receives m. m is delivered when: • a. VTpj[i] == VTm[i] – 1 [Pj has received all messages from Pi before m] • b. VTpj[k] >= VTm[k] for all k in {1,2,..n} - {i}, n is the • total number of processes. Delayed message are queued • in a sorted manner. [Pj has received all those messages received by Pi before m] • c. Concurrent messages are ordered by time of receipt. • When m is delivered at Pj, VTpj updated according Rule 2 of • vector clocks. • 2(a) : Pj has received all Pi’s messages preceding m. • 2(b): Pj has received all other messages received by Pi • before sending m. 16
BSS Algorithm … (0,0,0) (buffer) (0,0,1) (0,1,1) P1 deliver from buffer (0,0,1) (0,1,1) P2 P3 (0,0,1) (0,1,1) 17