CSE 414: �Transactions with Locks
February 18, 2021
Section 7
Announcements
Txn & Locking overview
Remember - locking is for database internal implementation
Conflicts Review
READ-WRITE
WRITE-READ
WRITE-WRITE
“Intra-transactional” - don’t mess with the order of operations within a transaction
}
Inter-transactional
Serializability Review
A schedule is serializable if it is behaviorally equivalent to a serial schedule.
It is conflict serializable if it can be transformed into a serial schedule via a series of non-conflicting swaps.
Serializable
Conflict
Serializable
Easy to check
Not easy to check
True or False: If all transactions are read-only, then every schedule is serializable.
2PL: 2 Phase Locking
Guarantees conflict serializability
Limitations of 2PL
See lecture for examples of both
Strict 2PL
Similar to 2PL BUT with an additional constraint:
2PL v.s. Strict 2PL at a glance
2PL:
Strict 2PL:
2PL v.s. Strict 2PL
Invalid reads
Trickled unlock and transaction end
Practice: Is this schedule possible under a Strict 2PL Protocol?
R2(B), W2(B), R3(C), W3(C), R3(A), W3(A), Co3, R2(C), W2(C), Co2, R1(A), R1(B), W1(A), W1(B), Co1
Practice: Is this schedule possible under a Strict 2PL Protocol?
R2(B), W2(B), R3(C), W3(C), R3(A), W3(A), Co3, R2(C), W2(C), Co2
R1(A), R1(B), W1(A), W1(B), Co1
Answer: Yes
Practice: Is this schedule possible under a Strict 2PL Protocol?
R2(B), W2(B), R3(C), W3(C), R1(A), R1(B), W1(A), W1(B), Co1, R2(C), W2(C), Co2, R3(A), W3(A), Co3
Practice: Is this schedule possible under a Strict 2PL Protocol?
R2(B), W2(B), R3(C), W3(C), R1(A), R1(B), W1(A), W1(B), Co1,
R2(C), W2(C), Co2,
R3(A), W3(A), Co3
Answer: Nope
Binary Locks
3-Tiered Locking (Shared/Exclusive locks)
Basically, you can have:
OR
All the locks!
Concurrency Control Method | Benefit |
2PL | Ensures conflict serializability |
Strict 2PL | Ensures recovery |
Conservative 2PL (not studied in 414) | Ensures deadlock-free |
Lock Type | Benefit |
Binary Locks | Simplest lock implementation |
Shared/Exclusive Locks | Greater throughput on reads |
Database Lock
Table Lock
Predicate Lock
Tuple Lock
Lock Granularity
SQLite!
Less Concurrency
More Concurrency
What Lock is this? (#1)
T1 | T2 |
S(A) | |
R(A) | |
| S(A) |
| R(A) |
U(A), Commit | |
| X(B) |
| U(A) |
| W(B) |
| U(B), Commit |
What Lock is this? (#1)
T1 | T2 |
S(A) | |
R(A) | |
| S(A) |
| R(A) |
U(A), Commit | |
| X(B) |
| U(A) |
| W(B) |
| U(B), Commit |
Shared/Exclusive Locks
Yes
No
What Lock is this? (#2)
T1 | T2 |
L(A) | |
| L(B) |
R(A) | |
| R(B) |
U(A), Commit | |
| L(A) |
| W(A) |
| R(A) |
| U(A), U(B), Commit |
What Lock is this? (#2)
T1 | T2 |
L(A) | |
| L(B) |
R(A) | |
| R(B) |
U(A), Commit | |
| L(A) |
| W(A) |
| R(A) |
| U(A), U(B), Commit |
Binary Locks
Yes
Yes
Takeaways...