Implementation of Locking in database

A lock manager used to maintain lock request and lock response. The lock manager reply message when lock grant or not grant. Lock manager reply two kind of message such as a transaction locked message and  unlocked message. The lock manager maintains a data structure called a lock table to record granted locks and pending requests. In this data structure the data item maintains a linked list of records. Each record of the linked list for a data item notes which transaction made the request, what lock mode it requested. The lock table uses hash table indexed on the name of the data item being locked.
lock_table
This picture shows an example of a lock table. This table contains locks for five different data items 14, 17, 123, 144, and 1912. Black rectangles indicate granted locks, white ones indicate waiting requests. The lock manager processes requests in two way first one is lock request and second one is unlock request:

1. Lock request: When first lock request message arrives, the lock manager create a new link list to record the lock request for the data item. If the linked list for the data item already exists, it adds to the end of the linked list for the data item. Note that the new lock request will be granted only if the lock request is compatible with all earlier locks.
2. Unlock request: When unlock request for a data item arrives, the lock manager delete the records from the linked list for that data item. Later requests are checked to see if they can now be granted or not. If the transaction aborts the lock manager deleted all waiting or granted request and update the records in the lock table.

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP