Two-Phase Locking
DBMS Scheduler
- Receives requests to execute operations from the query processor
- For each operation it chooses one of the following actions
- Execute (send to a lower module)
- Delay (insert in some queue)
- Reject (abort transaction)
- Ignore (no effect)
Types of Schedulers
- Conservative schedulers: Favour delaying operations
- Aggressive schedulers: Favour rejecting operations
2PL
Conservative schedulers are lock based
Lock
- Shared lock: Required to read an object
- Exclusive lock: Required to write an object
- Disallows any other lock at all to be hold on
by any other transaction
- Disallows any other lock at all to be hold on
Insufficient for a scheduler just to acquire a lock, access the data item, and release it immediately
2PL
Scheduler allows no lock to be acquired by a transaction
Theorem: Any execution order of operations admitted by a scheduler following the two phase locking protocol will be a prefix of an ultimate schedule that is a conflict serializable schedule
2PL can still allow operations to process that lead to
- Cascading aborts
- Deadlocl
Strict Two-Phase Locking
Scheduler allows no lock for a transaction
Theorem: Any execution order of operations admitted by a scheduler following the strict two phase locking protocol will be a prefix of an ultimate schedule that is a conflict serializable schedule and will also have the ACA property ensuring no cascading aborts
Variations on Locking
- Multi-granularity locking
- Not all locked objects have the same size
- Advantageous in presence of bulk versus tiny updates
- Predicate locking
- Locks based on selection predicate rather than on a value
- Tree locking
- Can be used to avoid congestion in roots of Btrees
- Allows relaxation of 2PL due to tree structure of data
- Lock upgrade protocols