2) 2-Phase lock

It is used to overcome the disadvantage of the simple lock. In the 2-phase locking, there are two phases are growing phase and shrinking phase. 2-phase ensures serializability.

Growing phase: A transaction may obtain locks but not release any locks.

Shrinking phase: A transaction may release lock but may not obtain new locks.

a) Simple 2-phase locking: Once a transaction releases a lock it enters in shrinking phase and in shrinking phase it cannot issue any more locks.

Advantage:

Less resource utilization.

Disadvantage:

Deadlock present.

Note: The final point of lock-in schedule of transaction called lock point of transaction. We denote conversion from shared to an exclusive mode called upgrade and its opposite conversion from exclusive to shared mode is called downgrade.

b) Conservative 2-phase locking: The lock of the entire data item that we need before the transaction starts.

Advantage:

No waiting for the data item

No deadlock create

Disadvantage:

Practically data implementation is difficult

c) Strict 2-phase locking: Transaction does not release any of the exclusive locks until after its commit or abort.

Advantage:

No dirty read problem

Proper lock

Disadvantage:

Deadlock create

d) Rigorous 2-phase locking: Transaction "t" does not release any of its locks until after it commits or aborts. All lock release at the same time no lock release first or last.

3) Graph-based protocol

It follows 6 rules:

It uses the only exclusive lock.

The first lock can be acquired on any data item.

Subsequent locks are allowed only if the parent is locked.

Unlock at any point.

Each data item can be accessed at most once.

Relocking by the same transaction is not allowed.

Advantage:

No rollback

No deadlock

Less waiting time

Disadvantage:

Prior knowledge of data

Unnecessary lock

Conclusion:

In this article, we have learned all the types of locking protocols and its advantage and disadvantage. In the next article, we gather more about DBMS. Stay tuned for the next article. Have a nice day! Happy Learning!