0% found this document useful (0 votes)
15 views36 pages

Concurrency Control

The document discusses concurrency control and recovery systems in database management systems (DBMS), emphasizing the importance of managing simultaneous transactions to prevent data inconsistency. It outlines various concurrency control problems such as dirty reads and lost updates, and describes protocols like lock-based and timestamp-based methods for ensuring data integrity. Additionally, it covers deadlock handling and recovery mechanisms to address failures in the system.

Uploaded by

utkarx10106
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)
15 views36 pages

Concurrency Control

The document discusses concurrency control and recovery systems in database management systems (DBMS), emphasizing the importance of managing simultaneous transactions to prevent data inconsistency. It outlines various concurrency control problems such as dirty reads and lost updates, and describes protocols like lock-based and timestamp-based methods for ensuring data integrity. Additionally, it covers deadlock handling and recovery mechanisms to address failures in the system.

Uploaded by

utkarx10106
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/ 36

Concurrency Control

and
Recovery system
Concurrency Control: Lock based protocols--Deadlock
handling-Multiple Granularity-Time stamp based protocols -
System recovery, Two- Phase Commit protocol, Recovery
system: Failure classification --Recovery and atomicity -
Recovery Algorithms.
Concurrency control
Concurrency control is a very important concept of DBMS
which ensures the simultaneous execution or manipulation of
data by several processes or user without resulting in data
inconsistency.
Concurrency Control deals with interleaved execution of
more than one transaction.
Concurrency Control Problems

• There are several problems that arise when numerous


transactions are executed simultaneously in a random
manner.
• The database transaction consist of two major operations
“Read” and “Write”.
• It is very important to manage these operations in the
concurrent execution of the transactions in order to
maintain the consistency of the data.
Dirty Read Problem(Write-Read conflict)
Dirty read problem occurs when one transaction updates an item but due to
some unconditional events that transaction fails but before the transaction
performs rollback, some other transaction reads the updated value. Thus
creates an inconsistency in the database. Dirty read problem comes under the
scenario of Write-Read conflict between the transactions in the database
• The lost update problem can be illustrated with the below scenario between
two transactions T1 and T2.
• Transaction T1 modifies a database record without committing the changes.
• T2 reads the uncommitted data changed by T1
• T1 performs rollback
• T2 has already read the uncommitted data of T1 which is no longer valid,
thus creating inconsistency in the database.
Lost Update Problem
• Lost update problem occurs when two or more transactions modify
the same data, resulting in the update being overwritten or lost by
another transaction. The lost update problem can be illustrated
with the below scenario between two transactions T1 and T2.
• T1 reads the value of an item from the database.
• T2 starts and reads the same database item.
• T1 updates the value of that data and performs a commit.
• T2 updates the same data item based on its initial read and
performs commit.
• This results in the modification of T1 gets lost by the T2’s write
which causes a lost update problem in the database.
Concurrency Control Protocols

• Concurrency control protocols are the set of rules which


are maintained in order to solve the concurrency control
problems in the database.
• It ensures that the concurrent transactions can execute
properly while maintaining the database consistency.
• The concurrent execution of a transaction is provided with
atomicity, consistency, isolation, durability, and
serializability via the concurrency control protocols.
Locked based concurrency control protocol
Timestamp based concurrency control protocol
Locked based Protocol
In locked based protocol, each transaction needs to acquire locks before they start
accessing or modifying the data items. There are two types of locks used in
databases.
Shared Lock :
1. Shared lock is also known as read lock which allows multiple transactions to
read the data simultaneously.
2. The transaction which is holding a shared lock can only read the data item but
it can not modify the data item.
Exclusive Lock :
3. Exclusive lock is also known as the write lock. Exclusive lock allows a
transaction to update a data item.
4. Only one transaction can hold the exclusive lock on a data item at a time.
5. While a transaction is holding an exclusive lock on a data item, no other
transaction is allowed to acquire a shared/exclusive lock on the same data item.
Lock Compatibility Matrix
• A transaction may be granted a lock on an item if the
requested lock is compatible with locks already held on
the item by other transactions.
• Any number of transactions can hold shared locks on an
item, but if any transaction holds an exclusive(X) on the
item no other transaction may hold any lock on the item.
• If a lock cannot be granted, the requesting transaction is
made to wait till all incompatible locks held by other
transactions have been released. Then the lock is granted.
Types of Lock-Based Protocols

1. Simplistic Lock Protocol


• It is the simplest method for locking data during a
transaction.
• Simple lock-based protocols enable all transactions to
obtain a lock on the data before inserting, deleting, or
updating it.
• It will unlock the data item once the transaction is
completed.
2. Pre-Claiming Lock Protocol

• Pre-claiming Lock Protocols assess transactions to determine which


data elements require locks.
• Before executing the transaction, it asks the DBMS for a lock on all of
the data elements.
• If all locks are given, this protocol will allow the transaction to start.
• When the transaction is finished, it releases all locks.
• If all of the locks are not provided, this protocol allows the transaction
to be reversed and waits until all of the locks are granted.
3. Two-phase locking (2PL)

• A transaction is said to follow the Two-Phase Locking


protocol if Locking and Unlocking can be done in two
phases
• Growing Phase: New locks on data items may be
acquired but none can be released.
• Shrinking Phase: Existing locks may be released but no
new locks can be acquired.
4. Strict Two-Phase Locking Protocol

• Strict Two-Phase Locking requires that in addition to the


2-PL all Exclusive(X) locks held by the transaction be
released until after the Transaction Commits.
Problem With Simple Locking
• Consider the Partial Schedule:
S.No T1 T2 1. Deadlock
In deadlock consider the
1 lock-X(B)
above execution phase.
2 read(B) Now, T1 holds an
3 B:=B-50 Exclusive lock over B,
and T2 holds a Shared
4 write(B)
lock over A. Consider
5 lock-S(A) Statement 7, T2 requests
for lock on B, while in
6 read(A)
Statement 8 T1 requests
7 lock-S(B) lock on A. This as you
8 lock-X(A) may notice imposes a
deadlock as none can
9 …… …… proceed with their
execution.
2. Starvation

• Starvation is also possible if concurrency control manager


is badly designed.
• For example: A transaction may be waiting for an X-lock
on an item, while a sequence of other transactions request
and are granted an S-lock on the same item.
• This may be avoided if the concurrency control manager is
properly designed.
Time stamp based protocols
• Lock based protocols ensure conflict serializability but it
causes 2 problems ➢ Deadlock and
➢ Starvation
❑ The alternative approaches to control concurrency are
1) Timestamp-Based Protocols
2) Validation Based Protocols
Timestamp-Based Protocols
• ❑ The Timestamp methods for concurrency control does
not need any locks and therefore there are no deadlocks
• ❑ Locking methods generally prevent conflicts by making
transactions to wait.
• ❑ Timestamp methods do not make the transactions wait.
• ❑ In this method, Transactions involved in a conflict are
simply rolled back and restarted.
• The most commonly used concurrency protocol is the timestamp
based protocol. This protocol uses either system time or logical
counter as a timestamp.
• Lock-based protocols manage the order between the conflicting
pairs among transactions at the time of execution, whereas
timestamp-based protocols start working as soon as a transaction
is created.
• Every transaction has a timestamp associated with it, and the
ordering is determined by the age of the transaction.
• A transaction created at 0002 clock time would be older than all
other transactions that come after it.
• For example, any transaction 'y' entering the system at 0004 is two
seconds younger and the priority would be given to the older one.
• In addition, every data item is given the latest read and
write-timestamp. This lets the system know when the last
‘read and write’ operation was performed on the data
item.
Timestamp Ordering Protocol
• The timestamp-ordering protocol ensures serializability
among transactions in their conflicting read and write
operations.
• This is the responsibility of the protocol system that the
conflicting pair of tasks should be executed according to
the timestamp values of the transactions.
Timestamp Ordering Protocol
Multiple Granularity Locking in DBMS

• It is the size of the data item allowed to lock.


• Now Multiple Granularity means hierarchically breaking
up the database into blocks that can be locked and can be
tracked what needs to lock and in what fashion.
• Such a hierarchy can be represented graphically as a
tree.
Hence, the levels starting from the top level are:
•database
•area
•File
•record
Consider the above diagram for the example
given, each node in the tree can be locked
individually. As in the 2-phase locking protocol, it
shall use shared and exclusive lock modes. When
a transaction locks a node, in either shared or
exclusive mode, the transaction also implicitly
locks all the descendants of that node in the same
lock mode.
Deadlock Handling
• A System is in a Dead lock state if there exists a set of
Transactions such that every transaction in the set is
waiting for another transaction in the set.
Recovery system: Failure
Classification
Disk Failure
❑ In early days of technology evolution, it was a common
problem where harddisk drives or storage drives used to fail
frequently.
❑ Disk failures include formation of bad sectors,
unreachability to the disk, disk head crash or any other
failure, which destroys all or a part of disk storage.
Recovery and Atomicity

You might also like