...

/

Analysis and Evaluation of Two-Phase Locking (2PL)

Analysis and Evaluation of Two-Phase Locking (2PL)

Let's analyze and evaluate the two-phase locking mechanism for concurrency management.

Handling of deadlocks

A situation might arise where transaction A is waiting for a long time for transaction B to finish, since we use a lot of locks simultaneously. In general, we refer to the situation where a cycle of transactions waits for one another to release locks as a deadlock.

Press + to interact
A deadlock
A deadlock

The database automatically identifies deadlocks among the transactions. To resolve them, it relies on two approaches—detection and prevention.

Deadlocks detection

The database management system (DBMS) produces a waits-for graphA directed graph used for deadlock detection., where transactions will form the nodes. Consequently, an edge will form between two nodes, Ti and Tj, if Ti is waiting for the release of a lock held by Tj. The system will frequently inspect the waits-for graph for cycles before determining how to break them. The system will have a deadlock only if there is a cycle in the waits-for graph.

  • The DBMS will choose a victim transaction to roll back when it notices a deadlock to break the loop.
  • Depending on how the application invoked the transaction, the victim transaction will either restart or abort.
  • When choosing a victim, there are many transaction properties to
...