Presentation is loading. Please wait.

Presentation is loading. Please wait.

Global States. Topics r Usefulness of global state r Difficulties in determining snapshot r Determining global state r Examples.

Similar presentations


Presentation on theme: "Global States. Topics r Usefulness of global state r Difficulties in determining snapshot r Determining global state r Examples."— Presentation transcript:

1 Global States

2 Topics r Usefulness of global state r Difficulties in determining snapshot r Determining global state r Examples

3 Readings r Van Steen and Tanenbaum: 5.3 r Coulouris: 10.5 r “ Distributed Snapshots: Determining Global States of Distributed Systems”, K. Mani Chandy and Leslie Lamport, ACM Transactions on Computer Systems, vol 3, no 1, February 1985.

4 Motivating Example r Assume that we have processes interacting in a client-server mode. r Client makes request to server m Waits for response m While waiting for response, client simply blocks; does not answer to requests from other nodes. A B C This is a deadlock

5 Motivating Example r Assume that you have a centralized server. r It queries each node m Each node responds with a list of requests that are pending (requests for which a response has not been sent). r Centralized server can then build a “waits- for” graph. m Cycle in graph implies deadlock r This is an example where being able to determine the global state is useful.

6 Other Motivating Examples r Distributed Debugging r Distributed Garbage Collection m An object is considered to be garbage if there are no longer any references to it anywhere in the distributed system. p 2 p 1 message garbage object object reference

7 Global State r Occasionally it is useful to know the global state of a distributed system. r The global state of a distributed system consists of the local state of each process, together with the messages that are currently in transit, that is, that have been sent but not delivered. r Exactly what a local state of a process is, depends on our interest. m In a distributed database system, the local state may consist of only those records that form part of the database and excludes temporary records used in computation.

8 Global State in a Single Process Application r Assume that we have the following code: x = y = z =0; x = z+1; y = x; z = y The state can be represented as the values of x,y,z. The sequence of states for the execution of the above program is the following: 000, 100, 110, 111 r Deterministic Computation m At any point in computation there is at most one event that can happen next. m There is only one sequence of states for the same input.

9 Global State for a Multiple Process Application Say in process P 1 you have a code segment as follows: 1.1 x = 5; 1.2 y = 10*x; 1.3 send(y,P 2 ); 1.4 z = 8; Say in process P 2 you have a code segment as follows: 2.1 a=8; 2.2 b=10*a; 2.3 rcv(c,P 1 ); 2.4 b = b+c;

10 Global State for a Multiple Process Application r Non-Deterministic Computation m At any point in computation there can be more than one event that can happen next r There is more than one possible sequence of states for the same input. r Assume that a state is represented as (x,y,z,a,b,c). r Observation: In this example, regardless of the sequence, eventually all sequences reach these global states ( 5,50,0,8,80,0), (5,50,0,8,80,50)

11 Global State for Multiple Process Application 0,0,0,0,0,0 5,0,0,0,0,0 5,0,0,8,0,0 5,0,0,8,80,0 0,0,0,8,0,0 5,0,0,8,0,0 5,50,0,8,0,0 5,50,0,8,80,50 5,50,8,8,80,50 5,50,8,8,80,130 5,50,0,8,80,130 5,50,8,8,80,130 5,50,0,8,80,0

12 A Non-Deterministic Computation r Each of the paths represent a possible sequence of events that could have occurred during execution. m This assumes that the same inputs were applied. m Different paths occur for different reasons that include machines that have different loads at different runs, the network load at different runs, etc; r The different paths correspond to a different sequence of global states that the distributed program goes through.

13 Viewing Global States r A process in a distributed system has only a limited view of the system, which consists of its local state and the messages it has sent or received. r Given this, is it possible for processes in the system to determine a global system state? r Instantaneous recording not possible m No global clock: Distributed recording of local states cannot be synchronized based on time. m Random network delays; What messages are in transit?

14 Viewing Global States r The main difficulty is that global state computation requires computation and communication, and by the time such effort is completed, the global state has changed. r A snapshot of the system is a single configuration of the system. It is not necessarily a global state that has actually occurred, but one that could have occurred during the computation.

15 A Naive Snapshot Algorithm r Processes record their state at any arbitrary point r A designated process collects these states r Simple, but not correct.

16 Example of Naive Snapshot Algorithm in Use P records its state PQ X = 5

17 Example of Naive Snapshot Algorithm in Use PQ m Let m be a message to update a variable Y in Q by incrementing it by the value of X.

18 Example of Naive Snapshot Algorithm in Use Q records its state after receiving m but before applying the operation. PQ m

19 Example of Naive Snapshot Algorithm in Use r Process P records its state before it actually sends m r Process Q records its state after it has received m. r This is bad. r The result is a global state that has recorded the receive event but no send event.

20 Distributed Snapshot r Represents a state in which the distributed system might have been in. r A distributed snapshot should reflect a consistent state. m If we have recorded that a process P has received a message from a process Q, then we should have also recorded that process Q had actually send that message. m Otherwise, a snapshot will contain the recording of messages that have been received but never sent. m The reverse condition (Q has sent a message that P has not received) is allowed.

21 Distributed Snapshot r The notion of a global state can be graphically represented by what is called a cut (example on the next slide). r A cut represents the last event that has been recorded for each process.

22 Consistent State a) A consistent cut b) An inconsistent cut

23 Assumptions for Algorithm r The algorithm to determine global states records process states locally and the states are collected by a designated server. r No failures in channels and processes – exactly once delivery. r Unidirectional channel and FIFO ordered message delivery. r Always a path between two processes. r Global snapshot initiation at any process at any time. r No process activity halt during snapshot.

24 Features of Algorithm r Does not promise us to give us exactly what is there i.e., an actual state r However does give us a consistent state

25 Algorithm r P starts by recording its own local state r P subsequently sends a marker along each of its outgoing channels r When Q receives a marker through channel C, its action depends on whether it had already recorded its local state: m Not yet recorded: It records its local state and sends the marker along each of its outgoing channels m Already recorded: The marker on C indicates that the channel’s state should be recorded: all messages received before this marker and since the last time Q records its own state. r Q is finished when it has received a marker along each of its incoming channels.

26 Algorithm a) Organization of a process and channels for a distributed snapshot

27 Algorithm b) Process Q receives a marker for the first time and records its local state c) Q records all incoming messages d) Q receives a marker for its incoming channel and finishes recording the state of the incoming channel

28 Algorithm r How do we know when we are done? m If a process Q receives the marker requesting a snapshot for the first time, it considers the process that sent the marker as its predecessor m When Q completes its part of the snapshot, it sends its predecessor a DONE message. m By recursion, when the initiator of the distributed snapshot has received a DONE message from all its successors, it knows that the snapshot has been completely taken.

29 Example r Assume two process p 1 and p 2 connected by two unidirectional channels, c 1 and c 2. r The two processes trade in widgets. r Process p 1 sends orders for widgets over c 2 to p 2, enclosing payment at the rate of $10 per widget. r Process p 2 sends widgets along channel c 1 to p 1. r The processes have the initial states shown in the figure on the next slide. It is assumed that p 2 has already received an order for 5 widgets, which it will shortly dispatch to p 1.

30 Example This is the initial state when the algorithm was initiated; Before initiation, the process p 2 had received an order for 5 widgets; Thus account has $50

31 Example r Upon request for global snapshot, process p 1 records its state in the actual global state, S 0, when p 1 ’s state is. p 1 p 2 (empty) (empty) c 2 c 1 1. Actual Global State S 0

32 Example r Process p 1 then emits a marker message over its outgoing channel c 2 before it sends the next application-level message: (Order 10, $100) over channel c 2. r The system enters actual global state S Actual Global state S 1 p 1 p 2 (Order 10, $100), M (empty) c 2 c 1

33 Example r Before p 2 receives the marker, it emits an application message (5 widgets) over c 1 in response to p 1 ’s previous order, yielding a new actual global state S Actual Global State S 2 p 1 p 2 (Order 10, $100), M (five widgets) c 2 c 1

34 Example r Now process p 1 receives p 2 ’s message (5 widgets) and p 2 receives the marker. p 2 records its state as and that of channel c 2 as the empty sequence. r p 2 sends a marker message over c 1. r When process p 1 receives p 2 ’s marker message, it records the state of c 1 which is the single message (5 widgets) that it received after it first recorded its state.

35 Example r The final recorded state is p 1 : ; p 2 : ;c 1 : ; c 2 :<> 4. Actual Global state S 3 p 1 p 2 (Order 10, $100) (empty) c 2 c 1

36 Example r The sequence of actual global states was the following: m S 0 : p 1 : ; p 2 : ;c 1 :<>; c 2 :<> m S 1 : p 1 : ; p 2 : ; c 1 :<>; c 2 : ; m S 2 : p 1 : ; p 2 : ; c 1 : ; c 2 : ; m S 3 : p 1 : ; p 2 : ; c 1 : ;c 2 : ;

37 Example r A possible sequence of global states is the following: m S 0 : p 1 : ; p 2 : ;c 1 :<>; c 2 :<> m S 1 ’: p 1 : ; p 2 : ;c 1 : ; c 2 :<> r Recorded State: m p 1 : ; p 2 : ;c 1 : ; c 2 :<>

38 Example S0S0 S1S1 S2S2 S3S3 S1’S1’ ………………

39 r The recorded state is not the same as one of the actual states. r The recorded state is one that was possible in one of the possible sequences of global states. r Why is this useful? What can we do with this? m To illustrate we will look at another example.

40 Example r What if p 1 initiates the snapshot algorithm after it issues a request for the 10 widgets and before it receives the 5 widgets? r This would imply that p 2 gets the order for the 10 widgets before the marker. This causes p 2 to update its account and number of widgets to $150 and 1985 respectively. p 2 will record this state when it receives the marker. p 2 sends the 10 widgets. r The state of c 1 is and c 2 is marked as empty.

41 Example 2 Say in process P 1 you have a code segment as follows: 1.1 a = 5; 1.2 recv(b, P 2 ); 1.3 c = a+ b; 1.4 send(c,P 2 ); Say in process P 2 you have a code segment as follows: 2.1 x = 5; 2.2 recv(y,P 1 ); 2.3 z = x+y; 2.4 send(z, P 1 ); State includes values of a,b,c,x,y,z and for each process records what that process is waiting (if there is anything).

42 Example 2 p 1 p 2 c 2 c 1 a=5 b=0 c=0 This is the state when the algorithm was initiated; 1.1 has been executed but 2.1 has not; marker is sent out after 1.1 has been executed but before trying to execute 1.2 Channels are empty x=0 y=0 z=0 S0S0

43 Example 2 p 1 p 2 c 2 c 1 a=5 b=0 c=0 2.1 has been executed before it receives the marker from p 1 Upon receiving the marker it records that c 2 is empty, that x=5,y=0,z=0 and that it is waiting for a message from p 1 It sends out a marker on c 1 x=5 y=0 z=0 S1S1 p 2 is waiting for message from p 1

44 Example 2 p 1 p 2 c 2 c 1 a=5 b=0 c=0 p 1 receives a marker on c 1 It records the state of its incoming channel as empty. The final state recorded is this:a=5,b=0,c=0, x=5,y=0,z=0; p 2 is waiting for a message from p 1 and channels are empty. x=5 y=0 z=0 S2S2 p 2 is waiting for message from p 1

45 Example 2 r So far the deadlock has not been detected. r Let’s say that after P 1 starts waiting for a message from P 2 that it initiates the global snapshot algorithm again. r P 1 records its state as a=5,b=0,c=0 and that it is waiting for a message from P 2 r P 1 sends the marker to P 2. r P 2 records its state as x=5,y=0,z=0, incoming channel is empty and it is waiting for a message from P 1 r P 2 sends a marker on c 1 ; When P 1 receives the marker it records the state of channel c 1 as empty

46 Example 2 r At this point the global state recorded includes the following: m a=5,b=0,c=0 m x=5,y=0,z=0 m Both channels are empty m P 1 is waiting for a message from P 2 and P 2 is waiting for a message from P 1 m This recorded state has enough information to determine that there is a deadlock. r If the algorithm is initiated again the global state still shows a deadlock.

47 Example 3 p0 p1 p2 M B C A M B A C M Send A Send B Record State Send M Recv B Recv A Recv C Recv M, Record State, Channel (2,1)empty Recv M, Record State, Channel (0,1)empty, Send M Recv M, Record State, Channel (0,1)A Send C

48 Stable Properties r The global state computed using the algorithm described can be used for detecting stable properties, e.g., m Distributed deadlock detection m Distributed garbage collection r A stable property is a property that once it holds true in a state S i then it holds true in state S j where j > i

49 Stable Properties r Let’s look at deadlock detection. Assume each process has a list waits-for which records the list of processes that the process is waiting for a message from. r The global state includes values of the waits-for list from each process. r Let’s assume two processes p 1 and p 2. Let p 1.waits-for = {p 2 } and p 2.waits-for = {p 1 }. r This represents a deadlock. If there is a deadlock in state S i then there is a deadlock in S j (where j > i).

50 Stable Properties S0S0 S1S1 S2S2 S3S3 S1’S1’ S2’S2’ If deadlock has happened in S 3 then it happens in subsequent states.

51 Summary r No shared memory in distributed systems r Very difficult to determine exactly what a system’s current state is. r Determining the global state of a distributed system can be done by synchronizing all processes so that each collects its own local state along with the messages that are currently in transit.


Download ppt "Global States. Topics r Usefulness of global state r Difficulties in determining snapshot r Determining global state r Examples."

Similar presentations


Ads by Google