04 Concurrency and Recovery
04 Concurrency and Recovery
Lock-compatibility
matrix
T1 T2 T3 Lock
status
LOCK-S(A) GRANT(A,T
1)
READ(A)
LOCK-S(A) GRANT(A,T
2)
READ(A)
LOCK-X(A) WAIT(A,T3)
WRITE(A)
Atomocity Using Lock-Based
Protocols
Lock-compatibility
matrix
T4 T5 T6 Lock
status
GRANT(A,T4
)
LOCK-X(A)
WRITE(A) WAIT(A,T5)
LOCK-S(A)
READ(A)
WAIT(A,T6)
LOCK-X(A)
WRITE(A)
Atomocity Using Lock-Based
Protocols
Lock-compatibility
matrix
T7 T8 T9 Lock
status
GRANT(A,T7
)
LOCK-X(A)
WRITE(A) GRANT(B,T8)
LOCK-X(B)
WRITE(B)
GRANT(C,T9
LOCK-X(C) )
WRITE(C)
Atomocity Using Lock-Based
Protocols
Lock-compatibility
matrix
T1 T2 T3 T4 LOCK
STATUS
READ(P)
WRITE(Q)
READ(P)
WRITE(P)
Lock-Based Protocols
A lock is a mechanism to control concurrent access to a
data item
Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as well
as
written. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is
<T0 start>
<T0, A, 1000, 950>
<To, B, 2000, 2050>
A = 950
B = 2050
<T0 commit>
<T1 start>
<T1, C, 700, 600> BC output before T1
C = 600 commits
BB , BC
<T1 commit>
BABA output after T0
commits
Note: BX denotes block containing X.
Undo and Redo Operations
Undo of a log record <Ti, X, V1, V2> writes the old value V1 to
X
Redo of a log record <Ti, X, V1, V2> writes the new value V2 to
X
Undo and Redo of Transactions
undo(Ti) restores the value of all data items updated by Ti to
their old values, going backwards from the last log record
for Ti
Each time a data item X is restored to its old value V a
special log record (called redo-only) <Ti , X, V> is written
out
When undo of a transaction is complete, a log record
<Ti abort> is written out (to indicate that the undo was
completed)
redo(Ti) sets the value of all data items updated by Ti to the
new values, going forward from the first log record for Ti
No logging is done in this case
Undo and Redo Operations (Cont.)
The undo and redo operations are used in
several different circumstances:
The undo is used for transaction rollback
during normal operation(in case a
transaction cannot complete its execution
due to some logical error).
The undo and redo operations are used
during recovery from failure.
We need to deal with the case where during
recovery from failure another failure occurs
prior to the system having fully recovered.
Transaction rollback (during normal
operation)
Tc Tf
T1
T2
T3
T4