Академический Документы
Профессиональный Документы
Культура Документы
Centralized Algorithms
Centralized Algorithm:
1. One process is elected as the coordinator. 2. Whenever a process wants to enter a Critical Section, it sends a REQUEST message to the coordinator asking for permission. 3. If no other process is currently in CS, the coordinator sends back a REPLY granting permission. 4. When the process finishes execution of CS, it sends a RELEASE message to the coordinator.
Centralized Algorithms
Advantages:
1. GUARANTEES mutual exclusion and it is also FAIR. 2. NO STARVATION. 3. Only 3 messages per entry are required to enter the CS: REQUEST, GRANT, and RELEASE.
Drawbacks:
1. If the coordinator crashes, the entire system may go down. 2. There is no distinction between a dead coordinator and permission denied, since in both cases no messages come back to the requesting process. 3. The single coordinator can become a performance bottleneck.
Decision
DECISION on whether Pj replies immediately to a REQUEST (Pi, TS) or defer its REPLY: >> If Pj is in the CS, then it defers its REPLY to Pi. >> If Pj does not want to enter the CS, then it sends a REPLY immediately. >> If Pj wants to enter the CS but has not yet entered it, then it compares its own REQUEST TS (timestamp) with the TS of the incoming message made by Pi. If Pjs TS > Pis TS (meaning that Pj is younger), then it sends a REPLY immediately to Pi. Otherwise, it defers the REPLY.
(2) If one process fails, then the entire scheme collapses. Resolution: By continuously monitoring the state of all processes in the group. If one process fails, then all other processes are notified, so that they will no longer send REQUEST messages to the failed process. When a process recovers, it must initiate the procedure that allows it to rejoin the group.
Abstract Ring
p2 p3 p2 p4 p6 p1 p3
p1
p4
p2 p5
p5
p6 p5
token
>> Phold designates the process in possession of the privilege token. >> The Algorithm maintains three invariants: (1) Process Phold is the root of the tree. (2) Each process in the system belongs to the tree. (3) Each process Pi other than Phold has exactly one outgoing edge (Pi, Pj) where Pj is the parent of Pi in the tree. >> A path from Pi to Phold exists in the system for every Pi other than Phold. >> The algorithm requires O(log n) messages per entry to CS, where n is the number of messages in the system.
p3
p3
p5
p6
p2
p4
>> When process P5 releases the CS, it (see Step (3)) (3)a. removes the P3 from its local queue, (3)b. passes the token to P3, (3)c. reverses the edge (P3, P5). (3)d. P5 now sends a request to P3 since its local queue is not empty. The result is shown in Figure (d).
>> P3 performs similar actions (see Step 4), which result in sending the token to process P4, reversal of edge (P4, P3) and sending of a request by P3 to P4. The result is shown in Figure (e). >> P4 now enter s CS. After P4 completes the CS, the token is transferred to process P1 via P3 and P5 in an analogous manner, which enables P1 to enter the CS. Note that this would not have been possible if Step 3(d) had not been executed.
Illustrating Example
p3 p1
p5 p1
p5
p1
p1
p3
p4
p1
p1
p3
p4 p5
p6
p2
p4
p4
p6
p2
p4
p4
(c)
(d)
Illustrating Example
p1
p5 p1
p5
p1
p1
p3
p4 p5
p1
p1
p3
p5
p6
p2
p4
p4
p6
p2
p4
p3
(d)
(e)
ELECTION Algorithm
>> The algorithms that determine where a new copy of the coordinator should be restarted if the coordinator fails. >> Election algorithms assume that a unique priority number is associated with each active process in the system. Further, assume the priority number for Pi to be i. >> The coordinator is always the process with the highest priority number.
An Example
a. Assumes the system consisting of processes P1 through P4, and initially, all processes are active; P4 is the coordinator. b. P1 and P4 fail. P2 determines that P4 has failed by sending a REQUEST that is not answered within time T. P2 then begins its ELECTION by sending a REQUEST to P3 (This is the only active process with priority number greater than p2.) c. P3 receives the REQUEST, responds to P2, and begins its own ELECTION by sending an ELECTION message to P4 (P3 does not know P4 has failed.) d. P2 receives P3s RESPONSE and begins waiting to receive a message informing it that a process with a higher priority number has been elected. (What if no message is received within a time interval T? This means P3 failed after it sent a RESPONSE message to P2. P2 should RESTART the ELECTION algorithm.)
(conti.)
e. P4 does not respond within an interval T, so P3 elects itself the new coordinator and informs P1 and P2. (P1 does not receive the message, since it has failed.) f. Later, when P1 recovers, it sends an ELECTION message to P2, P3, and P4. g. P2 and P3 respond to P1 and begin their own ELECTION. P3 will again be elected, though the same events as before. h. Finally, P4 recovers and notifies P1, P2, and P3 that it is the current coordinator. (Note: P4 sends no ELECTION requests, since it is the process with the highest number in the system.)
Another Example
(a) Process 4 holds an election. (b) Processes 5 and 6 respond, telling 4 to stop. (c) Now 5 and 6 each hold an election.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
(d) Process 6 tells 5 to stop. (e) Process 6 wins and tells everyone.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
[2]
7 [5,6] 3 [2,3] no response 6 [5] 5 4
(conti.)
>> When a node receives an ELECTION message from a node other than its parent, it merely acknowledges the receipt. >> When node R has designated node Q as its parent, it forwards the ELECTION message to its immediate neighbors (excluding Q) and waits for acknowledgements to come in before acknowledging the ELECTION message from Q. >> This waiting has an important consequence: 1st: Note that neighbors that have already selected a parent will immediately respond to R. 2nd: If all neighbors already have a parent, R is a leaf node and will be able to report back to Q quickly. In doing so, it will also report information such as its battery lifetime and other resource capacity.
(conti.)
>> This information will later allow Q to compare Rs capacities to that of other downstream nodes, and select the best eligible node for leadership. >> Of course, Q had sent an ELECTION message only because its own parent P had done so as well. >> In turn, when Q eventually acknowledges the ELECTION message previously sent by P, it will pass the most eligible node to P as well. >> In this way, the source will eventually get to know which node is best to be selected as leader, after which it will broadcast this information to all other nodes.
Election algorithm in a wireless network, with node a as the source. (a) Initial network. (b)(e) The build-tree phase
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Election algorithm in a wireless network, with node a as the source. (a) Initial network. (b)(e) The build-tree phase
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Figure 6-22. (e) The build-tree phase. (f) Reporting of best node to source.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5
Each process in the system is assigned a unique timestamp when it is created. The wait-die scheme: Based on a nonpreemptive technique When process Pi requests a resource currently held by Pj, Pi is allowed to wait only if it has a smaller timestamp than does pj (i.e., Pi is older than Pj). Otherwise, Pi is rolled back (dies).
(conti.)
The wound-wait scheme: Based on a preemptive technique When process Pi requests a resource currently held by Pj, Pi is allowed to wait only if it has a larger timestamp than does pj (i.e., Pi is younger than Pj). Otherwise, Pj is rolled back (Pj is wounded by Pi.)
Example
Suppose that processes P1, p2, and P3 have timestamps 5, 10, and 15, respectively. With the wait-die scheme, if P1 requests a resource held by P2, P1 will wait. If P3 requests a resource held by P2, P3 will be rolled back. With the wound-wait scheme, if P1 requests a resource held by P2, then the resource will be preempted from P2, and P2 will be rolled back. If P3 requests a resource held by P2, then P3 will wait.
Both schemes can avoid starvation provided that, when a process is rolled back, it is not assigned a new timestamp. Differences: wait-die: an older process must wait for a younger one to release its resource. wound-wait : an older process never waits for a younger process. wait-die: if Pi dies and is rolled back because it has requested a resource held by Pj, then Pi may reissue the same sequence of requests when it is restarted. If the resource is still held by Pj, then Pi will die again. Thus, Pi may rollback (die) several times before acquiring the needed resource. wound-wait : Pi is wounded and rolled back because Pj has requested a resource it holds. When Pi is restarted and requests the resource now being held by Pj, Pi waits. Thus, fewer rollbacks occur in the wound-wait scheme.
Discussion
Deadlock Detection
The deadlock-prevention algorithm may preempt resources even if no deadlock has occurred. To prevent unnecessary preemptions, we can use a deadlock-detection algorithm. If we assume only a single resource of each type, a cycle in the wait-for graph represents a deadlock. Problem in DS: How to maintain the wait-for graph?
Wait-For Graph
Local wait-for graphs are constructed as usual. When a process Pi in site S1 needs a resource held by process Pj in site S2, a request message is sent by Pi to site S2. The edge Pi Pj is then inserted in the local wait-for graph of site S2. If any local wait-for graph has a cycle, deadlock has occurred. The fact that we find no cycles in any of the local wait-for graphs does not mean that there are no deadlocks, however.
Example
p1 p2 p2 p4
p5
p3
p3 Site S2
Site S1
p2 p1
p4
p5
p3