0% found this document useful (0 votes)
51 views

DBMS UNIT - 3 (From Deadlock)

aktu

Uploaded by

patelomkar22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

DBMS UNIT - 3 (From Deadlock)

aktu

Uploaded by

patelomkar22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Deadlock

Deadlock is a situation where a process or a set of processes is blocked, waiting for


some other resource that is held by some other waiting process. It is an undesirable
state of the system.

The following are the four conditions that must hold simultaneously for a deadlock
to occur.
1. Mutual Exclusion – A resource can be used by only one process at a
time. If another process requests for that resource then the requesting
process must be delayed until the resource has been released.
2. Hold and wait – Some processes must be holding some resources in the
non-shareable mode and at the same time must be waiting to acquire some
more resources, which are currently held by other processes in the non-
shareable mode.
3. No pre-emption – Resources granted to a process can be released back to
the system only as a result of voluntary action of that process after the
process has completed its task.
4. Circular wait – Deadlocked processes are involved in a circular chain
such that each process holds one or more resources being requested by the
next process in the chain.
Methods of handling deadlocks

1. Deadlock Prevention
2. Deadlock avoidance (Banker's Algorithm)
3. Deadlock detection & recovery
4. Deadlock Ignorance (Ostrich Method)

1. Deadlock Prevention
 Deadlock happens whenever four conditions occur at the same time. If one of the four
conditions can be interrupted, we can prevent the system from becoming stuck in a deadlock.
 This mechanism exists for a straightforward reason. To put it another way, we only need to
fail in one of the requirements. It’s critical to avoid a given deadlock before it happens. As a
result, the system verifies each and every transaction before executing it to ensure that it does
not cause a deadlock. If a transaction has even the slightest chance of causing a deadlock, it is
then not allowed to run at all.

The following are some deadlock prevention strategies that make use of
timestamps to ensure that a deadlock doesn’t occur:

1. Wait-Die Scheme

2 Wound-Wait Scheme
A. Wait-Die Scheme

 The Wait-Die algorithm is a deadlock prevention scheme used in DBMS


(Database Management Systems). The algorithm makes use of timestamps
to prevent deadlocks from occurring in a multi-user database environment.
 The concept is that transactions with older timestamps are given priority to
access a resource, and transactions with newer timestamps are forced to
wait.

 Wait: If a transaction T1 requests a lock on a resource that is currently


locked by T2, and T2 has a smaller timestamp than T1, T1 waits until T2
releases the lock.

 Die: If a transaction T1 requests a lock on a resource that is currently locked


by T2, and T2 has a larger timestamp than T1, T1 aborts (dies). The
reasoning behind this is that T1 has a lower priority, and allowing it to
proceed could lead to a deadlock.

 If TS(Ti ) < TS(Tj ), i.e., Ti , which is requesting a conflicting lock,


is older than Tj , Ti is allowed to wait until the data item is
available.

B. Wound-Wait Scheme

 The Wound-Wait Algorithm is a deadlock prevention strategy in database


management systems (DBMS). It is based on the idea that the process
requesting a resource with the lowest timestamp (i.e., the oldest process)
will be granted access to the resource first.

 If TS(Ti ) < TS(Tj ), i.e., Ti , which is requesting a conflicting lock,


is older than Tj , Ti forces Tj to be rolled back, that is Ti wounds
Tj . Tj is restarted later with random delay but with same
timestamp.
2. Deadlock Detection
 The resource scheduler can detect deadlock because it maintains track of all the resources
allotted to different processes. When a deadlock is found, it can be resolved using the
methods provided.
 Deadlock detection is accomplished by using an algorithm that tracks cyclic waiting and kills
one or more processes in order to break the deadlock.
 The state of the system is checked on a regular basis to see whether any processes are stuck.
 A deadlock is broken by aborting and restarting a process, releasing all resources held by the
previous process.

2. Deadlock Avoidance
 The deadlock avoidance Algorithm works by proactively looking for potential
deadlock situations before they occur.
 It does this by tracking the resource usage of each process and identifying
conflicts that could potentially lead to a deadlock.
 If a potential deadlock is identified, the algorithm will take steps to resolve
the conflict, such as rolling back one of the processes or pre-emptively
allocating resources to other processes.

4. Deadlock Ignorance
 In the Deadlock ignorance method the OS acts like the deadlock never occurs
and completely ignores it even if the deadlock occurs.
 In the Deadlock ignorance method the OS acts like the deadlock never
occurs and completely ignores it even if the deadlock occurs.
 The algorithm is very simple. It says ” if the deadlock occurs, simply reboot
the system and act like the deadlock never occurred.” That’s why the
algorithm is called the Ostrich Algorithm.
Distributed databases
 A distributed database system consists of collection of sites, connected
together through a communication network.
 Each site is a database system site in its own right and the sites have
agreed to work together, so that a user at any site can access anywhere
in the network.

Advantages of DDBMS
 immediate and efficient access to data.
 It allows access to the data stored at remote sites. At the same time
users can retain the control to its own site to access the local data.
 If one site is not working the system will not be down because other
sites of the network can possibly continue functioning.

Disadvantages of DDBMS
 Complex software is required.
 The various sites must exchange message and perform additional
calculations to ensure proper coordination among the sites.
 If the data are not distributed properly according to their usage, or if
queries are not formulated correctly, response to requests for data can
be extremely slow.
Two types of distributed data storage

1.Data replication
 In this approach, the entire relationship is stored redundantly at 2 or more
sites. If the entire database is available at all sites, it is a fully redundant
database. Hence, in replication, systems maintain copies of data.
 This is advantageous as it increases the availability of data at different sites.
Also, now query requests can be processed in parallel.
 However, it has certain disadvantages as well. Data needs to be constantly
updated. Any change made at one site needs to be recorded at every site that
relation is stored or else it may lead to inconsistency.

2. Data fragmentation
 In this approach, the relations are fragmented (i.e., they’re divided into
smaller parts) and each of the fragments is stored in different sites where
they’re required.
 It must be made sure that the fragments are such that they can be used to
reconstruct the original relation (i.e, there isn’t any loss of data).
 Fragmentation is advantageous as it doesn’t create copies of data, consistency
is not a problem.

You might also like