Concurrency Control Tecniques Unit-4
Concurrency Control Tecniques Unit-4
Example
Assume that two people who go to electronic kiosks at the same
time to buy a movie ticket for the same movie and the same show
time.
However, there is only one seat left in for the movie show in that
particular theatre. Without concurrency control in DBMS, it is
possible that both moviegoers will end up purchasing a ticket.
However, concurrency control method does not allow this to
happen. Both moviegoers can still access information written in the
movie seating database. But concurrency control only provides a
ticket to the buyer who has completed the transaction process first.
Lock-Based Protocols
Two Phase Locking Protocol
Timestamp-Based Protocols
Validation-Based Protocols
Lock-based Protocols
A shared lock is also called a Read-only lock. With the shared lock,
the data item can be shared between transactions. This is because
you will never have permission to update data on the data item.
With the Exclusive Lock, a data item can be read as well as written.
This is exclusive and can’t be held concurrently on the same data
item. X-lock is requested using lock-x instruction. Transactions may
unlock the data item after finishing the ‘write’ operation.
4. Pre-claiming Locking
Starvation
Deadlock
In the above-given diagram, you can see that local and global
deadlock detectors are searching for deadlocks and solve them with
resuming transactions to their initial states.
Deadlock Prevention
• Require that each transaction locks all its data items before it
begins execution (pre-declaration).
Poor data-item utilization (most of the time data items are idle)
• Older transaction may wait for younger one to release data item.
• Younger transactions never wait for older ones; they are rolled
back instead.
Timeout-Based Schemes:
• Simple to implement
Deadlock Detection
Wait-for graph
• Vertices: transactions
Deadlock Recovery
How many data items the transaction has used and how many
required for completion?
Centralized 2PL
In Centralized 2 PL, a single site is responsible for lock
management process. It has only one lock manager for the entire
DBMS.
Distributed 2PL
In this kind of two-phase locking mechanism, Lock managers are
distributed to all sites. They are responsible for managing locks for
data at that site. If no data is replicated, it is equivalent to primary
copy 2PL. Communication costs of Distributed 2PL are quite higher
than primary copy 2PL
Example:
Suppose there are there transactions T1, T2, and T3.
T1 has entered the system at time 0010
T2 has entered the system at 0020
T3 has entered the system at 0030
Priority will be given to transaction T1, then transaction T2
and lastly Transaction T3.
Advantages:
Disadvantages:
1. Read Phase
2. Validation Phase
3. Write Phase
Read Phase
In the Read Phase, the data values from the database can be read
by a transaction but the write operation or updates are only applied
to the local data copies, not the actual database.
Validation Phase
In Validation Phase, the data is checked to ensure that there is no
violation of serializability while applying the transaction updates to
the database.
Write Phase
In the Write Phase, the updates are applied to the database if the
validation is successful, else; the updates are not applied, and the
transaction is rolled back.
Enforcing Serializability
Certify Locks
Lock Compatibility
Granularity
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.
For example, consider the tree, which consists of four levels of nodes. The highest
level represents the entire database. Below it is nodes of type area; the database
consists of exactly these areas. The area has children nodes which are called files.
Every area has those files that are its child nodes. No file can span more than one
area.
Finally, each file has child nodes called records. As before, the file consists of exactly
those records that are its child nodes, and no record can be present in more than one
file. 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. For example, if transaction Ti gets an explicit lock on file Fc in exclusive
mode, then it has an implicit lock in exclusive mode on all the records belonging to
that file. It does not need to lock the individual records of Fc explicitly. this is the
main difference between Tree-Based Locking and Hierarchical locking for multiple
granularities.
Now, with locks on files and records made simple, how does the system determine if
the root node can be locked? One possibility is for it to search the entire tree but the
solution nullifies the whole purpose of the multiple-granularity locking scheme. A
more efficient way to gain this knowledge is to introduce a new lock mode,
called Intention lock mode.
Intention Mode Lock
In addition to S and X lock modes, there are three additional lock modes with multiple
granularities:
Intention-Shared (IS): explicit locking at a lower level of the tree but only
with shared locks.
Intention-Exclusive (IX): explicit locking at a lower level with exclusive or
shared locks.
Shared & Intention-Exclusive (SIX): the subtree rooted by that node is
locked explicitly in shared mode and explicit locking is being done at a
lower level with exclusive mode locks.
The compatibility matrix for these lock modes are described below: