Working as Lock Manager

  • Initially, the lock table is empty as no data item is locked.
  • Whenever the lock manager 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 a 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 the request made by Ti.
  • If the lock mode requested by Ti is compatible with the lock mode of the transaction currently having the lock, Ti will acquire the lock too and the status will be changed to ‘granted’. Else, the status of Ti’s safety will be ‘waiting’.
  • If a transaction Ti wants to unlock the data item it is currently holding, it will send an unlock request to the lock manager. The lock manager will delete Ti’s node from this linked list. The lock will be granted to the next transaction in the list.
  • Sometimes transaction Ti may have to be aborted. In such a case all the waiting requests made by Ti will be deleted from the linked lists present in the lock table. Once abortion is complete, locks held by Ti will also be released.

Implementation of Locking in DBMS

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 a 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. 

Similar Reads

Data Structure in Lock Manager

The data structure required for the implementation of locking is called a Lock table....

Working as Lock Manager

Initially, the lock table is empty as no data item is locked. Whenever the lock manager 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 a 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 the request made by Ti. If the lock mode requested by Ti is compatible with the lock mode of the transaction currently having the lock, Ti will acquire the lock too and the status will be changed to ‘granted’. Else, the status of Ti’s safety will be ‘waiting’. If a transaction Ti wants to unlock the data item it is currently holding, it will send an unlock request to the lock manager. The lock manager will delete Ti’s node from this linked list. The lock will be granted to the next transaction in the list. Sometimes transaction Ti may have to be aborted. In such a case all the waiting requests made by Ti will be deleted from the linked lists present in the lock table. Once abortion is complete, locks held by Ti will also be released....

Advantages of Locking

Data Consistency: Locking can help ensure data consistency by preventing multiple users from modifying the same data simultaneously. By controlling access to shared resources, locking can help prevent data conflicts and ensure that the database remains in a consistent state. Isolation: Locking can ensure that transactions are executed in isolation from other transactions, preventing interference between transactions and reducing the risk of data inconsistencies. Granularity: Locking can be implemented at different levels of granularity, allowing for more precise control over shared resources. For example, row-level locking can be used to lock individual rows in a table, while table-level locking can be used to lock entire tables. Availability: Locking can help ensure the availability of shared resources by preventing users from monopolizing resources or causing resource starvation....

Disadvantages of Locking

Overhead: Locking requires additional overhead, such as acquiring and releasing locks on shared resources. This overhead can lead to slower performance and increased resource consumption, particularly in systems with high levels of concurrency. Deadlocks: Deadlocks can occur when two or more transactions are waiting for each other to release resources, causing a circular dependency that can prevent any of the transactions from completing. Deadlocks can be difficult to detect and resolve and can result in reduced throughput and increased latency. Reduced Concurrency: Locking can limit the number of users or applications accessing the database simultaneously. This can lead to reduced concurrency and slower performance in systems with high levels of concurrency. Complexity: Implementing locking can be complex, particularly in distributed systems or in systems with complex transactional logic. This complexity can lead to increased development and maintenance costs....

FAQs on Locking

1. What is Locking?...