Different concurrency control protocols in Database management include
- Lock-Based Protocols-
It is a mechanism in which a transaction cannot read or write data unless the appropriate lock is acquired. This helps in eliminating the concurrency problem by locking a particular transaction to a particular user. The lock is a variable that denotes those operations that can be executed on the particular data item.
The various types of lock include
- Binary lock– It ensures that the data item can be in either locked or unlocked state
- Shared Lock– A shared lock is also called read only lock because you don’t have permission to update data on the data item. With this lock data item can be easily shared between different transactions. For example, if two teams are working on employee payment accounts, they would be able to access it but wouldn’t be able to modify the data on the payment account.
- Exclusive Lock– With exclusive locks, the data items will not be just read but can also be written
- Simplistic Lock Protocol– this lock protocol allows transactions to get lock on every object at the start of operation. Transactions are able to unlock the data item after completing the write operations
- Pre-claiming locking– This protocol evaluates the operations and builds a list of the necessary data items which are required to initiate the execution of the transaction. As soon as the locks are acquired, the execution of transaction takes place. When the operations are over, then all the locks release.
- Starvation- It is the condition where a transaction has to wait for an indefinite period for acquiring a lock.
- Deadlock- It is the condition when two or more processes are waiting for each other to get a resource released
Lock Compatibility Matrix
- A transaction can be granted lock on a data item if the requested lock is found compatible with the locks on the data item from other transactions
- Multiple number of transactions can have shared locks on any data item. In case any transaction holds exclusive lock on the data item, no other transactions can hold lock on it
- All incompatible locks by other transactions must be released and the requested transaction has to wait if a lock is not granted