UBI529 Distributed Algorithms

Slides:



Advertisements
Similar presentations
Global States.
Advertisements

Distributed Snapshots: Determining Global States of Distributed Systems Joshua Eberhardt Research Paper: Kanianthra Mani Chandy and Leslie Lamport.
Lecture 8: Asynchronous Network Algorithms
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
Uncoordinated Checkpointing The Global State Recording Algorithm.
Uncoordinated Checkpointing The Global State Recording Algorithm Cristian Solano.
6.852: Distributed Algorithms Spring, 2008 Class 12.
Time and Global States Part 3 ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Termination Detection of Diffusing Computations Chapter 19 Distributed Algorithms by Nancy Lynch Presented by Jamie Payton Oct. 3, 2003.
CS542 Topics in Distributed Systems Diganta Goswami.
Distributed Computing 5. Snapshot Shmuel Zaks ©
Global State Collection. Global state collection Some applications - computing network topology - termination detection - deadlock detection Chandy-Lamport.
Distributed Snapshot (continued)
CS514: Intermediate Course in Operating Systems Professor Ken Birman Vivek Vishnumurthy: TA.
CS 582 / CMPE 481 Distributed Systems
Causality & Global States. P1 P2 P Physical Time 4 6 Include(obj1 ) obj1.method() P2 has obj1 Causality violation occurs when order.
Ordering and Consistent Cuts Presented By Biswanath Panda.
Distributed Systems Fall 2009 Logical time, global states, and debugging.
Chapter 11 Detecting Termination and Deadlocks. Motivation – Diffusing computation Started by a special process, the environment environment sends messages.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
Ordering and Consistent Cuts Presented by Chi H. Ho.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
Cloud Computing Concepts
CIS 720 Distributed algorithms. “Paint on the forehead” problem Each of you can see other’s forehead but not your own. I announce “some of you have paint.
1 Distributed Systems CS 425 / CSE 424 / ECE 428 Global Snapshots Reading: Sections 11.5 (4 th ed), 14.5 (5 th ed)  2010, I. Gupta, K. Nahrtstedt, S.
Distributed Computing 5. Snapshot Shmuel Zaks ©
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
Chapter 9 Global Snapshot. Global state  A set of local states that are concurrent with each other Concurrent states: no two states have a happened before.
Lecture 6-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) September 12, 2013 Lecture 6 Global Snapshots Reading:
Distributed Snapshot. Think about these -- How many messages are in transit on the internet? --What is the global state of a distributed system of N processes?
Distributed Systems Fall 2010 Logical time, global states, and debugging.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Snapshot. One-dollar bank Let a $1 coin circulate in a network of a million banks. How can someone count the total $ in circulation? If not.
Hwajung Lee. -- How many messages are in transit on the internet? --What is the global state of a distributed system of N processes? How do we compute.
Networks and Distributed Snapshot Sukumar Ghosh Department of Computer Science University of Iowa.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 5 Instructor: Haifeng YU.
Global State Collection
Fault tolerance and related issues in distributed computing Shmuel Zaks GSSI - Feb
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Lecture 4-1 Computer Science 425 Distributed Systems (Fall2009) Lecture 4 Chandy-Lamport Snapshot Algorithm and Multicast Communication Reading: Section.
Hwajung Lee. Some applications - computing network topology - termination detection - deadlock detection Chandy Lamport algorithm does a partial job.
1 Chapter 11 Global Properties (Distributed Termination)
Hwajung Lee. -- How many messages are in transit on the internet? --What is the global state of a distributed system of N processes? How do we compute.
Token-passing Algorithms Suzuki-Kasami algorithm The Main idea Completely connected network of processes There is one token in the network. The holder.
Distributed Systems Lecture 6 Global states and snapshots 1.
ICS Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State.
Termination detection
Consistent cut A cut is a set of events.
Global State Recording
CSE 486/586 Distributed Systems Global States
Theoretical Foundations
Lecture 9: Asynchronous Network Algorithms
ITEC452 Distributed Computing Lecture 9 Global State Collection
Distributed Snapshot.
Global State Recording
Distributed Snapshot.
湖南大学-信息科学与工程学院-计算机与科学系
Global state collection
Global State Collection
Distributed Snapshot Distributed Systems.
ITEC452 Distributed Computing Lecture 8 Distributed Snapshot
Distributed deadlock Assume each process owns a few resources, and review how resources are allocated. Why deadlocks occur? - Exclusive (i.e not shared)
Distributed Snapshot.
CSE 486/586 Distributed Systems Global States
Distributed algorithms
CIS825 Lecture 5 1.
Consistent cut If this is not true, then the cut is inconsistent
Distributed Snapshot.
Distributed Snapshots
Presentation transcript:

UBI529 Distributed Algorithms Global State of Distributed Systems

Motivation Goal: Take a snapshot of the global computation A snapshot of local states on n processes taken at exactly the same time Two terms “global state” and “global snapshot” Useful for debugging Useful for backup/check-pointing Useful for calculating global predicate E.g., Exactly how much currency do we have in the country (notice that money flows among people constantly)? Deadlock Detection Rollback Recovery Termination Detection

Global state Global state A set of local states that are concurrent with each other Concurrent states: no two states have a happened before relation with each other

The mystery of the missing dollars Send $100 B A $300 $400 Picture taken at A - $400 A sends $100 to B Picture taken at B - $400 Total is $800

Global Snapshot Problem Determine the global system state (e.g. the total money ) Each process records its own state No shared clock/memory Group of photographers taking snaps of different portions and trying to combine to get the overall picture.

Consistent cut Given computation (E,!) and F µ E is a cut iff F is a consistent cut (global snapshot) iff

Consistent and inconsistent cuts

A cut is a set of events. a b c g d P1 m e f P2 P3 k i h j Cut 1 Cut 2 Consistent cut A cut is a set of events. (a  consistent cut C)  (b happened before a)  b  C a b c g d P1 m e f P2 P3 k i h j Cut 1 Cut 2 (Consistent) (Not consistent)

Consistent snapshot The set of states immediately following a consistent cut forms a consistent snapshot of a distributed system. A snapshot that is of practical interest is the most recent one. Let C1 and C2 be two consistent cuts and C1  C2. Then C2 is more recent than C1. Analyze why certain cuts in the one-dollar bank are inconsistent.

Consistent snapshot 1. The recording must be non-invasive How to record a consistent snapshot? Note that 1. The recording must be non-invasive 2. Recording must be done on-the-fly. You cannot stop the system.

Chandy Lamport Algorithm Assumes FIFO and Unidirectional channels A bidirectional channel is modelled as two unidirectional channels Each process has an associated color. All processes are initially white. A process records it local state just before turning red On turning red the process sends out a marker on all outgoing channels On receiving a marker a white process turns red

Chandy-Lamport Algorithm Works on a (1) strongly connected graph (2) each channel is FIFO. An initiator initiates the algorithm by sending out a marker ( )

White and red processes Initially every process is white. When a process receives a marker, it turns red if it has not already done so. Every action by a process, and every message sent by a process gets the color of that process.

Two steps Step 1. In one atomic action, the initiator (a) Turns red (b) Records its own state (c) sends a marker along all outgoing channels Step 2. Every other process, upon receiving a marker for the first time (and before doing anything else) (a) Turns red (b) Records its own state (c) sends markers along all outgoing channels The algorithm terminates when (1) every process turns red, and (2) Every process has received a marker through each incoming channel.

Why does it work? Lemma 1. No red message is received in a white action.

SSS Why does it work? All white All red Easy conceptualization of the snapshot state Theorem. The global state recorded by Chandy-Lamport algorithm is equivalent to the ideal snapshot state SSS. Hint. A pair of actions (a, b) can be scheduled in any order, if there is no causal order between them, so (a; b) is equivalent to (b; a)

Let an observer observe the following actions: Why does it work? Let an observer observe the following actions: w[i] w[k] r[k] w[j] r[i] w[l] r[j] r[l] …  w[i] w[k] w[j] r[k] r[i] w[l] r[j] r[l] … [Lemma 1] w[i] w[k] w[j] r[k] w[l] r[i] r[j] r[l] … [Lemma 1] w[i] w[k] w[j] w[l] r[k] r[i] r[j] r[l] … [done!] Recorded state

Example 1. Count the tokens Let us verify that Chandy-Lamport snapshot algorithm correctly counts the tokens circulating in the system D C A B How to account for the channel states? Use sent and received variables for each process.

Chandy Lamport Algorithm

Algorithm public class RecvCamera extends Process implements Camera { . . . public RecvCamera(Linker initComm, CamUser app) { for (int i = 0; i < N; i++) if (isNeighbor(i)) { closed[i] = false; chan[i] = new LinkedList(); } else closed[i] = true; } public synchronized void globalState() { myColor = red; app.localState(); // record local State; sendToNeighbors("marker", myId); // send Markers public synchronized void handleMsg(Msg m, int src, String tag) { if (tag.equals("marker")) { if (myColor == white) globalState(); closed[src] = true; if (isDone()){ ----- Display channel state (transit messages) chan[] ---- } else { // application message if ((myColor == red) && (!closed[src])) chan[src].add(m); app.handleMsg(m, src, tag); // give it to app boolean isDone() { if (myColor == white) return false; if (!closed[i]) return false; return true; } } Algorithm

Lai Yang Algorithm LY1. The initiator records its own state. When it needs to send a message m to another process, it sends a message (m, red). LY2. When a process receives a message (m, red), it records its state if it has not already done so, and then accepts the message m.

Another example of distributed snapshot: Communicating State Machines

Something unusual down  up M’ Let machine i start Chandy-lamport snapshot before it has sent M along ch1. Also, let machine j receive the marker after it sends out M’ along ch2. Observe that the snapshot state is down  up M’ Doesn’t this appear strange? This state was never reached during the computation!

Understanding snapshot

Understanding snapshot The observed state is a feasible state that is reachable from the initial configuration. It may not actually be visited during a specific execution. The final state of the original computation is always reachable from the observed state.

Discussions What good is a snapshot if that state has never been visited by the system? - It is relevant for the detection of stable predicates. - Useful for checkpointing.

Discussions What if the channels are not FIFO? Study how Lai-Yang algorithm works. It does not use any marker LY1. The initiator records its own state. When it needs to send a message m to another process, it sends a message (m, red). LY2. When a process receives a message (m, red), it records its state if it has not already done so, and then accepts the message m. Question 1. Why will it work? Question 1 Are there any limitations of this approach?

Global state collection Some applications - computing network topology - termination detection - deadlock detection Chandy Lamport algorithm does a partial job. Each process collects a fragment of the global state, but these pieces have to be stitched together to form a global state.

s(i) s(j) i j s(k) s(l) k l A simple exercise At the end, each process Once the pieces of a consistent global state become available, consider collecting the global state via all-to-all broadcast At the end, each process will compute a set V, where V= {s(i): 0 ≤ i ≤ N-1 } s(i) s(j) i j s(k) s(l) k l

Assume that the topology is strongly connected graph All-to-all broadcast Assume that the topology is strongly connected graph Program broadcast (for process i} define V.i, W.i : set of values; initially V.i={s(i)}, W.i =  andevery channel is empty do V.i ≠ W.i send (V.i \ W.i) to every outgoing channel; W.i := V.i  ¬ empty (k, i) receive X from channel(k, i); V.i := V.i  X od V.i W.i (i,k) V.k W.k Acts like a “pump”

V.i W.i (i,k) V.k W.k Proof Lemma. empty (i. k)  W.i V.k. (Upon termination) i: V.i = W.i, and all channels are empty. So, V.i  V.k. On a cyclic path, V.i = V.k must be true. Since s(i) V.i, s(i) V.k V.i W.i (i,k) V.k W.k

Acknowledgements This part is heavily dependent on Dr. Sukumar Ghosh Iowa University Distributed Systems course 22C:166

Termination Detection and Deadlocks

Termination detection During the progress of a distributed computation, processes may periodically turn active or passive. A distributed computation termination when: (a) every process is passive, (b) all channels are empty, and (c) the global state satisfies the desired postcondition

Visualizing diffusing computation initiator active passive Notice how one process engages another process. Eventually all processes turn white, and no message is in transit -this signals termination. How to develop a signaling mechanism to detect termination?

Dijkstra-Scholten algorithm The basic scheme Node j engages node k. An initiator initiates termination detection by sending signals (messages) down the edges via which it engages other nodes. At a “suitable time,” the recipient sends an ack back. When the initiator receives ack from every node that it engaged, it detects termination. j k signal j k j k ack

Dijkstra-Scholten algorithm Deficit (e) = # of signals on edge e - # of ack on edge e For any node, C = total deficit along incoming edges and D = total deficit along outgoing edges For the initiator, by definition, C = 0 Dijkstra-Scholten algorithm used the following two Invariants to develop their algorithm: Invariant 1. (C ≥ 0)  (D ≥ 0) Invariant 2. (C > 0)  (D = 0) 1 2 3 4 5

Dijkstra-Scholten algorithm The invariants must hold when an interim node sends an ack. So, acks will be sent when (C-1 ≥ 0)  (C-1 > 0 D=0) {follows from INV1 and INV2} = (C > 1)  (C ≥1  D=0) = (C > 1) (C =1  D=0) 1 2 3 4 5

Dijkstra-Scholten algorithm program detect {for an internal node i} initially C=0, D=0, parent = i do - m = signal  (C=0)  C:=1; state:= active; parent := sender {this node can send out messages to engage other nodes, or turn passive} - m = ack  D:= D-1 - (C=1 D=0)  state = passive  send ack to parent; C:= 0; parent := i - m = signal  (C=1)  send ack to the sender; od 1 2 3 4 5 Note that the engaged nodes induce a spanning tree

Distributed deadlock Why deadlocks occur? Assume each process owns a few resources, and review how resources are allocated. Why deadlocks occur? - Exclusive (i.e not shared) resources - Non-preemptive scheduling - Circular waiting by all or a subset of processes

Distributed deadlock Three aspects of deadlock deadlock detection deadlock prevention deadlock recovery

Distributed deadlock May occur due to bad designs/bad strategy [Sometimes prevention is more expensive than detection and recovery. So designs may not care about deadlocks, particularly if it is rare.] Caused by failures or perturbations in the system

Wait-for Graph (WFG) Represents who waits for whom. No single process can see the WFG. Review how the WFG is formed.

Another classification Resource deadlock [R1 AND R2 AND R3 …] also known as AND deadlock Communication deadlock [R1 OR R2 OR R3 …] also known as OR deadlock

Detection of resource deadlock Notations w(j) = true  (j is waiting) depend [j,i] = true  j  succn(i) (n>0) P(i,s,k) is a probe (i=initiator, s= sender, r=receiver) 2 1 3 4 P(4,4,3) initiator

Detection of resource deadlock {Program for process k} do P(i,s,k) received  w[k]  (k ≠ i) ¬ depend[k, i]  send P(i,k,j) to each successor j; depend[k, i]:= true P(i,s, k) received w[k]  (k = i)  process k is deadlocked od

Should the links be FIFO? Observations To detect deadlock, the initiator must be in a cycle Message complexity = O(|E|) (edge-chasing algorithm) E=set of edges Should the links be FIFO?

Communication deadlock This has a resource deadlock but no communication deadlock

Detection of communication deadlock A process ignores a probe, if it is not waiting for any process. Otherwise, first probe  mark the sender as parent; forwards the probe to successors Not the first probe  Send ack to that sender ack received from every successor  send ack to the parent Communication deadlock is detected if the initiator receives ack. Has many similarities with Dijkstra-Scholten’s termination detection algorithm

Distributed deadlock Major issues detection prevention recovery May occur due to faulty design or resource sharing problems [Sometimes prevention is more expensive than detection and recovery. So certain designs deliberately do not care about deadlocks, particularly if it is rare.] Sometimes failures failures or perturbations can modigy the system state and cause deadlock. Major issues detection prevention recovery

Wait-for Graph (WFG) Represents who waits for whom. No single process can see the WFG. Review how the WFG is formed.

Another classification Resource deadlock [R1 AND R2 AND R3 …] also known as AND deadlock Communication deadlock [R1 OR R2 OR R3 …] also known as OR deadlock

Detection of resource deadlock Notations w(j) = true  (j is waiting) depend [j,i] = true j  succn(i) (n>0) P(i,s,k) is a probe (i=initiator, s= sender, r=receiver) 2 1 3 4 P(4,4,3) initiator

Detection of resource deadlock Chandy-Misra-Haas algorithm {Program for process k} do P(i,s,k) received  w[k]  (k ≠ i) ¬ depend[k, i]  send P(i,k,j) to each successor j; depend[k, i]:= true P(i,s,k) received w[k]  (k = i)  process k is deadlocked od

Observations E=set of edges To detect deadlock, the initiator must be in a cycle Message complexity = O(|E|) (edge-chasing algorithm) E=set of edges

Communication deadlock 5 The subgraph of the WFG consisting of black nodes and black edges has a resource deadlock as well as a communication deadlock. However, if we add node 5 and the red edge (4,5) then the communication deadlock will disappear.

Detection of communication deadlock A process ignores a probe, if it is not waiting for any process. Otherwise, first probe  mark the sender as parent; forwards the probe to successors Not the first probe  Send ack to that sender ack received from every successor  send ack to the parent Communication deadlock is detected if the initiator receives ack. Has many similarities with Dijkstra-Scholten’s termination detection algorithm

Acknowledgements This part of the slides is almost entirely dependent on Dr. Sukumar Ghosh course Iowa University Distributed Systems course 22C:166