Module 5
Module 5
TRANSACTION
•Isolation property may no long be preserved.
•so we need Concurrency control scheme
lock is a mechanism to
control concurrent access
to a data item
Compatible??
Ex: for performing locking
If a lock cannot be granted, the requesting
transaction is made to wait till all
incompatible locks held by other
transactions have been released. The lock
is then granted
Consider the example for
deadlock:
Starvation : If a transaction T never
make a progress , then is said to be
starved.
When a transaction Ti request a lock
on a data item Q in a particular mode M
We can avoid starvation by:
•There is no othertransaction holding a lock
on Q in a mode that conflicts with M
T1: lock-s(A);
read (A);
lock-S(B);
read (B);
unlock(A);
Unlock(B);
display(A+BLB)S;IT
The point in the schedule where
the transaction has obtained its final
lock (the end of growing phase)
T1 T2 T3 T4
R(A)
W(A)
R(A)
R(A)
W(A)
For implementing this we use two simple methods
OR
Rollback T1 T1 T2
T1 T2 T1 T2
W(A)
Rollback T2 R(A) W(A)
W(A)
R(A)
Rollback T2 W(A) . .
. .
. . .
. .
. . .
. .
. . .
. .
Commit .
. Commit .
. .
. . .
.****
. .****
EXAMPLE
T1 100 T2 200 T3 300 Suppose a transaction Ti issues a read(Q)
Older Younger Youngest operation
R(A) a. If WTS(A) > TS(Ti),Rollback Ti.
R(B) b. Otherwise execute R(A) operation
W(C)
c. Set RTS(A) = Max{RTS(A),TS(Ti)}
R(B)
R(C)
W(B)
W(A) Suppose a transaction Ti issues a write(Q)
operation
A B C a. If RTS(A)>TS(Ti) then Rollback Ti
RTS 0 0 0 b. If WTS(A)>TS(Ti) then Rollback Ti
WTS 0 0 0
c. Otherwise execute Write(A) Operation
A B C Set WTS(A)=TS(Ti)
RTS 100 300 100
WTS 300 0 100
•ensures •may not cascade-
freedom from free
•may not recoverable.
deadlock
• Problem with timestamp-ordering protocol:
• Suppose Ti aborts, but Tj has read a data item written by Ti , then
Tj must abort; if Tj had been allowed to commit earlier, the
schedule is not recoverable.
• Further, any transaction that has read a data item written by Tj
must abort this can lead to cascading rollback --- that is, a chain
of rollbacks
• Solution 1:
• A transaction is structured such that its writes are all performed at the
end of its processing
• All writes of a transaction form an atomic action; no transaction may
execute while a transaction is being written
• A transaction that aborts is restarted with a new timestamp
• Solution 2: Limited form of locking: wait for data to be committed before
reading it
• Solution 3: Use commit dependencies to ensure recoverability
Consider the example Example :
Don’t worry, We
have a soloution
THOMAS WRITE
RULE
• Modified version of the timestamp-ordering protocol in which obsolete
write operations may be ignored under certain circumstances.