
Programmers know how important the database management system is as it provides a digital memory space to save data. Shortly known as DBMS, it helps the users to access, modify and save data without any problems. The best part is, DBMS isn’t just limited to simple data, but it also is used to store crucial and highly confidential data.
Say, we need to store and protect bank details in a DBMS, we can easily do so by employing certain approaches. One approach that gets widely used is the 2 phase locking protocol in DBMS as it employs three-part locks. Let us learn more about it below for a clearer understanding.
Lock-based protocol
Lock-based protocols help in saving transactions from being read and written without proper access. There are usually, two types of lock that gets employed and they are,
Shared lock: Shared lock which is also known as read-only lock ensures that the transaction alone can read the date time. When the transaction has a lock, it cannot update the data item at all.
Exclusive lock: In this lock, the transaction can read and write the data time. The lock ensures that many transactions cannot read and write simultaneously.
What are the types of lock protocols?
Lock protocols aren’t complicated nor simple to comprehend. It comes in various shapes and sizes, each serving its purpose perfectly. Below, we’ve listed the types of lock protocols which can be used to save important transactions or data.
Simplistic
When a transaction is going on, one cannot insert, delete or update the data item until the transaction is fully done. This is made possible by the simplistic lock on the transaction.
Pre-claiming
When the pre-claiming lock is applied, it first checks the transaction and its data that needs the lock. Before execution, all the data is locked and then only the transaction is permitted to execute. Once the transaction is done, the data items are unlocked. Unless and until the data items get locked, the transaction never runs.
Two phase
Two phase or 2 phase locking protocol in DBMS separates the translation execution period into three parts and applies the lock.
We will further study about this type once we look into DBMS concurrency control.
Strict two-phase
The strict two phase is a subtype of two phase, as it also divides the transaction execution into three parts and locks it. The unique feature is that there isn’t a shrinking phase in the strict-two phase locking protocol unlike the two-phase locking protocol, which we will thoroughly study below.
Note: While these above-mentioned lock protocols help in securing crucial data, there is another approach called the DBMS in data abstraction which can be employed to hide unnecessary data or data which you want to keep private.
Concurrency control
Concurrency control in DBMS is a method of managing transaction operations simultaneously without clashing with each other. It ensures that the transactions are concurrently done, produce good results and do not violate the data.
When it comes to concurrency control it employs
Shared and exclusive locks
Two phase locking protocol
Time-stamp-based protocols
Validation-Based protocols
The most commonly used protocol is the Two-phase locking protocol. Let us briefly learn about it.
What exactly is the 2 phase locking protocol in DBMS?
The 2 phase locking protocol also known as 2PL comes under concurrency control and it locks the current transaction data and blocks other transactions that try to access the data item of a current transaction. The protocol divides the transaction execution point into three and locks it. The three parts are,
First part: Transaction seeks permission for the locks it requires before execution
Second part: All the locks that are needed are granted. Then when the first lock gets released, the transaction enters the third part.
Third part: No new locks can be demanded henceforth and so the obtained locks get unlocked one by one.
The two phases that get followed are,
1. Growing: A new lock can be obtained for a data item by the transaction but no locks can be unlocked.
2. Shrinking: No new locks can be obtained but the previously acquired locks can be released by the transaction.
What is a lock point?
A lock point is the place where the growing phase ends. In simple words, the lock point is where the transaction acquires its last required lock.
Here is an example to understand it,
Consider the growing phase as 1, 2, 3, 4, 5. Then the shrinking phase could be, 6, 7, 8, 9, 10. In this two phases, the lock point would be number 5 as it breaks the sequence.
Types of 2 phase locking protocol in DBMS
The 2 Phase locking protocol is further divided into types that might sound similar but does have its distinct features.
Strict 2PL
As we previously saw, strict 2PL is similar to 2PL. The shared lock can be released after the point of the lock whereas the exclusive lock can be released only after the transaction is done. In the strict method, when one transaction comes back then other transactions must also do the same as they are dependent. This process is known as cascading schedule.
Rigorous 2PL
In this method, both the shared and exclusive locks cannot be released. Additionally, this method guarantees serializability but doesn’t guarantee deadlock.
Conservative two-phase locking protocol
In this method, every data must first be locked for the execution of the transaction to begin. If the data (any) aren’t there for locking, then no items will get locked before the execution. Moreover, in this method the both write & read items must know when the transaction begins. Additionally, this method is free of deadlock and it also doesn’t make sure of a strict program.
Conclusion
With locking protocols, many transactions and its data get to be saved and secured from illegal data entries that get made. We hope you have understood how the 2 phase locking protocol in DBMS processes with its sub types and other important terms necessary for understanding DBMS locking protocols.
Comments