1 of 13

CSE 344 Section 7

Locking & HW5 OH

February 16th, 2023

2 of 13

Announcements

  • Midterm done!
  • HW4 grades released soon
  • HW5
    • M0 feedback released soon
    • M1 due Wed, Feb 22 @ 11pm
    • M2 due Mon, Mar 6 @ 11pm

3 of 13

Locking

4 of 13

Locking Overview

Remember - locking is for database internal implementation

  • A way to provide the ACID guarantees
  • Pessimistic concurrency control
    • Assumes transaction executions will conflict
  • Users of a database need only specify �BEGIN TRANSACTION … COMMIT / ROLLBACK
    • ...and the isolation level...

5 of 13

Database Lock

Table Lock

Predicate Lock

Tuple Lock

Lock Granularity

SQLite!

Less Concurrency

More Concurrency

6 of 13

Binary Locks

7 of 13

2PL with Binary Locks

Lock growing phase

Lock shrinking phase

8 of 13

2PL vs. Strict 2PL

Invalid reads

Trickled unlock and transaction end

9 of 13

2PL vs. Strict 2PL

2PL:

  • In every transaction, all lock requests must precede all unlock requests
  • Ensures conflict serializability
  • Might not be able to recover (Dirty Read: Read on some write that gets rolled back)
  • Can result in deadlocks

Strict 2PL:

  • Every lock for each transaction is held until commit or abort
  • Ensures conflict serializability
  • Recoverable as each transaction does not affect others until commit/abort
  • Can result in deadlocks

10 of 13

3-Tiered Locking (Shared/Exclusive locks)

  • X(A) - Exclusive lock on A
    • No other transaction can read or write to A
  • S(A) - Shared lock on A
    • Other transactions can acquire a shared lock to A, only allows for reads
    • If only one transaction holds a shared lock for A, �then it can upgrade to an exclusive lock
  • U(A) - No lock on A (or think of it as Unlock)
    • This transaction does not hold a lock on A
    • If it had a shared lock, some other transactions might still have a lock for A

11 of 13

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

12 of 13

HW5 ER Diagram Design Review

13 of 13

HW5 Office Hours