Create a node for each transaction.
n Create a directed edge T
i → T
j
, if transaction T
i
is waiting to lock an item that is
currently locked by T
j
.
Deadlock exists if and only if the WFG contains a cycle (Holt, 1972). Figure 20.20
shows the WFG for the transactions in Figure 20.19. Clearly, the graph has a cycle in it
(T
17→ T
18→ T
17
), so we can conclude that the system is in deadlock.
Frequency of deadlock detection
Since a cycle in the wait-for graph is a necessary and sufficient condition for deadlock to
exist, the deadlock detection algorithm generates the WFG at regular intervals and examines
it for a cycle. The choice of time interval between executions of the algorithm is import-ant. If the interval chosen is too small, deadlock detection will add considerable overhead;
if the interval is too large, deadlock may not be detected for a long period. Alternatively,
a dynamic deadlock detection algorithm could start with an initial interval size. Each time
no deadlock is detected, the detection interval could be increased, for example, to twice
the previous interval, and each time deadlock is detected, the interval could be reduced,
for example, to half the previous interval, subject to some upper and lower limits.
Recovery from deadlock detection
As we mentioned above, once deadlock has been detected the DBMS needs to abort one
or more of the transactions. There are several issues that need to be considered:
(1) Choice of deadlock victim In some circumstances, the choice of transactions to abort
may be obvious. However, in other situations, the choice may not be so clear. In such
cases, we would want to abort the transactions that incur the minimum costs. This may
take into consideration:
(a) how long the transaction has been running (it may be better to abort a transaction
that has just started rather than one that has been running for some time);
(b) how many data items have been updated by the transaction (it would be better to
abort a transaction that has made little change to the database rather than one that
has made significant changes to the database);
(c) how many data items the transaction is still to update (it would be better to abort
a transaction that has many changes still to make to the database rather than one
that has few changes to make). Unfortunately, this may not be something that the
DBMS would necessarily know.
Create a node for each transaction.
n Create a directed edge T
i → T
j
, if transaction T
i
is waiting to lock an item that is
currently locked by T
j
.
Deadlock exists if and only if the WFG contains a cycle (Holt, 1972). Figure 20.20
shows the WFG for the transactions in Figure 20.19. Clearly, the graph has a cycle in it
(T
17→ T
18→ T
17
), so we can conclude that the system is in deadlock.
Frequency of deadlock detection
Since a cycle in the wait-for graph is a necessary and sufficient condition for deadlock to
exist, the deadlock detection algorithm generates the WFG at regular intervals and examines
it for a cycle. The choice of time interval between executions of the algorithm is import-ant. If the interval chosen is too small, deadlock detection will add considerable overhead;
if the interval is too large, deadlock may not be detected for a long period. Alternatively,
a dynamic deadlock detection algorithm could start with an initial interval size. Each time
no deadlock is detected, the detection interval could be increased, for example, to twice
the previous interval, and each time deadlock is detected, the interval could be reduced,
for example, to half the previous interval, subject to some upper and lower limits.
Recovery from deadlock detection
As we mentioned above, once deadlock has been detected the DBMS needs to abort one
or more of the transactions. There are several issues that need to be considered:
(1) Choice of deadlock victim In some circumstances, the choice of transactions to abort
may be obvious. However, in other situations, the choice may not be so clear. In such
cases, we would want to abort the transactions that incur the minimum costs. This may
take into consideration:
(a) how long the transaction has been running (it may be better to abort a transaction
that has just started rather than one that has been running for some time);
(b) how many data items have been updated by the transaction (it would be better to
abort a transaction that has made little change to the database rather than one that
has made significant changes to the database);
(c) how many data items the transaction is still to update (it would be better to abort
a transaction that has many changes still to make to the database rather than one
that has few changes to make). Unfortunately, this may not be something that the
DBMS would necessarily know.
การแปล กรุณารอสักครู่..