Sunteți pe pagina 1din 3

Prove that the basic two-phase locking protocol guarantees conflict serializability of

schedules. (Hint: Show that, if a serializability graph for a schedule has a cycle, then
at least one of the transactions participating in the schedule does not obey the two-
phase locking protocol.)

Answer:
As the name suggests the two-phase locking protocol is made of two phases. The first
phase transaction has it to acquires new locks on data items to access them and in next
phase the transaction releases locks that transaction acquired i.e. (read_lock,write_lock)
precede the first unlock operation. Given below is the basic Two Phase Protocol locking

TRANSACTION 1 TRANSACTION 2
READ_LOCK(Y) READ_LOCK(X)
READ_ITEM(Y) READ_ITEM(X)
WRITE_LOCK(X) WRITE_LOCK(Y)
UNLOCK(Y) UNLOCK(X)
READ_ITEM(X) READ_ITEM(Y)
X := X + Y Y := X + Y
WRITE_ITEM(X) WRITE_ITEM(Y)
UNLOCK(X) UNLOCK(Y)

In real life the RDBMS implements a strict conservative 2PL locking which requires the
transaction to lock all the items it access before the transaction begins by pre declaring
the WRITE_SET and READ_SET. If the Transaction cannot lock the items that it needs,
it waits until all the items are available for locking. In the example given below a
schedule S, the Transaction 2 wants to READ(X), and READ(Y) it has to wait until
TRANSACTION 1 releases lock on the X and Y. It’s assumed that when a Transaction
reads or access data items, it acquires the implicit locks on data items X and Y in first
phase of 2PL and releases the locks when commit is issued during the execution of
Schedule S. Also 2PL holds all the locks until the needed locks are acquired i.e.
TRANSACTION 2 holds the lock on X until it acquires lock on Y to perform needed
operation.
TRANSACTION 1 TRANSACTION 2
READ(X)
WRITE(X)
COMMIT
READ (X)
READ(Y)
WRITE(Y)
COMMIT
READ(Y)

Schedule S

So according to the serializability rules, we created a node for each committed


transaction and draw an arc from TRANSACTION1 or T1 to TRANSACTION2 or
T2, Since the TRANSACTION2 wants to read and write data item X and Y

Data Item X

T1 T2

Data Item Y

The graph is acyclic and there are no loops i.e. T2 doesn’t cycle back to T1. Thus this
ensures that Transaction T2 at some point of execution of Schedule S does not obey 2PL
locking. Thus 2PL two-phase locking protocol guarantees conflict serializability of
schedules

References:
Elmasri, R. & Navathe, S. B. (2007). Introduction to transaction processing concepts and
theory. In K. Cantwell, M. Goldstein, P. Mahtani (Eds.), Fundamentals of database
systems (pp. 609- 636). Boston, MA: Addison Wesley.

Elmasri, R. & Navathe, S. B. (2007). Concurrency control techniques. In K. Cantwell, M.


Goldstein, P. Mahtani (Eds.), Fundamentals of database systems (pp. 641- 666).
Boston, MA: Addison Wesley.

S-ar putea să vă placă și