The Wayback Machine - https://web.archive.org/web/20241123042705/https://www.geeksforgeeks.org/multiple-granularity-locking-in-dbms/
Open In App

Multiple Granularity Locking in DBMS

Last Updated : 23 Nov, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The various Concurrency Control schemes have used different methods and every individual Data item is the unit on which synchronization is performed. A certain drawback of this technique is if a transaction Ti needs to access the entire database, and a locking protocol is used, then Ti must lock each item in the database. It is less efficient, it would be simpler if Ti could use a single lock to lock the entire database. But, if it considers the second proposal, this should not in fact overlook certain flaws in the proposed method. Suppose another transaction just needs to access a few data items from a database, so locking the entire database seems to be unnecessary moreover it may cost us a loss of Concurrency, which was our primary goal in the first place. To bargain between Efficiency and Concurrency. Use Granularity. 

Let’s start by understanding what is meant by Granularity. 

Granularity

It is the size of the data item allowed to lock. Now Multiple Granularity means hierarchically breaking up the database into blocks that can be locked and can be tracked what needs to lock and in what fashion. Such a hierarchy can be represented graphically as a tree. 
For example, consider the tree, which consists of four levels of nodes. The highest level represents the entire database. Below it is nodes of type area; the database consists of exactly these areas. The area has children nodes which are called files. Every area has those files that are its child nodes. No file can span more than one area. 

Finally, each file has child nodes called records. As before, the file consists of exactly those records that are its child nodes, and no record can be present in more than one file. Hence, the levels starting from the top level are: 

  • database
  • area
  • file
  • record
    Multi Granularity Tree

    Multi Granularity tree Hiererchy

Consider the above diagram for the example given, each node in the tree can be locked individually. As in the 2-phase locking protocol, it shall use shared and exclusive lock modes. When a transaction locks a node, in either shared or exclusive mode, the transaction also implicitly locks all the descendants of that node in the same lock mode. For example, if transaction Ti gets an explicit lock on file Fc in exclusive mode, then it has an implicit lock in exclusive mode on all the records belonging to that file. It does not need to lock the individual records of Fc explicitly. this is the main difference between Tree-Based Locking and Hierarchical locking for multiple granularities. 

Now, with locks on files and records made simple, how does the system determine if the root node can be locked? One possibility is for it to search the entire tree but the solution nullifies the whole purpose of the multiple-granularity locking scheme. A more efficient way to gain this knowledge is to introduce a new lock mode, called Intention lock mode. 

Intention Mode Lock

In addition to S and X lock modes, there are three additional lock modes with multiple granularities: 

  • Intention-Shared (IS): explicit locking at a lower level of the tree but only with shared locks.
  • Intention-Exclusive (IX): explicit locking at a lower level with exclusive or shared locks.
  • Shared & Intention-Exclusive (SIX): the subtree rooted by that node is locked explicitly in shared mode and explicit locking is being done at a lower level with exclusive mode locks.

The compatibility matrix for these lock modes are described below: 

Multi Granularity Tree hierarchy

Multi Granularity tree Hierarchy

The multiple-granularity locking protocol uses the intention lock modes to ensure serializability. It requires that a transaction Ti that attempts to lock a node must follow these protocols: 

  • Transaction Ti must follow the lock-compatibility matrix.
  • Transaction Ti must lock the root of the tree first, and it can lock it in any mode.
  • Transaction Ti can lock a node in S or IS mode only if Ti currently has the parent of the node-locked in either IX or IS mode.
  • Transaction Ti can lock a node in X, SIX, or IX mode only if Ti currently has the parent of the node-locked in either IX or SIX modes.
  • Transaction Ti can lock a node only if Ti has not previously unlocked any node (i.e., Ti is two-phase).
  • Transaction Ti can unlock a node only if Ti currently has none of the children of the node-locked.

Observe that the multiple-granularity protocol requires that locks be acquired in top-down (root-to-leaf) order, whereas locks must be released in bottom-up (leaf to-root) order. 
As an illustration of the protocol, consider the tree given above and the transactions: 

  • Say transaction T1 reads record Ra2 in file Fa. Then, T1 needs to lock the database, area A1, and Fa in IS mode (and in that order), and finally to lock Ra2 in S mode.
  • Say transaction T2 modifies record Ra9 in file Fa . Then, T2 needs to lock the database, area A1, and file Fa (and in that order) in IX mode, and at last to lock Ra9 in X mode.
  • Say transaction T3 reads all the records in file Fa. Then, T3 needs to lock the database and area A1 (and in that order) in IS mode, and at last to lock Fa in S mode.
  • Say transaction T4 reads the entire database. It can do so after locking the database in S mode.

Note that transactions T1, T3, and T4 can access the database concurrently. Transaction T2 can execute concurrently with T1, but not with either T3 or T4. 
This protocol enhances concurrency and reduces lock overhead. Deadlock is still possible in the multiple-granularity protocol, as it is in the two-phase locking protocol. These can be eliminated by using certain deadlock elimination techniques.

Conclusion

  • Database objects can be locked by transactions at various granularities using MGL, ranging from individual data points to whole tables or databases.
  • Because multiple granularity locking shortens the time that transactions must wait for locks to be released, it can increase concurrency.
  • When compared to other concurrency control algorithms, such two-phase locking (2PL), MGL can be more difficult to implement and maintain.


Previous Article
Next Article

Similar Reads

Implementation of Locking in DBMS
Locking protocols are used in database management systems as a means of concurrency control. Multiple transactions may request a lock on a data item simultaneously. Hence, we require a mechanism to manage the locking requests made by transactions. Such a mechanism is called a Lock Manager. It relies on the process of message passing where transacti
5 min read
Levels of Locking in DBMS
The locking in a database can be done at 4 levels, which start with the database at the highest level and down via table and page to the row at the lowest level. Database LevelTable LevelPage-LevelRow Level Before we discuss the levels of locking, we should know about the types of locks or lock mode. So, there are 5 locks types in the locking and t
6 min read
Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3
Prerequisite - Basics of Two-Phase Locking protocol(2-PL), Types of 2-PL. Now, we know both Strict 2-PL and Rigorous 2-PL avoids Cascading Rollbacks and ensures a Strict schedule but still cannot guarantee that our schedule is Deadlock free. We have seen both Strict and Rigorous 2-PL are similar in application and a general misconception is common
3 min read
Predicate Locking
A lock, in DBMS, is a variable that is associated with a data item. Locks in DBMS help synchronize access to the database items by concurrent transactions. Lock Based Protocol in DBMS is used to eliminate concurrency problems for simultaneous transactions, (this refers to a situation wherein one transaction results in changing the results of anothe
3 min read
MOSS Concurrency Control Protocol (Distributed Locking in Database)
This is a protocol which is used to control the concurrency in the Distributed database environment, Here we'll read about the rules and regulations that are required to keep in mind while applying MOSS Concurrency Control Protocol. MOSS Concurrency Control Protocol:- a) It is mainly used for handling the nested(hierarchical) transactions which are
2 min read
Two Phase Locking Protocol
Pre-Requisite: Concurrency Control Protocol, Lock-based Protocol.  Now, recalling where we last left off, there are two types of Locks available Shared S(a) and Exclusive X(a). Implementing this lock system without any restrictions gives us the Simple Lock-based protocol (or Binary Locking), but it has its own disadvantages, they do not guarantee S
4 min read
Categories of Two Phase Locking (Strict, Rigorous & Conservative)
Now that we are familiar with what is Two-Phase Locking (2-PL) and the basic rules which should be followed which ensures serializability. Moreover, we came across problems with 2-PL, Cascading Aborts, and Deadlocks. Now, we turn towards the enhancements made on 2-PL which try to make the protocol nearly error-free. Briefly, we allow some modificat
4 min read
Thomas Write Rule in DBMS
The "write rule" in database management systems (DBMS) refers to a principle that governs how changes to the database are handled. Specifically, the write rule states that any modification to a database must be written to disk before control is returned to the user. In other words, when a user executes a command that modifies the database (such as
5 min read
Armstrong's Axioms in Functional Dependency in DBMS
Prerequisite - Functional Dependencies This article contains Armstrong's Axioms and how Armstrong's Axioms are used to decide about the functional dependency on the database. We will be also learning about the Secondary Rules and Armstrong Relations. We will learn each thing in detail. Before moving ahead, you must have a knowledge of Functional De
4 min read
Database Objects in DBMS
A database object is any defined object in a database that is used to store or reference data.Anything which we make from create command is known as Database Object.It can be used to hold and manipulate the data.Some of the examples of database objects are : view, sequence, indexes, etc. Table - Basic unit of storage; composed rows and columns View
4 min read
Starvation in DBMS
Starvation or Livelock is the situation when a transaction has to wait for an indefinite period of time to acquire a lock. Reasons for Starvation:If the waiting scheme for locked items is unfair. ( priority queue )Victim selection (the same transaction is selected as a victim repeatedly )Resource leak.Via denial-of-service attack.Starvation can be
5 min read
Graph Based Concurrency Control Protocol in DBMS
Graph-based concurrency control protocols are used in database management systems (DBMS) to ensure that concurrent transactions do not interfere with each other and maintain the consistency of the database. In graph-based concurrency control, transactions are represented as nodes in a graph, and the conflicts between transactions are represented as
4 min read
Introduction to TimeStamp and Deadlock Prevention Schemes in DBMS
Deadlock occurs when each transaction T in a schedule of two or more transactions waiting for some item locked by some other transaction T' in the set. Thus, both end up in a deadlock situation, waiting for the other to release the lock on the item. Deadlocks are a common problem and we have introduced the problem while solving the Concurrency Cont
7 min read
Tuple Relational Calculus (TRC) in DBMS
Tuple Relational Calculus (TRC) is a non-procedural query language used in relational database management systems (RDBMS) to retrieve data from tables. TRC is based on the concept of tuples, which are ordered sets of attribute values that represent a single row or record in a database table. TRC is a declarative language, meaning that it specifies
4 min read
Fragmentation in Distributed DBMS
Fragmentation is a process of dividing the whole or full database into various subtables or sub relations so that data can be stored in different systems. The small pieces or sub relations or subtables are called fragments. These fragments are called logical data units and are stored at various sites. It must be made sure that the fragments are suc
5 min read
Challenges of database security in DBMS
Seeing the vast increase in volume and speed of threats to databases and many information assets, research efforts need to be consider to the following issues such as data quality, intellectual property rights, and database survivability. Let's discuss them one by one. 1. Data quality - The database community basically needs techniques and some org
5 min read
Schema Integration in DBMS
Definition: Schema integration is used to merge two or more database schemas into a single schema that can store data from both the original databases. For large databases with many expected users and applications, the integration approach of designing individual schema and then merging them can be used. Because the individual views can be kept rel
5 min read
Domain Key Normal Form in DBMS
Prerequisites - Normal Forms, 4th and 5th Normal form, find the highest normal form of a relation It is basically a process in database to organize data efficiently. Basically there are two goals of doing normalization these are as follows: To remove repeated data or in simple words we can say to remove redundant data.Second one is to ensure that t
4 min read
Interfaces in DBMS
A database management system (DBMS) interface is a user interface that allows for the ability to input queries to a database without using the query language itself. User-friendly interfaces provided by DBMS may include the following: Menu-Based InterfacesForms-Based InterfacesGraphical User InterfacesNatural Language InterfacesSpeech Input and Out
4 min read
Why recovery is needed in DBMS
Basically, whenever a transaction is submitted to a DBMS for execution, the operating system is responsible for making sure or to be confirmed that all the operations which need to be performed in the transaction have been completed successfully and their effect is either recorded in the database or the transaction doesn't affect the database or an
6 min read
Economic factors (Choice of DBMS)
Basically, the choice of a DBMS is governed by a number of factors such as: Technical Economics Politics of Organization Here we will basically discuss Non-technical factors which include the financial status and the support organization of the vendor. In this article, we will concentrate on discussing the economic and organizational factors that a
2 min read
Categories of End Users in DBMS
Pre-Requisite: Different Types of End Users End users are basically those people whose jobs require access to the database for querying, updating, and generating reports. The database primarily exists for their use. There are several categories of end-users these are as follows. Casual End usersNaive or Parametric End UsersApplication ProgrammersSo
3 min read
Semantic Heterogeneity in DBMS
Semantic Heterogeneity basically occurs when schema or data set for same domain is developed by independent parties which leads to differences in meaning, interpretation and intended use of the same or related data. Semantic Heterogeneity among components database system basically creates the biggest hurdle in designing global schemas of the hetero
4 min read
Impedance Mismatch in DBMS
Impedance mismatch is a term used in computer science to describe the problem that arises when two systems or components that are supposed to work together have different data models, structures, or interfaces that make communication difficult or inefficient. In the context of databases, impedance mismatch refers to the discrepancy between the obje
4 min read
Network attached storage in DBMS
With the phenomenal growth in digital data, particularly generated from multi-media and other enterprise application the need for high-performance storage solution at low cost has become extremely important. Network Attached Storage (NAS) devices are basically among the latest of storage devices being used for this purpose. These devices are in fac
4 min read
Use of DBMS in System Software
Here we are going to discuss about how a user interacts with a DBMS, and how the DBMS is related to system software. Using a general-purpose programming language, user can write a source program in the normal way. However, instead of writing I/O statements of the form provided by the programming language, the programmer writes commands in a data ma
5 min read
OLAP Operations in DBMS
OLAP stands for Online Analytical Processing Server. It is a software technology that allows users to analyze information from multiple database systems at the same time. It is based on multidimensional data model and allows the user to query on multi-dimensional data (eg. Delhi -> 2018 -> Sales data). OLAP databases are divided into one or m
2 min read
Building a Data Warehouse in DBMS
A Data warehouse is a heterogeneous collection of different data sources organized under unified schema. Builders should take a broad view of the anticipated use of the warehouse while constructing a data warehouse. During the design phase, there is no way to anticipate all possible queries or analyses. Some characteristic of Data warehouse are: Su
5 min read
On Line Transaction Processing (OLTP) System in DBMS
On-Line Transaction Processing (OLTP) System refers to the system that manage transaction oriented applications. These systems are designed to support on-line transaction and process query quickly on the Internet. For example: POS (point of sale) system of any supermarket is a OLTP System. Every industry in today's world use OLTP system to record t
3 min read
Validation Based Protocol in DBMS
Validation Based Protocol is also called Optimistic Concurrency Control Technique. This protocol is used in DBMS (Database Management System) for avoiding concurrency in transactions. It is called optimistic because of the assumption it makes, i.e. very less interference occurs, therefore, there is no need for checking while the transaction is exec
5 min read
three90RightbarBannerImg