DatabasesLesson 1 of 2 in the course Transactions and concurrency

Two-Phase Locking: Lock Phases, Variants, and Deadlocks

5 flashcards · 5 quiz questions · 5 match pairs · 5 fill-in sentences · English

Lesson progress
0 / 5

Your progress is kept in this browser only.Sign up to save it

Summary

Two-phase locking (2PL) is a pessimistic concurrency-control protocol that coordinates transactions by using locks. It guarantees conflict serializability when every transaction follows the protocol. This lesson explains the basic lock rules, the growing and shrinking phases, and how conservative, strict, and strong strict 2PL differ.

A transaction holds a lock on a data object when it has acquired that lock and has not yet released it. Locks coordinate access so that conflicting operations do not proceed at the same time.

All flashcards

What are shared and exclusive locks?
A shared (read) lock permits reading and can coexist with other shared locks on the same object. An exclusive (write) lock permits writing and conflicts with every other lock on that object.
What are the two phases of 2PL?
In the expanding phase, a transaction can acquire locks but cannot release them. In the shrinking phase, it can release locks but cannot acquire new ones.
What is the lock point, and why does it matter?
The lock point is the moment a transaction obtains its final lock. The order of transactions by their lock points provides a serial order that explains why 2PL guarantees conflict serializability.
How does conservative 2PL prevent deadlocks, and what is one limitation?
C2PL requires a transaction to obtain all locks it needs before execution, so it does not hold some locks while waiting for others. It requires advance knowledge of the transaction's complete read and write sets, which may be difficult to provide.
How do S2PL and SS2PL differ?
S2PL holds exclusive locks until commit or abort but may release shared locks during shrinking. SS2PL holds both shared and exclusive locks until commit or abort.

Quiz questions

  1. Two transactions each hold a shared lock on the same object. What does the lock compatibility rule allow?Answer: Both transactions may retain their shared locks.
  2. What is a transaction's lock point in two-phase locking?Answer: The moment it obtains its final lock.
  3. Why does conservative 2PL prevent deadlocks caused by lock wait cycles?Answer: A transaction obtains all required locks before execution or waits without holding a partial set.
  4. A transaction requests an exclusive lock on an object that another transaction holds with a shared lock. What happens to the request?Answer: It is blocked until the conflicting lock is no longer held.
  5. What serializability property is guaranteed when every transaction follows basic 2PL?Answer: Conflict serializability.

Based on the Wikipedia article Two-phase locking, licensed CC BY-SA 4.0. Adapted into a summary, flashcards and quizzes.

All Databases lessons