Beruflich Dokumente
Kultur Dokumente
Introduction:
Interactions among transactions can cause the
database to become inconsistent, even when the
transactions individually preserve correctness of the
state, and there is no system failure. Thus the order in
which the individual steps of di fferent transactions
occur needs to be regulated in some manner. The
function of controlling these steps is given to the
scheduler component of the DBMS, and the general
process of assuring that transactions preserve
consistency when executing simultaneou sly is called
concurrency control.
2. What’s transactions?
l Results in a deadlock
EXEC SQL
BEGIN TRANSACTION
END-EXEC
EXEC SQL
END-EXEC
EXEC SQL
UPDATE Department
SET EmpCount=EmpCount-1
WHERE DeptNo=500
END-EXEC
EXEC SQL
END TRANSACTION
END-EXEC
If an error were to occur during the processing of either
the DELETE or UPDATE statement within the BEGIN
TRANSACTION and END TRANSACTION statements, both
Employee and Department tables would be restored to
their sta tes before the transaction began.
3.What’s lock?
UPI/NUPI/USI NUSI/Full
Table Scan
DROP DATABASE
MONIFY DATABASE
DROP TABLE
ALTER TABLE
4.What’s deadlock?
A deadlock occurs when transaction1 places a lock on
resources A, then needs to lock resources B. But
resource B has already been locked by transaction 2,
which in turn needs to place a lock on resource A. This
state of affairs is called a deadlock or a deadly
embrace.
5. Transaction Recovery
l Software failure
l Parity error
l RDBMS recovery
l Hardware failure
l Software failure
l User command
l Lock Manager
• Locking Modes
l Blocked Requests
l Preventing Deadlocks
1.Lock Manager
Introduction
5
And Row.
2.Locking Modes
5
Introduction
5
Granted
[VALUES]… Write
5.Single-Statement Transactions
5
When several requests that compete for the same table are
submitted as separate, single-statement transactions, the lock
manager resolves the locking requirements as follows:
Stage Process
4 Job4 requires a Read lock. This conflicts with the queued Write
lock, so Job4 is queued behind Job2.
6.Multi-Statement Transactions
5
Introduction
5
8.Preventing Deadlocks
5Introduction
5
Example1.
5
AccntNo QualifyAccnt
------- ------------
1761 4214
In this case, the value "1587" was found in the secondary index
subtable, and the corresponding data row was selected and
returned. However, the data for account 1761 had been
changed by the other user while this se lection was in
progress. Returns such as this are possible even if the data is
changed or deleted only momentarily by a transaction that is
subsequently
User A:
BEGIN TRANSACTION;
END TRANSACTION;
User B:
BEGIN TRANSACTION;
END TRANSACTION;
In this example, the UserA request for a rowhash Write lock is
granted, which blocks the UserB request for a Write lock on
that row. The UserB transaction is queued until the UserA lock
is released. The UserA lock is held unt il the entire transaction
is complete. Thus, the UserB ’LOCK ROW ...’ request is granted
only after the UserA END TRANSACTION statement has been
processed.
Introduction
5
Changing Mode