lecture 5 - University of Illinois at Urbana–Champaign

Download Report

Transcript lecture 5 - University of Illinois at Urbana–Champaign

Global States
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Algorithms to Find Global States
• Why?
– (Distributed) garbage collection
– (Distributed) deadlock detection, termination [think database
transactions]
• What?
– Capture the instantaneous states of a collection of processes
– And the messages in transit on different communication
channels
• How?
– We’ll see this lecture!
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Detecting Global Properties
p2
p1
object
referenc e
mes sage
a. Garbage c oll ec tion
garbage object
p1
wait-for
b. Deadl oc k
p2
wait-for
p2
p1
acti vate
c . T ermi nation
pas sive
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
pas sive
Two Processes and Their Initial States
c2
p1
p2
c1
$1000
(none)
$50
2000
acc ount
widgets
acc ount
widgets
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Execution of the Processes
1. Global s tate S0
2. Global s tate S1
3. Global s tate S2
4. Global s tate S3
<$1000, 0>
<$900, 0>
<$900, 0>
<$900, 5>
p1
p1
p1
p1
c2
(empty)
c1
(empty)
c2
(Order 10, $100), M
c1
(empty)
c2
(Order 10, $100), M
c1
(five widgets)
c2
(Order 10, $100)
c1
(empty)
(M = marker mes sage)
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
p2
<$50, 2000>
p2
<$50, 2000>
Send 5 widgets
p2
<$50, 1995>
p2
<$50, 1995>
Obvious First Solution…
• Synchronize clocks of all processes (which
algorithm?)
• Ask all processes to record their states at known
time t
• Problems?
– Time synchronization possible only approximately (but
distributed banking applications cannot take approximations)
– Does not record the state of messages in the channels
• Again: synchronization not required – causality is
enough!
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Process Histories and States
 For a process Pi ,
history(Pi) = hi = <ei0, ei1, … >
prefix history(Pik) = hik = <ei0, ei1, …,eik >
Sik : Pi ‘s state immediately before kth event
 For a set of processes,
global history: H = i (hi)
global state: S = i (Siki)
a cut C  H = h1c1  h2c2  …  hncn
the frontier of C = {eici, i = 1,2, … n}
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Consistent States
 A cut C is consistent if
e  C (if f  e then f  C)
 A global state S is consistent if
it corresponds to a consistent cut
P1
P2
P3
e10
e12
e11
e13
e21
e22
e20
e30
Inconsistent cut
e31
2
Consistent e3
cut
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Global States
 A Run is a total ordering of events in H that is
consistent with each hi’s ordering
 A Linearization is a run consistent with happensbefore () relation in H.
 Linearizations pass through consistent global
states.
 A global state Sk is reachable from global state Si,
if there is a linearization, L, that passes through Si
and then through Sk.
 A DS evolves as a series of transitions between
global states S0 , S1 , ….
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Global State Predicates
 A global-state-predicate is a function from the set of
global states to {true, false} , e.g. deadlock,
termination
If P is a global-state predicate of reaching
termination, then
liveness(P(S0))   L linearizations from S0 ,SL :L passes through SL & P(SL)
= true
A stable global-state-predicate is one that once it
becomes true, it remains true in subsequent global
states, e.g. deadlock
 if P is a global-state-predicate of being deadlocked,
then
safety(P(S0))  S reachable from S0, P(S) = false
We need a way to record global states
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
The “Snapshot” Algorithm
 Records a set of process and channel
states such that the combination is a
consistent GS.
 Assumptions:
 No failure, all messages arrive intact, exactly once
 Communication channels are unidirectional and FIFOordered
 There is a comm. path between any two processes
 Any process may initiate the snapshot (sends Marker)
 Snapshot does not interfere with normal execution
 Each process records its state and the state of its
incoming channels (no central collection)
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
The “Snapshot” Algorithm (2)
1. Marker sending rule for initiator process P0
 After P0 has recorded its state
• for each outgoing channel C, send a marker on C
2. Marker receiving rule for a process Pk
on receipt of a marker over channel C
 if Pk has not yet recorded its state
- record Pk’s state
- record the state of C as “empty”
- turn on recording of messages over other incoming
channels
• for each outgoing channel C, send a marker on C
- else
- record the state of C as all the messages received over C
since Pk saved its state
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Chandy and Lamport’s ‘Snapshot’ Algorithm
Marker receiving rule for process pi
On pi’s receipt of a marker message over channel c:
if (pi has not yet recorded its state) it
records its process state now;
records the state of c as the empty set;
turns on recording of messages arriving over other incoming channels;
else
pi records the state of c as the set of messages it has received over c
since it saved its state.
end if
Marker sending rule for process pi
After pi has recorded its state, for each outgoing channel c:
pi sends one marker message over c
(before it sends any other message over c).
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Snapshot Example
P1
e10
e11,2
e13 e14
M
M
M
a
P2
e20
e21,2,3
b
P3
e30
e24 e25
M
M M
e31,2,3
e34
1- P1 initiates snapshot: records its state (S1); sends Markers to P2 & P3;
turns on recording for channels C21 and C31
2- P2 receives Marker over C12, records its state (S2), sets state(C12) = {}
sends Marker to P1 & P3; turns on recording for channel C32
3- P1 receives Marker over C21, sets state(C21) = {a}
4- P3 receives Marker over C13, records its state (S3), sets state(C13) = {}
sends Marker to P1 & P2; turns on recording for channel C23
5- P2 receives Marker over C32, sets state(C32) = {b}
6- P3 receives Marker over C23, sets state(C23) = {}
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Reachability Between States in Snapshot
Algorithm
actual exec ution e0 ,e 1,...
Sin it
recording
begins
pre-snap: e '0 ,e'1 ,...e'R -1
recording
ends
Ssn ap
Sfin al
pos t-s nap: e' R,e 'R +1 ,...
Let ei and ej be events occurring at pi and pj, respectively such that ei  ej
the snapshot algorithm ensures that
• if ej is in the cut then ei is also in the cut.
• if ej occurred before pj recorded its state, then ei must have occurred before
pi recorded its state.
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Causality Violation
Physical Time
P1
0
P2
0
P3
1
0
Include(obj1
)
2
1
5
2
6
4
3
4
obj1.method()
P2 has obj1
• Causality violation occurs when order of messages causes an
action based on information that another host has not yet received.
• In designing a DS, potential for causality violation is important
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)
Detecting Causality Violation
Physical Time
P1
0,0,0
P2
0,0,0
P3
1,0,0
Violation:
(1,0,0) < (2,1,2)
2,0,0
(1,0,0)
(2,0,0)
0,0,0
2,1,2
2,2,2
(2,0,2)
2,0,1
2,0,2
• Potential causality violation can be detected by vector timestamps.
• If the vector timestamp of a message is less than the local vector
timestamp, on arrival, there is a potential causality violation.
 2002, M. T. Harandi and J. Hou (modified: I. Gupta, N. Vaidya)