What is Strict 2 phase locking?
Strict Two-Phase Locking (Strict 2PL) is a rule used in databases to keep information safe when many people are using it at the same time. It works in two main steps:
- Locking Phase: In this part, the system puts locks on the data that a transaction wants to use. The locks can be for reading or writing data. This step makes sure that no one else can change the data while the first transaction is still working on it.
- Unlocking Phase: This is when the system removes the locks, but only after the transaction is completely done, including saving any changes. This ensures that the data stays correct and safe.
The strict part means that all write locks (locks put on data that was changed) stay until the transaction is fully done and all the changes are saved. This rule helps prevent problems like data getting messed up or lost when two people try to change it at the same time.
Some silent features of strict two-phase locking
- Locking Phase: First, it locks the data before using it. This is like calling dibs on a game before playing.
- Unlocking Phase: After using the data, it unlocks it. This lets others take their turn.
- No Unlocking Early: It waits to unlock everything at once, at the end. This stops confusion and keeps data safe.
- Prevents Deadlocks: By locking and unlocking in order, it avoids deadlocks, where no one can move forward.
- Ensures Consistency: It makes sure data stays correct, even when many people are using the database.
Concept of Cascading Rollback
Cascading rollbacks happen when one transaction has to be undone, causing other transactions that have used the same data to also be undone. Strict Two-Phase Locking (Strict 2PL) avoids cascading rollbacks by making sure all write locks are held until a transaction is completely finished and its changes are permanently saved (committed) or undone (rolled back).
Example
Let two transactions be T1 and T2 that are executing parallel. The transaction takes an exclusive lock on data (letโs say X) from the database, starts its operation on X, and writes the X value, but the transaction t1 is still not completed. Then transaction T2 comes into action and asks to take the X and start its execution on X, and transaction T2 is performing its remaining execution, but then the T1 failed. In this case, t1 will start its execution from the beginning again and this leads T2 to start again as T2 is dependent on the value of X generated by transaction T1. This situation is called cascading rollback.
In order to avoid this, we use a strict two-phasing locking technique where there is a restriction that a transaction holds all the exclusive locks until the transaction is committed or aborted during the execution. So until T1 release the lock on value X, the transaction T2 will wait for value X and once T1 release the lock the T2 will acquire the lock on X and performs its operation. This will make removes the possibility of cascading rollback.
Similar Reads
-
Aggregate function in SQL with Examples
In a Database Management System (DBMS), an aggregate function is a special tool that performs calculations on a set of… -
SQL and Parts of SQL language
SQL is a popular programming language, which is used to manage the relational databases and to perform various operations on… -
Views in Relational Algebra
In SQL, virtual table are considered as views. Like Tables, views also contain rows and columns. We can select the… -
Syntax of following SQL commands: sysdate, to date(), dual table ,to_number, substr() and initcap()
1. SYSDATE Purpose: SYSDATE is a function that returns the current date and time of the database server. Syntax SELECT… -
What is Super key, Candidate key and Primary key?
1. Super Key A super key is an attribute or a set of attributes within a table that uniquely identifies… -
What is Cursor? Difference between Implicit and Explicit Cursor
A Cursor is essentially a temporary work area created in the system memory that comes into play during the execution… -
What is Relational Algebra?
Relational algebra is a formal language used to query and manipulate data stored in relational database systems. It provides a… -
What do you mean by Relational Model? Explain with Example
The relational model is a type of model, which represents how the data are stored in a relational database. In… -
Functions of DBA in DBMS
The role of a Database Administrator (DBA) is to manage and maintain the performance, security, and integrity of a database.… -
What is Data Abstraction and Data Redundancy in DBMS
In the world of data management, two terms often come up: data abstraction and data redundancy. Both play crucial roles…