DBMS UNIT - 3 (From Deadlock)
DBMS UNIT - 3 (From Deadlock)
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
B. Wound-Wait Scheme
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.