TM - Locking Flashcards
Locking
Mechanisms for central repository concurrency control.
Locks are variables linked with instances and holds state of instances acceptable access operations.
Binary Locks
Can be locked or unlocked (1 or 0). Ideal for mutual exclusion. Indivisible operations.
For transaction model, a Binary lock is invoked when:
Lock before R/W. Unlock after complete. No issue of Lock(x) if it already holds Lock. Same with unlock.
Problem with Binary locks
Their Totality
Multiple Mode Locks (Shared (R) or Exclusive (W) )
Lock can be in three states: Read, Write or Unlock.
For transaction Model, a Multiple Mode lock is invoked when:
Issues R/W lock before r(X), Issues W lock before W(x). Issus unlock after all operations conclude, only if it holds R/W lock. Doesn’t issue locks if x already has a lock.
Problem with Multiple Mode Locking
Use of locks alone does not guarantee serializability of transaction schedules. Stricter rules needed such as Two Phase Locking.
Two Phase Locking
2PL Scheduler manages locks by controlling when to lock or unlock a transaction.
If 2PL Theorem Holds:
No need to test for serializability of schedules.
Protocol enforces serializability.
Limits level of concurrency in a schedule.
Important 2PL Theorem
If all transactions in a scheduler adhere to a 2PL protocol then the schedule is serializable.
2PL protocol phases:
Lock Hoarding (Growing) phase [No locks released]
Releasing of Locks (Shrinking) phase [No locks required]
Types of 2PLs
Conservative (Static)
Strict
Conservative/Static 2PL
Hoards locks at start. If lock cannot be accessed it waits. Deadlock free. Difficult to use due to predeclaring R/Ws.
Sharing Phenomena
SQL Standard tries to explain sharing protocol through phenomena. Running concurrent transactions at different levels of isolation allows application designers to trade throughput for correctness. Lower isolation levels increase transaction concurrency but risk assessing object’s state that have not yet been committed
Strict 2PL
Releases all transaction locks after commit.
Not Deadlock free.
Guarantees Strict Schedule.
Recoverable Schedules and avoids cascading rollbacks.