Deadlock Handling Strategies in Distributed System
The following are the strategies used for Deadlock Handling in Distributed System:
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection and Recovery
1. Deadlock Prevention: As the name implies, this strategy ensures that deadlock can never happen because system designing is carried out in such a way. If any one of the deadlock-causing conditions is not met then deadlock can be prevented. Following are the three methods used for preventing deadlocks by making one of the deadlock conditions to be unsatisfied:
- Collective Requests: In this strategy, all the processes will declare the required resources for their execution beforehand and will be allowed to execute only if there is the availability of all the required resources. When the process ends up with processing then only resources will be released. Hence, the hold and wait condition of deadlock will be prevented.
- But the issue is initial resource requirements of a process before it starts are based on an assumption and not because they will be required. So, resources will be unnecessarily occupied by a process and prior allocation of resources also affects potential concurrency.
- Ordered Requests: In this strategy, ordering is imposed on the resources and thus, process requests for resources in increasing order. Hence, the circular wait condition of deadlock can be prevented.
- An ordering strictly indicates that a process never asks for a low resource while holding a high one.
- There are two more ways of dealing with global timing and transactions in distributed systems, both of which are based on the principle of assigning a global timestamp to each transaction as soon as it begins.
- During the execution of a process, if a process seems to be blocked because of the resource acquired by another process then the timestamp of the processes must be checked to identify the larger timestamp process. In this way, cycle waiting can be prevented.
- It is better to give priority to the old processes because of their long existence and might be holding more resources.
- It also eliminates starvation issues as the younger transaction will eventually be out of the system.
- Preemption: Resource allocation strategies that reject no-preemption conditions can be used to avoid deadlocks.
- Wait-die: If an older process requires a resource held by a younger process, the latter will have to wait. A young process will be destroyed if it requests a resource controlled by an older process.
- Wound-wait: If an old process seeks a resource held by a young process, the young process will be preempted, wounded, and killed, and the old process will resume and wait. If a young process needs a resource held by an older process, it will have to wait.
2. Deadlock Avoidance: In this strategy, deadlock can be avoided by examining the state of the system at every step. The distributed system reviews the allocation of resources and wherever it finds an unsafe state, the system backtracks one step and again comes to the safe state. For this, resource allocation takes time whenever requested by a process. Firstly, the system analysis occurs whether the granting of resources will make the system in a safe state or unsafe state then only allocation will be made.
- A safe state refers to the state when the system is not in deadlocked state and order is there for the process regarding the granting of requests.
- An unsafe state refers to the state when no safe sequence exists for the system. Safe sequence implies the ordering of a process in such a way that all the processes run to completion in a safe state.
3. Deadlock Detection and Recovery: In this strategy, deadlock is detected and an attempt is made to resolve the deadlock state of the system. These approaches rely on a Wait-For-Graph (WFG), which is generated and evaluated for cycles in some methods. The following two requirements must be met by a deadlock detection algorithm:
- Progress: In a given period, the algorithm must find all existing deadlocks. There should be no deadlock existing in the system which is undetected under this condition. To put it another way, after all, wait-for dependencies for a deadlock have arisen, the algorithm should not wait for any additional events to detect the deadlock.
- No False Deadlocks: Deadlocks that do not exist should not be reported by the algorithm which is called phantom or false deadlocks.
There are different types of deadlock detection techniques:
- Centralized Deadlock Detector: The resource graph for the entire system is managed by a central coordinator. When the coordinator detects a cycle, it terminates one of the processes involved in the cycle to break the deadlock. Messages must be passed when updating the coordinator’s graph. Following are the methods:
- A message must be provided to the coordinator whenever an arc is created or removed from the resource graph.
- Every process can transmit a list of arcs that have been added or removed since the last update periodically.
- When information is needed, the coordinator asks for it.
- Hierarchical Deadlock Detector: In this approach, deadlock detectors are arranged in a hierarchy. Here, only those deadlocks can be detected that fall within their range.
- Distributed Deadlock Detector: In this approach, detectors are distributed so that all the sites can fully participate to resolve the deadlock state. In one of the following below four classes for the Distributed Detection Algorithm- The probe-based scheme can be used for this purpose. It follows local WFGs to detect local deadlocks and probe messages to detect global deadlocks.
There are four classes for the Distributed Detection Algorithm:
- Path-pushing: In path-pushing algorithms, the detection of distributed deadlocks is carried out by maintaining an explicit global WFG.
- Edge-chasing: In an edge-chasing algorithm, probe messages are used to detect the presence of a cycle in a distributed graph structure along the edges of the graph.
- Diffusion computation: Here, the computation for deadlock detection is dispersed throughout the system’s WFG.
- Global state detection: The detection of Distributed deadlocks can be made by taking a snapshot of the system and then inspecting it for signs of a deadlock.
To recover from a deadlock, one of the methods can be followed:
- Termination of one or more processes that created the unsafe state.
- Using checkpoints for the periodic checking of the processes so that whenever required, rollback of processes that makes the system unsafe can be carried out and hence, maintained a safe state of the system.
- Breaking of existing wait-for relationships between the processes.
- Rollback of one or more blocked processes and allocating their resources to stopped processes, allowing them to restart operation.