Loading, please wait...

Locking Methods of Concurrency Control

"A lock is a variable that is used to control the access of the data item."
Locking is the mostly used in the concurrency control. Lock is used when multiple users need to access a database concurrently. This protect data from being corrupted when multiple users try to read while others write to the database.

 

 Locks are divided into three fields:

  1. Lock Granularity
  2. Lock Types
  3. Deadlocks

Lock Granularity-: The size of the data item chosen as the unit of protection by a concurrency control program is called GRANULARITY and it also indicates the level of lock use.

Locking can take place at following table.

Ø Database level.

Ø Table level.

Ø Page level.

Ø Row (Tuple) level.

Ø Attributes (fields) level.

 

Database level-: In this entire database is locked

Table level-: Entire table is locked.

Page level-: Entire disk page is locked.

Row (Tuple) level-: Allow concurrent transaction to access different rows of same table. Even if rows are located on the same page.

Attributes (fields) level-: Allow concurrent transaction to access same rows. As long as they require use of different field (attributes) within that row.

 

Lock Types-: The DBMS mainly uses following types of locking techniques.

  1. Binary Locking
  2. Shared / Exclusive Locking
  3. Two - Phase Locking (2PL)

Binary Locking-: It have only two states

  1. Locked
  2. Unlocked

Shared Locking -: These locks are known as read locks, and it is denoted by 'S'. Concurrent transaction are granted read access on the basis of a common lock.

Exclusive Locking-: Access is specifically reserved for transaction that locked object. These locks are referred as Write locks, and denoted by 'X'.

Two - Phase Locking (2PL)-: It define how transaction acquire and relinquish locks. It ensure serializability but it does not prevent deadlocks.

Growing phase-: Transaction acquires all required locks without unlocking any data.

Shrinking phase-: Transaction release all the locks and cannot obtain any new lock.

 

Deadlocks-: It is the condition where two transactions are waiting for each other to unlock data.

Controlling of Deadlock.

Ø Avoidance

Ø Prevention