Monday 17 February 2014

Two phase locking protocol in concurrency control | Transaction management


TWO PHASE LOCKING PROTOCOL(PESSIMISTIC APPROACH)

A transaction follows the two phase locking protocol, if all the locking operations precede the first unlock operation in the transaction. There are two phases in the Schedule. These are:

1.) GROWING PHASE- During which all the locks are requested.
2.) SHRINKING PHASE- During which all the locks are released.

Initially a transaction is in the growing phase. The transaction acquires locks as needed. Once the transaction releases a lock, it enters the shrinking phase and it can issue no more lock requests.

For Example:

             Lock X(A) 

             Read(A)   
             A:= A-200    GROWING PHASE
             Write(A)
             Lock X(B)
             ---------
             Unlock(A)
             Read(B)
             B:=B+200     SHRINKING PHASE
             Write(B)
             Unlock(B)

PROBLEMS WITH TWO PHASE LOCKING PROTOCOL:-

1.) Deadlock
2.) Cascading Roll-Back

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete