Locking protocols are used in database management systems as a means of concurrency control. Multiple transactions may request a lock on a data item simultaneously. Hence, we require a mechanism to manage the locking requests made by transactions. Such a mechanism is called as Lock Manager. It relies on the process of message passing where transactions and lock manager exchange messages to handle the locking and unlocking of data items.
Data structure used in Lock Manager –
The data structure required for implementation of locking is called as Lock table.
- It is a hash table where name of data items are used as hashing index.
- Each locked data item has a linked list associated with it.
- Every node in the linked list represents the transaction which requested for lock, mode of lock requested (mutual/exclusive) and current status of the request (granted/waiting).
- Every new lock request for the data item will be added in the end of linked list as a new node.
- Collisions in hash table are handled by technique of separate chaining.
Consider the following example of lock table:
Explanation: In the above figure, the locked data items present in lock table are 5, 47, 167 and 15.
The transactions which have requested for lock have been represented by a linked list shown below them using a downward arrow.
Each node in linked list has the name of transaction which has requested the data item like T33, T1, T27 etc.
The colour of node represents the status i.e. whether lock has been granted or waiting.
Note that a collision has occurred for data item 5 and 47. It has been resolved by separate chaining where each data item belongs to a linked list. The data item is acting as header for linked list containing the locking request.
Working of Lock Manager –
- Initially the lock table is table empty as no data item is locked.
- Whenever lock manger receives a lock request from a transaction Ti on a particular data item Qi following cases may arise:
- If Qi is not already locked, a linked list will be created and lock will be granted to the requesting transaction Ti.
- If the data item is already locked, a new node will be added at the end of its linked list containing the information about request made by Ti.
Database system Concepts, 6th edition
- Multiple Granularity Locking in DBMS
- Two Phase Locking Protocol
- Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3
- Categories of Two Phase Locking (Strict, Rigorous & Conservative)
- Implementation of ls | wc command
- B*-Trees implementation in C++
- LRU Cache Implementation
- Implementation of a Falling Matrix
- Array implementation of queue (Simple)
- UDP Client Server using connect | C implementation
- Decision tree implementation using Python
- Binary Tree (Array implementation)
- Bloom Filters - Introduction and Python Implementation
- Johnson’s algorithm for All-pairs shortest paths | Implementation
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Ayushi Jain 10