Lock-based Concurrency Control

COMP9315 21T1 ♢ Locking ♢ [0/10]
❖ Lock-based Concurrency Control

Requires read/write lock operations which act on database objects.

Synchronise access to shared DB objects via these rules:

These rules alone do not guarantee serializability.
COMP9315 21T1 ♢ Locking ♢ [1/10]
❖ Lock-based Concurrency Control (cont)

Locks introduce additional mechanisms in DBMS:


[Diagram:Pics/txproc/txproc2.png]


The Lock Manager manages the locks requested by the scheduler

COMP9315 21T1 ♢ Locking ♢ [2/10]
❖ Lock-based Concurrency Control (cont)

Lock table entries contain:

Lock and unlock operations must be atomic.

Lock upgrade:

COMP9315 21T1 ♢ Locking ♢ [3/10]
❖ Lock-based Concurrency Control (cont)


Consider the following schedule, using locks:

T1(a): Lr(Y)     R(Y)           continued
T2(a):      Lr(X)    R(X) U(X)  continued

T1(b):      U(Y)         Lw(X) W(X) U(X)
T2(b): Lw(Y)....W(Y) U(Y)

(where Lr = read-lock, Lw = write-lock, U = unlock)

Locks correctly ensure controlled access to X and Y.

Despite this, the schedule is not serializable.  (Ex: prove this)

COMP9315 21T1 ♢ Locking ♢ [4/10]
❖ Two-Phase Locking


To guarantee serializability, we require an additional constraint:

Each transaction is then structured as:
Clearly, this reduces potential concurrency ...
COMP9315 21T1 ♢ Locking ♢ [5/10]
❖ Problems with Locking


Appropriate locking can guarantee serializability..

However, it also introduces potential undesirable effects:

COMP9315 21T1 ♢ Locking ♢ [6/10]
❖ Deadlock


Deadlock occurs when two tx's wait for a lock on an item held by the other.

Example:

T1: Lw(A) R(A)            Lw(B) ......
T2:            Lw(B) R(B)       Lw(A) .....

How to deal with deadlock?

COMP9315 21T1 ♢ Locking ♢ [7/10]
❖ Deadlock (cont)


Handling deadlock involves forcing a transaction to "back off"

COMP9315 21T1 ♢ Locking ♢ [8/10]
❖ Deadlock (cont)

Methods for managing deadlock

COMP9315 21T1 ♢ Locking ♢ [9/10]
❖ Deadlock (cont)

Properties of deadlock handling methods:

COMP9315 21T1 ♢ Locking ♢ [10/10]


Produced: 14 Apr 2021