AKU EXAM 2019 DBMS
What is two-phase locking protocol ? Explain its working in detail. How can it guarantee serializability ?
Let us first understand What is transaction ?
A transaction is an executing program that forms a logical unit of Database Processing. A transaction can include one or more database operation like insertion, deletion, modification or retrieval operation.
What is schedule ?
A schedule is a list of actions like reading, writing, aborting or committing which form a set of transactions and the order in which two actions of a transaction T appear in a schedule must be the same as the order in which they appear in T.
As name indicates read operation means it read data item For Example, Read operation in schedule represented as R(A) means read operation performed on data item A. Similarly, Write operation can be represented by W(B) means write operation performed on item B. Abort operation in schedule is used to cancel performed operation in schedule. Similarly, commit operation is used for saving performed operation permanently in schedule. A schedule that contains either an abort or commit for each transaction whose actions are listed in it is called a complete schedule.
There are basically two types of schedule is allowed in DBMS system. One is serial schedule another one is concurrent schedule.
If the actions of different transactions are not interleaved-that is transactions are executed from start to finish one by one is called serial schedule.
The DBMS interleaves the actions of different transactions to improve performance but not all interleaving should be allowed is called concurrent schedule.. Only those concurrent schedule is allowed in DBMS which is equivalent to some serial schedule. DBMS typically uses a locking protocol to achieve this.
A locking protocol is a set of rules to be followed by each transaction to ensure that , even though actions of several transactions might be interleaved, the net effect is identical to executing all transactions in some serial order.
There are two different locks are as follows :
1) Shared lock(S): It is required for reading a data item.
2) Exclusive lock(X): it is required for writing an data item.
Two phase Locking Protocol
2PL insures the serializability. It other words we can say it does not allow to execute any non serializable schedule. The idea of 2PL protocol is that a transaction cannot request additional locks once it releases any lock.
As name indicates it has one phase called growing phase in which it acquires locks followed by second phase called shrinking phase in which it release locks.
LP: (Lock Point) It is the point between last lock and first unlock.
Equivalent serial schedule is based upon the lock points of transactions in Two Phase Locking Protocol.
Ex: Consider the following schedule S: Check if schedule S is allowed by 2PL or not
It's too good mam....
ReplyDeleteVery useful for us....
Explained in very easy manner...i wish its reaching to the right person...
ReplyDelete