Professional Documents
Culture Documents
DBMS Lecture27 28 - SZQ
DBMS Lecture27 28 - SZQ
Lecture #27-28
Concurrency Controls
(Deadlock Management, Intent Locking)
Timeouts
▪ If the lock has not been granted within this period,
the lock request times out.
▪ In this case, the DBMS assumes the transaction
may be deadlocked,
o even though it may not be, and
o it aborts and automatically restarts the
transaction.
▪ This is a very simple and practical solution to
deadlock avoidance and is used by several
commercial DBMSs.
Deadlock Prevention
▪ The wait-die scheme is a non-preemptive technique.
o allows only an older transaction to wait for a
younger one,
o otherwise the transaction is aborted (dies) and
restarted with the same timestamp,
o so that eventually it will become the oldest active
transaction and will not die.
❖When Ti requests a data item currently held by Tj,
❖Ti is allowed to wait only if it has a timestamp
smaller than that of Tj (that is, Ti is older than Tj).
❖Otherwise, Ti is rolled back (dies).
6
Deadlock Prevention
▪ The wound-wait scheme is a preemptive technique.
o uses a symmetrical approach
o only a younger transaction can wait for an older one.
o If an older transaction requests a lock held by a
younger one, the younger one is aborted (wounded).
❖When transaction Ti requests a data item currently
held by Tj,
❖Ti is allowed to wait only if it has a timestamp
larger than that of Tj (that is, Ti is younger than Tj).
❖Otherwise, Tj is rolled back (Tj is wounded by Ti).
8
Deadlock Prevention
▪ Whenever the system rollbacks transactions, it is
important to ensure that there is no starvation
o i.e., no transaction gets rolled back repeatedly
o and is never allowed to make progress.
▪ Both the DL prevention schemes avoid starvation:
o At any time, there is a transaction with the smallest
timestamp.
o This transaction cannot be required to roll back in
either scheme.
o Since timestamps always increase, and a transaction
that is rolled back repeatedly will eventually have
the smallest timestamp at which point it will not be
rolled back again.
10
11
Deadlock Prevention
12
13
Deadlock Detection
▪ The DBMS allows deadlock to occur but
recognizes occurrences of deadlock and breaks
them.
▪ Detecting the deadlock involves detecting a cycle
in the Wait-For-Graph
o (i.e. the graph of who is waiting for whom).
▪ The wait-for-graph (WFG) shows the transaction
dependencies:
o that is, transaction Ti is dependent on Tj
o if transaction Tj holds the lock on a data item that
Ti is waiting for.
14
15
Deadlock Detection
16
T1 T2
T4 17
Deadlock Detection
Exercise
18
19
Deadlock Detection
Choice of time interval
▪ The choice of time interval between executions
of the deadlock detection algorithm is
important.
o If the interval chosen is too small, deadlock
detection will add considerable overhead;
o if the interval is too large, deadlock may not be
detected for a long period.
▪ A dynamic detection algorithm could start with
an initial interval size. 20
21
23
26
27
28
Locking Granularity
Locking Granularity
32
Locking Granularity
▪ A transaction might lock the entire database, in
which case the granule size is the entire database.
▪ However this granularity would prevent any other
transactions from executing until the lock is
released.
▪ This would clearly be undesirable.
▪ Ideally, the DBMS should support mixed
granularity with data item, record, and file level
locking.
34
Locking Granularity
36
Intent Locking
▪ Now, we have already implied that X and S locks
make sense for whole relation as well as for
individual tuples.
▪ We now introduce three new kinds of locks, called
intent locks, that also make sense for relations, but
not for individual tuples.
▪ The new kinds of locks are called
o intent shared (IS),
o intent exclusive (IX) and
o shared intent exclusive (SIX) locks.
38
INTENT LOCKING
40
41
INTENT LOCKING
43
INTENT LOCKING
▪ Note that a lock request that fails for a given lock type
will certainly fail for a stronger lock type
o and this fact implies that it is always safe to use a
lock type that is stronger than strictly necessary.
▪ Note too that neither of S and IX is stronger than the
other.
44
45
INTENT LOCKING
47
INTENT LOCKING
48