5.5 Locking
Locking
Locking: A solution to problems arising due to concurrency.
Locking of records can be used as a concurrency control technique to prevent the above mentioned problems. A transaction acquires a lock on a record if it does not want the record values to be changed by some other transaction during a period of time. The transaction releases the lock after this time.
Locks are of two types
- shared (S lock)
- and exclusive (X Lock).
- A transaction acquires a shared (read) lock on a record when it wishes to retrieve or fetch the record.
- An exclusive (write) lock is acquired on a record when a transaction wishes to update the record. (Here update means INSERT, UPDATE or DELETE.)
The following figure shows the Lock Compatibility matrix.
Normally, locks are implicit. A FETCH request is an implicit request for a shared lock whereas an UPDATE request is an implicit request for an exclusive lock.
Explicit lock requests need to be issued if a different kind of lock is required during an operation. For example, if an X lock is to acquired before a FETCH it has to be explicitly requested for.
Leave a Comment