CS 6378, Fall 2004 Midterm 2, October 21, 2004 Student Name: ID #: Important: a. b. c. Examination is for 20 marks (4 questions). Duration: 75 minutes. Keep your answers short: typically 5-6 sentences should suffice. Longer answers may invite negative credit. Discuss with me during the exam before making any assumptions. Questions: 1. Lamport’s algorithm has a message complexity of 3*(N-1). We discussed briefly the following optimization strategy that brings down the message complexity to somewhere between 2*(N-1) and 3*(N-1): “Suppress reply messages. (e.g.) Sj receives a REQUEST message from Si after sending its own REQUEST message with time stamp higher than that of Si’s. Do NOT send REPLY message.” Ricart-Agrawala’s algorithm has an even better message complexity of 2*(N-1) [not considering the allowed repeated CS entries]. This algorithm does not use RELEASE message and uses the REPLY message itself judiciously for that purpose. Do you think you can apply something similar (need not be exactly same) to the Lamport’s optimization strategy for Ricart-Agrwala? For instance, do you think you can suppress REPLY message from S1 & S3, and allow S2 to enter CS at Tx (instead of Ty)? The reason being S2 knows about that the time stamps of the requests from S1 and S3 are higher. a) If your answer is yes, you should outline the complete optimization strategy for RicartAgrawala and specify the new message complexity. b) If your answer is no, you should explain what aspects will go wrong using a space-time diagram similar to the one below (or an extension to it). (5 Marks) S1 S2 (5, 1) (3, 2) Ty Tx S3 (4, 3) Answer: Yes, you can. Modification for Ricart-Agrawala: Executing CS: “After Si sent its REQUEST, Si has received from all other sites either a REQUEST message with time stamp larger than (tsi,i) or a REPLY message.” New message complexity: varies from (N-1) to 2*(N-1). 2. The initialization of SV (status vector) in Singhal’s algorithm is done in a “staircase pattern”: number of Rs in each site decrease from left to right (with sites arranged in decreasing order). This initialization pattern ensures that a token request will always be received by a group of nodes among which token resides. Will this staircase pattern be preserved during the numerous token exchanges? Why? (5 Marks) N N N N N N N N R N R N N N R N H N N R N N N R R 3 R 2 1 R R R R n N R R R R Sn S3 S2 Status Vector SV in each site Si N S1 Answer: When there is no “left over work”, i.e. no pending CS requests, the system will satisfy the staircase pattern. Here, number of Rs in each site decrease from left to right even though the order of sites will be interchanged. E.g., let us assume the order of requests to be: S3, S5, and lastly S2. The updated staircase pattern is shown below: 4Rs in S4, 3Rs in S1, 2Rs in S3, 1 R in S5, and H in S2. N R N N N N N N R N R N N R N H N N N R N R R 4 R N 3 R 2 1 R R R R n 5 N R R N N Sn S5 S4 S1 S3 Status Vector SV in each site Si N S2 3. We saw that some deadlock detection algorithms may detect false deadlocks, i.e., pronounce a deadlock where none actually exists. Do you think diffusion based algorithm deadlock will detect false deadlocks? Why? (4 Marks) Answer: False deadlock occurs when the algorithm says there is a deadlock and no deadlock exists. This occurs when there is a time interval between decision making and response given, e.g., HoRamamurthy approach. In diffusion-based approach, decision making is done in a distributed manner. For instance, a process decides to give a Reply if (i) it is not an engaging query and (ii) if it has collected the number of replies equal to the number of processes in its dependent set. There is no time lag between the decision of forwarding reply and the receipt of other replies/the “not engaging” query. This decision making process of forwarding reply messages is done in a distributed manner until it comes to the initiator. Hence, the algorithm does not detect false deadlocks. 4. CODA is a file system that tries to provide “constant data availability” through caching and replication. Here, servers can cache/replicate entire files from other servers and clients are also allowed to cache entire files. In fact, clients can cache files and even get disconnected (if they are mobile stations to save power etc.). Replica updates in Coda are handled using Coda Version Vectors (CVV). CVV is collection of update histories carried out on a particular replica. Before carrying out an update on the server, the CVVs of the server and the client are compared. Is there a possibility that the CVV on the client is greater (i.e., more recent) than that of the server? Why? (4 Marks) Answer: A simple situation: when client caches the whole file, gets disconnected, and makes updates, the CVV of client will be higher than the server’s. Brief Descriptions of Algorithms 1. Lamport’s Mutual Exclusion Algorithm: Requesting CS: Send REQUEST(tsi, i). (tsi,i): Request time stamp. Place REQUEST in request_queuei. On receiving the message; sj sends time-stamped REPLY message to si. Si’s request placed in request_queuej. Executing CS: Si has received a message with time stamp larger than (tsi,i) from all other sites. Si’s request is the top most one in request_queuei. Releasing CS: Exiting CS: send a time stamped RELEASE message to all sites in its request set. Receiving RELEASE message: Sj removes Si’s request from its queue. 2. Ricart-Agrawala’s Algorithm: Requesting critical section Si sends time stamped REQUEST message Sj sends REPLY to Si, if Sj is not requesting nor executing CS If Sj is requesting CS and Si’s time stamp is smaller than its own request. Request is deferred otherwise. Executing CS: after it has received REPLY from all sites in its request set. Releasing CS: Send REPLY to all deferred requests. i.e., a site’s REPLY messages are blocked only by sites with smaller time stamps 3. Diffusion-based Algorithm: Initiation by a blocked process Pi: send query(i,i,j) to all processes Pj in the dependent set DSi of Pi; num(i) := |DSi|; waiti(i) := true; Blocked process Pk receiving query(i,j,k): if this is engaging query for process Pk /* first query from Pi */ then send query(i,k,m) to all Pm in DSk; numk(i) := |DSk|; waitk(i) := true; else if waitk(i) then send a reply(i,k,j) to Pj. Process Pk receiving reply(i,j,k) if waitk(i) then numk(i) := numk(i) - 1; if numk(i) = 0 then if i = k then declare a deadlock. else send reply(i, k, m) to Pm, which sent the engaging query. 4. Singhal’s Heuristic Algorithm: Data Structures: Si maintains SVi[1..N] and SNi[1..N] for storing information on other sites: state and highest sequence number. Token contains 2 arrays: TSV[1..N] and TSN[1..N]. States of a site R : requesting CS; E : executing CS; H : Holding token, idle; N : None of the above Initialization: SVi[j] := N, for j = N .. i; SVi[j] := R, for j = i-1 .. 1; SNi[j] := 0, j = 1..N. S1 (Site 1) is in state H. Token: TSV[j] := N & TSN[j] := 0, j = 1 .. N. Requesting CS 1. If Si has no token and requests CS: a. SVi[i] := R. SNi[i] := SNi[i] + 1. b. Send REQUEST(i,sn) to sites Sj for which SVi[j] = R. (sn: sequence number, updated value of SNi[i]). 2. Receiving REQUEST(i,sn): if sn <= SNj[i], ignore. Otherwise, update SNj[i] and do: a. SVj[j] = N -> SVj[i] := R. b. SVj[j] = R -> If SVj[i] != R, set it to R & send REQUEST(j,SNj[j]) to Si. Else do nothing. c. SVj[j] = E -> SVj[i] := R. d. SVj[j] = H -> SVj[i] := R, TSV[i] := R, TSN[i] := sn, SVj[j] = N. Send token to Si. Executing CS: after getting token. Set SVi[i] := E. Releasing CS SVi[i] := N, TSV[i] := N. Then, do: For other Sj: if (SNi[j] > TSN[j]), then {TSV[j] := SVi[j]; TSN[j] := SNi[j]} else {SVi[j] := TSV[j]; SNi[j] := TSN[j]} If SVi[j] = N, for all N, then set SVi[i] := H. Else send token to a site Sj provided SVi[j] = R.