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

DBMS Presentation - Concurrency Control

The document discusses concurrency control in database management systems, focusing on techniques such as lock-based protocols, two-phase locking, and timestamp-based protocols. It explains the types of locks, deadlock scenarios, and methods for deadlock avoidance and prevention. Additionally, it highlights the advantages and disadvantages of different concurrency control methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

DBMS Presentation - Concurrency Control

The document discusses concurrency control in database management systems, focusing on techniques such as lock-based protocols, two-phase locking, and timestamp-based protocols. It explains the types of locks, deadlock scenarios, and methods for deadlock avoidance and prevention. Additionally, it highlights the advantages and disadvantages of different concurrency control methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Department of Management

Studies, Kumaun University,


Bhimtal (Nainital) 263136

Database Management System


MI-202
Name : Saurabh Joshi
Roll. No. : 201405880020
Course : B.M.S – M.B.A Integrated
(II Sem.)

Submitted to : Dr. Sunil


Kumar Arora
Topic
Types of Locks,
Two Phases Locking- Deadlock,
Time Stamp Based on Concurrency
Control
Contents
• Concurrency Control
• Concurrency Control Techniques
• Types of Locks
• Two Phase Locking
• Deadlocking
• Bibliography
Concurrency Control
• Concurrency Control is the working concept
that is required for controlling and managing
the concurrent execution of database
operations and thus avoiding the
inconsistencies in the database. Thus, for
maintaining the concurrency of the database,
we have the concurrency control protocols.
Concurrency Control
Techniques:-
The concurrency control protocols ensure the atomicity,
consistency, isolation, durability and serializability of the
concurrent execution of the database transactions.
Therefore, these protocols are categorized as:
1. Lock Based Concurrency Control Protocol
2. Time Stamp Concurrency Control Protocol
3. Validation Based Concurrency Control Protocol
1. Lock – Based Technique:
Locking data items is a commonly used technique for controlling
concurrent execution of transactions.
In this type of protocol, any transaction cannot read or write data until
it acquires an appropriate lock on it.
A lock guarantees exclusive use of a data item to a current transaction.
• The lock is used to:
1. To Access Data Item (Lock Acquire)
2. After Completion of transaction. (Release Lock)
• All data items must be accessed in a mutually exclusive manner.
Types of Locks
• Shared lock: (Lock- S)
It is also known as a Read-only lock. In a shared lock, the data
item can only read by the transaction.
It can be shared between the transactions because when the
transaction holds a lock, then it can’t update the data on the data
item.
• Exclusive lock: (Lock- X)
• In the exclusive lock, the data item can be both reads as well as
written by the transaction.
This lock is exclusive, and in this lock, multiple transactions do
not modify the same data simultaneously.
Compatibility
between Lock
Modes:-
If you have shared Lock on 1
transaction and another
transaction also wants to read
that data item. So, it is
allowed because many
transactions can read it at a
particular time.
But, a compatibility between
shared and exclusive lock is
false, because when an
exclusive lock is involved it
cannot be accessible with
another transaction.
Example of Lock
Protocol

Note: Any no. of


Transactions can hold
Shared Lock on an
item but Exclusive
Lock can be hold only
by one transaction at a
time.
Two Phase Locking (2PL)
Two Phase Locking Protocol: Requires both Locks and
Unlocks being done in two phases.
There are two phases:
1. Growing (Expanding) Phase: locks are acquired and no
locks are released.
2. Shrinking Phase: locks are released and no new locks
can be acquired.
• Lock Point: A point at which transaction has obtained its
final lock, and as soon as a transaction enters a lock point
Shrinking Phase is Started
Deadlock in DBMS
A deadlock is a condition where two or
more transactions are waiting
indefinitely for one another to give up
locks. Deadlock is said to be one of the
most feared complications in DBMS as
no task ever gets finished and is in
waiting state forever.
If two or more processes are
waiting on happening of some
event, but that event doesn’t
happen. It is Simply called
deadlock, and those two processes
Example of For example: In the student table,
transaction T1 holds a lock on some rows
Deadlock and needs to update some rows in the
grade table. Simultaneously, transaction
T2 holds locks on some rows in the grade
table and needs to update the rows in the
Student table held by Transaction T1.
Now, the main problem arises. Now
Transaction T1 is waiting for T2 to release
its lock and similarly, transaction T2 is
waiting for T1 to release its lock. All
activities come to a halt state and remain
at a standstill. It will remain in a standstill
until the DBMS detects the deadlock and
aborts one of the transactions.
Deadlock Avoidance
When a database is stuck in a deadlock, It is always better to avoid the
deadlock rather than restarting or aborting the database. Deadlock
avoidance method is suitable for smaller databases whereas deadlock
prevention method is suitable for larger databases.This is a waste of
time and resource.

• One method of avoiding deadlock is using application-consistent logic.
In the above given example, Transactions that access Students and
Grades should always access the tables in the same order. In this way,
in the scenario described above, Transaction T1 simply waits for
transaction T2 to release the lock on Grades before it begins. When
transaction T2 releases the lock, Transaction T1 can proceed freely.
• Another method for avoiding deadlock is to apply both row-level
locking mechanism and READ COMMITTED isolation level. However, It
does not guarantee to remove deadlocks completely.
Deadlock Prevention
Deadlock prevention method is suitable for a large
database. If the resources are allocated in such a way
that deadlock never occurs, then the deadlock can be
prevented.

• The Database management system analyzes the
operations of the transaction whether they can
create a deadlock situation or not. If they do, then
the DBMS never allowed that transaction to be
executed.
Timestamp- based Protocol
Timestamp based Protocol in DBMS is an algorithm which uses the System Time or
Logical Counter as a timestamp to serialize the execution of concurrent
transactions. The Timestamp-based protocol ensures that every conflicting read and
write operations are executed in a timestamp order.

The older transaction is always given priority in this method. It uses system time to
determine the time stamp of the transaction. This is the most commonly used
concurrency protocol.

Lock-based protocols help you to manage the order between the conflicting
transactions when they will execute. Timestamp-based protocols manage conflicts as
soon as an operation is created.
A timestamp is a tag that can be attached to any transaction or any data item, which
denotes specific time on which the data item had been activated in any way.
Example
Suppose there are there transactions T1, T2, and T3.
T1 has entered the system at time 0010 – 100(older)
T2 has entered the system at 0020 – 200(younger)
T3 has entered the system at 0030 – 300(youngest)
Priority will be given to transaction T1, then transaction T2 and
lastly Transaction T3.
• Ts (T1) - 100
• Ts (T2) - 200
• Ts (T3) - 300
Types of Timestamp
Read_Ts (RTS): Write_Ts (WTS):
• Last (latest) transaction • Last (latest) transaction
no. which Performed Read no. Which Performed Write
Successfully. So, here Successfully. So, here
RTS(A)T1= 300
T2 T3 WTS(A) T1
= 200T2 T3
W(A) R(A)
W(A) R(A)
W(A) R(A)
100 200 300 100 200 300
• Transaction T1 issues a
Read(A) operation
1. If WTS(A) > TS(T1), Rollback T1
2. Otherwise execute R(A) operation
Set RTS(A) = Max

Rules
{RTS(A), TS(T1)}

• Transaction T1 issues Write(A)


operation
1. If RTS(A) > TS(T1) then Rollback
T1 (old) T2 (young) T1
2. If WTS(A) > TS(T1) then
R(A) Rollback T1
W(A) 3. Otherwise execute write(A)
operation
W(A)
Set WTS(A) = TS (T1)
R(A)
• The Transaction which came
First will be completed First.
i.e. Older Transaction is given
Advantages & Disadvantages
Advantages:
Schedules are serializable just like 2PL
protocols
No waiting for the transaction, which
eliminates the possibility of deadlocks!

Disadvantages:
Starvation is possible if the same transaction
Bibliography
1. Slideshare.com
2. www.google.com
3. www.geeksforgeeks.com
Thank You

You might also like