Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (2024)

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (1)

Article byPriya Pedamkar

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (2)

Introduction to Lock Based Protocols in DBMS

The DBMS houses data that can interact with one another and can be manipulated at any given instant. In a few scenarios, there is a possibility of more than one user trying to access a certain data item at the same time creating a concurrency. Thus, a need arises to deal with the said concurrency to handle the simultaneous execution of tractions among the multiple databases in the picture. One such method is termed as Lock Based Protocols. In this topic, we are going to learn about Lock Based Protocols in DBMS.

Lock Based Protocols eliminate the shortcomings caused by the concurrency access in DBMS by providing the required isolation to the tractions involved within the DBMS.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

This article tends to provide an insight on Lock Based Protocols in DBMS.

What is Lock Based Protocols in DBMS?

Hundreds of transactions happen each moment. Consider booking a movie ticket in your favorite cinemas, chances are two users will try to book the same seat unknowing to one another. A scenario like this, when dealt on a large scale, might affect the database consistency leading to the corruption of data. In order to avoid conflicts w.r.t the user access to read and write into the database, and to maintain consistency throughout the DBMS, each traction must be enforced in isolation. This task is achieved by implementing Lock Based Protocols in DBMS.

Lock based Protocols in simpler terms helps overcome the issues related to accessing the DBMS concurrently by locking the current transaction for only one user. The assumption or more like a requirement that is necessary for implementing Lock Based Protocol is that all the data items involved are accessed in a mutually exclusive manner i.e. when one traction is active by a user, no other traction is allowed access to update or modify that traction at the same time. As the name suggests, the Lock based protocols when in action, are required to acquire a lock to access the data items and release the lock when the said traction is completed.

Types of Locks in DBMS

The locking and unlocking of data items in Lock based Protocols in DBMS are implemented in 2 modes:

  • Shared Lock (lock-S)
  • Exclusive Lock (lock-X)

1. Shared Lock

Often represented as lock-S(), Shared Locks are basically the locks that grant Read-Only access to the data items associated with it. This means when a shared lock is implemented on a database, it can be READ by multiple users, however, none of the users reading the data items will be able to update it. In other words, there is no write access associated with Shared Lock. Since multiple users can read the data items simultaneously, more than one shared lock can be placed on them at a given time but for the shared lock to be placed, the data item must not have any other locks associated with it.

Example of shared Lock:

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (3)

Consider a transaction(T1) which requires only to read the data item value A. The following steps take place when lock protocol is applied to this traction

  1. T2 will acquire an exclusive lock on the data item A
  2. Read the current value of data item A
  3. Once the transaction is completed, the data item will be unlocked

2. Exclusive Lock

While Shared Lock allows Read-Only access, Exclusive Locks allow both Read and Write access on a data item present in the database. Often represented as lock-X(), Exclusive locks provide the privilege of reading and modifying the data as seen fit by a user. For the sake of security and consistency of the database, this process will be exclusive to the user using them and is not permitted to other users trying to access the same data item. Once the exclusive lock is placed, no other locks including the Shared lock can be placed on the same row or column until its unlocked.

Example of Exclusive Lock:

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (4)

Consider a transaction(T2) which requires to update the data item value A. The following steps take place when lock protocol is applied to this traction

  1. T2 will acquire an exclusive lock on the data item A
  2. Read the current value of data item A
  3. Modify the data item as required. In the example illustrated, a value of 50 is subtracted from the data item A
  4. Write the updated value of the data item
  5. Once the transaction is completed, the data item will be unlocked.

Lock Compatibility Matrix

A keynote while applying the Lock based protocols in DBMS is that: any number of tractions can hold a Shared Lock while only one traction has a claim over Exclusive Lock since because shared lock is only reading the data and not performing any other actions whereas the exclusive lock is performing both read and write operations. This can be illustrated using a compatibility matrix like the one shown below:

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (5)

The figure illustrates that when two transactions are involved, and both attempt to only read a given data item, it is permitted and no conflict arises, but when one transaction attempts to write the data item and another one tries to read or write at the same time, conflict occurs resulting in a denied interaction.

Conversion between the locks is possible by the two methods listed below:

Upgrading: conversion from a read lock to write lock

Downgrading: conversion from a write lock to read lock

Problems associated with Simple locking:

  1. Data inconsistency between multiple transactions
  2. Deadlock, a situation where the transactions try to access lock on already locked data items
  3. No guarantee of serializability (i.e. execution of a concurrent transaction equivalent to that of a transaction executed serially)

Two Phase Locking (2PL)

The trivial requirement for a 2PL to exist is that the locking and unlocking of a transaction take place in either of the 2 phases i.e. Growing or Shrinking phase

Growing Phase: It is the phase where new locks can be acquired on the data items.

Shrinking phase: It is the phase where the existing locks on the data items are released.

The above phases in a DBMS are determined by something called a ‘Lock Point’. Lock point is the point where a transaction has achieved its final lock. It is also the point where the growing phase ends and the shrinking phase begins.

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (6)

Types of 2 Phase Locking (PL)

Here are the types of 2 phase locking mention below

1. Conservative 2PL

Conservative or Static 2PL when implied acquires all the locks before a transaction begins and releases the locks once the transaction is committed. This kind of 2 PL helps in overcoming problems related to cascading rollback and deadlocks.

2. Strict 2PL

In this type of 2PL, the exclusive (write) lock is released only after a transaction is committed, whereas a shared (read) lock can be released at regular intervals. Though Strict 2PL helps overcome the cascading rollback issues, it may also cause a bottleneck in some cases.

3. Strong strict or Rigorous 2PL

In this type of 2PL, both shared and exclusive locks are released only when the transaction is ended, i.e. when the transaction is committed or aborted. This kind of 2PL is used in practice today, promotes serializability and is simpler to implement due to the strictness involved w.r.t the implementation of the phase endings.

Conclusion

Concurrency control is essential in DBMS for handling the simultaneous execution of transactions among various databases. Lock Based Protocols being an essential member in the concurrency control technique enforces isolation among the transactions, preserve and maintain the reliability of the database, and resolve the conflicts of read-write and write-read operations. In addition to Lock based Protocols concurrency control can also be achieved via methodologies such as Timestamp Protocol, Mutilversion concurrency Protocol, and Validation Concurrency Protocols.

Recommended Articles

This is a guide to Lock Based Protocols in DBMS. Here we discuss what is Lock Based Protocols in DBMS and its types along with the examples and 2 Phase Locking. You may also look at the following articles to learn more –

  1. Types of DBMS
  2. Hashing in DBMS
  3. Normalization in DBMS
  4. Deadlock in DBMS
  5. Serializability in DBMS | Types with Examples

ADVERTIsem*nT

All in One Excel VBA Bundle 500+ Hours of HD Videos 15 Learning Paths 120+ Courses Verifiable Certificate of Completion Lifetime Access

ADVERTIsem*nT

Financial Analyst Masters Training Program 2000+ Hours of HD Videos 43 Learning Paths 550+ Courses Verifiable Certificate of Completion Lifetime Access

ADVERTIsem*nT

All in One Data Science Bundle 2000+ Hour of HD Videos 80 Learning Paths 400+ Courses Verifiable Certificate of Completion Lifetime Access

ADVERTIsem*nT

All in One Software Development Bundle 5000+ Hours of HD Videos 149 Learning Paths 1050+ Courses Verifiable Certificate of Completion Lifetime Access
Primary Sidebar

");jQuery('.cal-tbl table').unwrap("

");jQuery("#mobilenav").parent("p").css("margin","0");jQuery("#mobilenav .fa-bars").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").addClass("showfix-bar");/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-close fa fa-bars');});jQuery("#mobilenav .fa-close").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").removeClass("showfix-bar");jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-bars fa fa-close');/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/});});

Lock Based Protocols in Database Management Systems (DBMS) play a pivotal role in ensuring data integrity and consistency in concurrent access scenarios. These protocols mitigate issues arising from simultaneous access to data items by multiple users, thereby maintaining the reliability of the database.

Understanding Lock Based Protocols involves delving into concepts like concurrency control, isolation, and different types of locks used to regulate access. Here's an analysis of the concepts covered in the provided article:

1. Concurrency in DBMS

  • Challenge: When multiple users access the same data concurrently, it might lead to inconsistencies and data corruption.
  • Solution: Concurrency control techniques like Lock Based Protocols help manage simultaneous transactions.

2. Lock Based Protocols

  • Purpose: Ensure isolation among transactions to maintain database consistency.
  • Methods: Employ locks to restrict access to data items during transactions.
  • Lock Types: Shared Lock (lock-S) and Exclusive Lock (lock-X).

3. Shared Lock

  • Functionality: Allows multiple users to read data simultaneously but restricts write access.
  • Example: Transaction T1 acquiring a shared lock for reading data item A.

4. Exclusive Lock

  • Functionality: Grants both read and write access, exclusive to the user acquiring the lock.
  • Example: Transaction T2 acquiring an exclusive lock to update data item A.

5. Lock Compatibility

  • Matrix: Illustrates compatibility between read and write operations to prevent conflicts.

6. Problems and Solutions

  • Issues: Data inconsistency, deadlocks, lack of serializability.
  • Solutions: Two Phase Locking (2PL) technique.

7. Two Phase Locking (2PL)

  • Phases: Growing Phase (acquiring locks) and Shrinking Phase (releasing locks).
  • Types: Conservative 2PL, Strict 2PL, Strong strict or Rigorous 2PL.

8. Conclusion

  • Importance: Lock Based Protocols ensure transaction isolation, database reliability, and resolve read-write conflicts.

Other Concurrency Control Techniques

  • Mentioned in the article: Timestamp Protocol, Multiversion Concurrency Protocol, Validation Concurrency Protocols.

Understanding Lock Based Protocols involves comprehending the nuances of locking mechanisms, compatibility, and their impact on transaction execution within a DBMS. These protocols ensure data integrity by regulating concurrent access and play a significant role in database management and optimization.

Lock Based Protocols in DBMS | Learn the Types of Locks in DBMS (2024)
Top Articles
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 5812

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.