Pessimistic Concurrency Control (PCC)
Explore the principles of pessimistic concurrency control through the two-phase locking protocol. Learn how read and write locks manage concurrent transactions, preventing interference by acquiring locks in expanding and shrinking phases. Understand lock compatibility, how this protocol ensures serializability, and methods to prevent or detect deadlocks that may arise during transaction processing.
2-Phase locking (2PL)
2-phase locking (2PL) is a pessimistic concurrency control protocol that uses locks to prevent concurrent transactions from interfering. These locks indicate that a record is being used by a transaction, so that other transactions can determine whether it is safe to use it or not.
Types of locks
There are two basic types of locks used in this protocol:
- Write (exclusive) locks: These locks are acquired when a record is going to be written (inserted/updated/deleted).
- Read (shared) locks: These locks are acquired when a record is read.
Interaction between write (exclusive) locks and read (shared) locks
- A read lock does not block a read from another transaction. This is why it is also called shared because multiple read locks can be acquired at the same time.
- A read lock