Information Technology Reference
In-Depth Information
Latching and unlatching must be as efficient as possible. This is why it is
normal practice not to keep a wait-for graph of the latches acquired by processes to
notice deadlocks. Thus, the latching protocol applied by all processes must prevent
deadlocks.
If a process or thread must keep more than one page latched simultaneously,
such as in a B-tree a parent page and one or two child pages, the latches must
always be acquired in a predefined order, such as in the order first-parent-then-child,
first-older-sibling-then-younger-sibling. Upgrading of a read-latch to a write latch
is forbidden altogether.
6.6
Conditional Lock Requests
Deadlocks can also occur between locks and latches.
Example 6.20 Assume two forward-rolling transactions T 1 and T 2 .
1. T 1 performs the insert action IŒx; v on data page p. Therefore the key x is
X-locked by T 1 for commit duration, page p is write-latched, the insertion is
performed and logged, and page p is unlatched.
2. T 2 wants to perform the read action RŒx > z ; v . Therefore page p is read-latched,
the key x satisfying the search condition is found, and an S lock on x for T 2 is
requested. Because x is currently X-locked by T 1 , the requested S lock cannot be
granted immediately, and so T 2 must wait.
3. T 1 is still active and wants to perform the insert action IŒy; w on page p (which
also covers key y). Therefore a write latch on page p is requested. Because p is
currently read-latched by the thread executing T 2 , the requested latch cannot be
granted immediately, and so T 1 must wait.
Now the thread executing T 1 is waiting for a write latch on page p that is currently
read-latched by the thread executing T 2 and waiting for an S lock on key x (Fig. 6.5 ).
t
Deadlocks between latches and locks are prevented by requiring that a process
or thread must never hold a latch on any page when it is waiting for a lock. Thus,
going to sleep to wait for a lock is only allowed when the thread holds no latches.
Fig. 6.5 Deadlock between
locks and latches. Transaction
T 2 is holding page p latched
while waiting for an S lock on
key x currently X-locked by
T 1 , which now wants to
write-latch p for IŒy; w
Search WWH ::




Custom Search