×

Concurrency Control Protocols

Concurrency Control Protocols

Concurrency control protocols ensure the atomicity, serializability and isolation of the concurrent transactions. The Concurrency control protocols can be broadly classified into the following categories:

  1. Lock Based Protocol
  2. Timestamp protocol

Lock Based Protocol

In this protocol, any transaction in the database cannot read or write any data item until it acquires an appropriate lock on it. This means that in the database, any transaction cannot retrieve, insert, delete, or update the data until it gets access to that specific data item. Any transaction proceeds only when the lock request is granted.  Following are there two different types of protocol:

  1. Shared Lock
  2. Exclusive lock

Shared Lock(S)

This type of lock is also called a read-only lock. With the shared lock, the data item can only be read by the transaction. In the shared lock, the data item can be shared between the transactions because when a transaction holds this type of lock, then it cannot update the data item.

If a transaction Ti has obtained a shared lock which is denoted by S on an item Q, then Ti transaction can read, but cannot write, Q.

For example: When two transactions are reading the account balance of a person. Then, the database will let them read by placing the shared lock. But at the same time, if another transaction wants to update the account balance by placing, the shared lock does not allow it until the reading process is finished.

Exclusive Lock(X)

In this type of lock, a data item can be read as well as written by the transaction. Once this lock is placed on the data item, no other lock (either shared or Exclusive) can be placed on that data item until Exclusive lock is released. This lock is exclusive, and in this lock, multiple transactions in the database do not modify the same data item simultaneously.

If a transaction Ti has obtained an exclusive lock which is denoted by X on an item Q, then Ti transaction can both read and write Q.

For example: when a transaction wants to update the account balance of a person, then in database let it does by placing the X-lock on it. But if a second transaction wants to read the data, the shared lock does not allow it. And if another transaction wants to write the data, the exclusive lock doesn’t allow that.

Lock Compatibility Matrix

  S X
S True False
X False False

There are four types of lock protocol available:

1. Simplistic lock protocol

This is the simplest way of locking the data items during transactions. This protocol allows all transactions to get the lock (shared or exclusive) on the data before insert, delete, or update operations performed on it. And this protocol will unlock the data item after completing the operations in the transaction.

2. Pre-claiming Lock protocol

This protocol evaluates those transactions which contain the data items that need to be locked. Before the transaction begins its execution, this protocol requests DBMS for all locks on all the data items.
When all the locks are granted, then it allow the transaction to start its execution and release all the locks when it is completed. If all the locks are not assigned to all the data items, then this protocol rolls back the transaction and wait until the locks are granted.

3. Two-Phase Locking Protocol (2PL)

This type of locking protocol (2PL) divides the execution phase of the transaction into three parts.
In the first part, when the transaction starts its execution, it seeks permission for the locks it requires. In the second part, any transaction in the database acquire all the locks. As soon as a transaction in database releases its first lock, the third phase starts. In this part, a transaction cannot demand any new lock, and here it only released all the acquired locks.

  1. The two-phase locking protocol consists of two phases:
  2. a) Growing Phase: The phase where the transaction acquires all the locks on the data items, but none can be released known as a growing phase.
  3. Shrinking Phase:  The phase where the existing locks held by the transaction may be released, but no new lock on the data item can be acquired. This type of phase is known as the shrinking phase.

Note: Lock Point: The point in a schedule where the transaction has obtained its final lock (end of growing phase) is called a lock point.

Note: If the conversion of lock is allowed, then in growing phase upgrading of a lock (from S(a) to X(a)) is allowed. And in shrinking phase downgrading of a lock (from X(a) to S(a)) must be done.

Example:

Time Transaction T1 Transaction T2
t1 Lock-X(B) Lock-S(A)
t2 Read(B) Read(A)
t3 B=B-50 Lock-S(B)
t4 Write(B) Read(B)
t5 Lock-X(B) unlock(A)
t6 Lock-X(A) unlock(B)
t7 Read(A)  
t8 A=A-50  
t9 Write(A)  
t10 unlock(B)  
t11 unlock(A)  

4. Strict two-phase locking protocol 

The first phase of this protocol is similar to the two-phase locking protocol (2PL). In the first phase of this protocol, when the transaction acquired all the locks, it continues to execute normally. 

The only difference between the two-phase locking protocol and strict two-phase locking protocol is that this protocol does not have a shrinking phase for releasing the locks. It waits till the whole transaction to finish and commit, and then it releases all the lock held by the transaction at a time. 

Timestamp Based Protocol

The Timestamp-based protocol is the most commonly used concurrency control protocol and is used to order the execution of the concurrent transaction based on their Timestamp. This protocol uses the logical counter or system time to determine the timestamp of the transaction. It also maintains the timestamp of last ‘read’ and ‘write’ operations on the data.

The lock-based protocol acquires locks at the time of execution. But in this protocol, as soon as the transaction is created, it assigns the order of the concurrent transactions. The priority of an older transaction is higher; that’s why it starts its execution first.

Let's suppose there are two transactions T1 and T2. Suppose the T1 transaction has entered the system at 005 times and transaction T2 has entered the system at 008 times. T1 transaction has the higher priority that’s why it executes first as it is entered the system first.

Two types of Timestamp:

1. W_Timestamp(X): This represents the largest timestamp of any transaction that executes write(X) successfully.

2. R_Timestamp(X): This represents the largest timestamp of any transaction that executes Read(X) successfully.

Timestamp ordering protocol  

The timestamp ordering protocol ensures that any conflicting read and write operation are executed in timestamp order.

Following are the two cases which describe the work of basic timestamp ordering protocol:

1. Suppose a transaction Ti read an item (X), check the following condition:

  • If Timestamp(Ti) < W_Timestamp(X), then the read operation is rejected and Ti is rolled back.
  • If Timestamp(Ti) > W_Timestamp(X), then the operation is executed.

2. Suppose a transaction Ti write an item (X), check the following condition:

  • If Timestamp(Ti) < R_Timestamp(X) then the operation is rejected.
  • If Timestamp(Ti) < W_Timestamp(X) then the write operation is rejected and Ti transaction is rolled back otherwise, other operations are executed.  

Related Topics

What is RDBMS?

To discuss the Relational Database Management System, there are some terms and concepts you need to know. Database Any collection of related information is called a database. The phone book is...

5 minutes read.

Characteristics of DBMS

Introduction to DBMS: A database management system (DBMS) is a software application that is designed to manage and organize data stored in a database. It is responsible for storing, retrieving, and...

3 minutes read.

Multivalued Dependency

Multivalued Dependency exists in a relation when two attributes depend on the third attribute but independent to each other. It is a full constraint between two sets of attributes in a relation. It...

2 minutes read.

Advantages of Database Management System in DBMS

A database management system (DBMS) is a software tool that provides an interface for managing data stored in a database. Some advantages of using a DBMS include: data integration, data...

3 minutes read.

Specialization in DBMS

Specialization in DBMS In the database management system, specialization breaks the higher-level entity into two or more than two lower entities. The main motive of this concept is to share the...

2 minutes read.

Components of an ER Diagram

An ER Diagram consists of the following components: Entity AttributesRelationships 1. Entity An entity may be an object, place, person, or an event which stores data in the database. In an entity-relationship diagram, an entity...

4 minutes read.

Meta Data in DBMS

Metadata: Metadata is simply described as information about information. It indicates that the data is described as well as its context. It makes data easier to find, interpret, and organize. I'll...

4 minutes read.

Concurrency Control Protocols

Concurrency Control Protocols Concurrency control protocols ensure the atomicity, serializability and isolation of the concurrent transactions. The Concurrency control protocols can be broadly classified into the following categories: Lock Based ProtocolTimestamp protocol Lock Based Protocol In this protocol,...

5 minutes read.

ER Diagram for University Database in DBMS

What is an ER diagram? ER diagram, short for Entity Relationship Diagram, also known as ERD, is a diagram that shows the relationships of a set of entities stored in a...

9 minutes read.

DBMS Generalization, Specialization, and Aggregation

DBMS Generalization Generalization is a bottom-up approach in which the common attributes of two or more lower-level entities combines to form a new higher-level entity. In generalization, the generalized entity of higher level can also...

3 minutes read.

Fragmentation in Distributed DBMS

Fragmentation is a course of isolating the entire or full information base into different sub tables or sub relations with the goal that information can be put away in various...

4 minutes read.

DBMS Schema

Schema It is a physical representation of data that appears in the database management system. In simple words, a schema is the structure of any database.It defines how the data is stored...

2 minutes read.

ER Model: Entity Relationship Diagram (ERD) with Examples

ER model stands for Entity-Relationship Model. It is a high-level data model diagram which defines the conceptual view of the database. It is a blueprint or design of a database that will...

2 minutes read.

What is Transaction in DBMS

A transaction is a collection of logically related operations which reads and possibly updates the various data items in the database. Usually, a transaction is initiated by a user program written in high-level...

3 minutes read.

Normalization in DBMS: 1NF, 2NF, 3NF, BCNF & 4NF with Examples

Normalization is a technique of organizing the data in the database. It is a systematic approach which is used to remove or reduce data redundancy in the tables and remove the...

7 minutes read.

Advantages of B-Tree in DBMS

A self-balancing search tree is the B-Tree. It is assumed that everything is in the main memory in most other self-balancing search trees (such as AVL and Red-Black Trees). We must...

3 minutes read.

What is Advanced Database Management System

Before diving into the Advance Database management system, we need to learn about the database management system and its usage. Database management system Database Management System or DBMS in short implies the...

3 minutes read.

DBMS Architecture

This is the first step when creating a database management system. The architecture of a database management system plays an important role in determining the actual design and layout of...

4 minutes read.

Difference between DBMS and RDBMS

Database Management System A DBMS is system software which is used to store and manage the data in the database. It was introduced in 1960 for storing the data or information. This system allows...

3 minutes read.

ER Diagram for School Management System in DBMS

What is ER Diagram? An ERD, or entity relationship diagram, is a diagram that depicts the connections between a group of entities contained in a database. In other words, ER diagrams...

6 minutes read.