Question 1: What variations are possible on two-phase locking protocol?
Ans:Variations are possible on two-phase locking protocol arefollowing:
It is possible to construct a 2PL scheduler that never abortstransactions. This
technique is known as Conservative 2PL or Static 2X. As we haveseen, 2PL
causes abortions because of deadlocks. Conservative 2PL avoids deadlocks by
requiring each transaction to obtain all of its locks before any of its operationsaresubmitted to the DM. This is done by having each transaction predeclare its readsetand writeset. Specifically, each transaction T, first tells the scheduler all the data itemsit will want to Read or Write, for example as part of its Start operation. The scheduler tries to set all of the locks needed by T,. It can do this providing that none of theselocks conflicts with a lock held by any other transaction.If the scheduler succeeds in setting all of T,‘s locks, then it submits Ti’s operations tothe DM as soon as it receives them. After the DM acknowledges the processing of T,‘s last database operation, the scheduler may release all of l-j’s locks.
If, on the other hand, an)’ of the locks requested in T,‘s Startconflicts with locks presently held by other transactions, then thescheduler does not grant any of T,‘s locks. Instead, it inserts T,along with its lock requests into a waiting queue. Every time thescheduler releases the locks of a completed transaction, it examinesthe waiting queue to see if it can grant all of the lock requests of any waiting transactions. If so, it then sets all of the locks for eachsuch transaction and continues processing as just described. In Conservative 2PL, if a transaction T; is waiting for a lock held by Tj, then T; is holding no locks. Therefore, no other transaction Thcan be waiting for T,, so there can be no WFG edges of the form Tk -+ T,. Since there can be no such edges, T, cannot be in a WFG cycle,and hence cannot become part of a deadlock. Since deadlock is theonly reason that a 2PL scheduler ever rejects an operation andthereby causes the corresponding transaction to abort,Conservative 2PL never aborts a transaction. (Of course, atransaction may abort for other reasons.) This is a classic case of aconservative scheduler. By delaying operations sooner than it hasto, namely, when the transaction begins executing, the scheduleravoids abortions that might otherwise be needed for concurrencycontro1 reasons.
Almost all implementations of 2PL use a variant called Strict 2PL. This differs from the Basic 2PL scheduler described in Section 3.2 inthat it requires the scheduler to release all of a transaction’s lockstogether, when the transaction terminates. More specifically, Tlslocks are released after the DM acknowledges the processing of cior aj, depending on whether T; commits or aborts (respectively).