Professional Documents
Culture Documents
DBMS CH 10
DBMS CH 10
Objectives of concurrency
control
To enforce Isolation (through mutual
exclusion) among conflicting transactions.
To preserve database consistency through
consistency preserving execution of
transactions.
To resolve
conflicts.
read-write
and
write-write
T2
Read(P1)
P1=P1+5
0
Write(P1)
Write(P1)
Commit
Commit
Value of Data
Items
T1.P1300
T1.P1300+100=
400
T2.P1300
T2.P1300+50=3
50
T1 writes P1400
T2 writes P1350
This is incorr
value of P1.
Problem was
to overwritin
value of P1 b
Correct valu
450.
T2
Read(P1)
P1=P1+10
0
Write(P1)
Read(P1)
P1=P1+5
0
Abort
Write(P1)
Commit
Value of Data
Items
T1.P1300
T1.P1300+100=
400
T1 writes P1400
T2.P1400
T2.P1400+50=4
50
T1 is aborted
(Undo)
T1 writes P1450
This is incorre
value of P1.
Problem was
to reading of
value of data
by T2. Correc
value is 350.
Read(P2)
Sum=Sum+
P2
Commit
T2
Read(P2)
P2=P2+50
Write(P2)
Commit
i
m
u
ls
a
n
sh
i
f
h
The ect. T 2 w
T
r
cor ause o w
bec wed t T
t
allo tha i
item se in
u
to rect v
Cor
475
Read(P2)
P2=P2-10
Write(P2)
Commit
T2
Value of Data
Items
T1.P215
Read(P2) T2.P215
P2=P2-10 T2.P25
Write(P2) T2 writes P25
Commit
T1.P25
T1.P25-10=-5
T1 writes P2 -5
T2
Lock(x)
Read(x)
x=x+100
Write(x)
Unlock(x)
Lock(x)
x=x*2
Wtite(x)
Unlock(x)
Lock(y)
Read(y)
y=y*2
Write(y)
Unlock(y)
Lock(y)
Read(y)
y=y+100
Write(y)
Unlock(y)
T1
x50
x150
T2 writes x150
Lock(x)
Read(x)
x=x+100
Write(x)
Lock(y)
Unlock(x)
y150
y250
T1 writes y250
Lock(x)
Read(x)
x=x*2
Wtite(x)
x300
T2 writes x300
y=50
y=100
T2 writes y150
T2
Read(y)
y=y+100
Write(y)
Unlock(y)
Lock(y)
Unlock(x)
Read(y)
y=y*2
Write(y)
Unlock(y)
x150
x300
T2 writes x300
y=50
y=150
T1 writes y150
y150
y300
T2 writes y300
Deadlock
Two schemes that prevent deadlock
are called wait-die and wound-wait.
Wait-Die Scheme
If TS(Ti)< TS(Tj) //Ti older tha Tj
then
Ti waits
else
T2
Wait
Die
T3
Ti dies
TS={5,10,15} for T2,T3 & T5 respectively
T4
Deadlock
Wound-Wait Scheme
if TS(Ti)< TS(Tj)
then
Tj is wounded (rolled back)
else
Ti waits
Aborted
&
T2
Rolledbak
Allowed to Wait
T3
T4
Deadlock Detection
T2
T3
Read-Lock(x)
Read(x)
Read-Lock(y)
Read(y)
Write-Lock(x)
Write(x)
Read-Lock(x)-wait for
T1
Read-Lock(z)
Read(z)
Write-Lock(z)
Write(z)
Read-Lock(y)
Read(y)
Write-Lock(y)-wait
for T2
Read-Lock(x)-wait
for T1
Deadlock Detection
This situation can be represented in
wait-for as below.Since the graph
contains cycle T1T2T1, the given
schedule suffers from deadlock
problem
T2
T1
T3
Starvation
T2
Read(x)
Timestamps
ReadTS(x)100
ReadTS(x)110
x=x+200
x=x+200
Write(x)
Write(x)
Abort T1
WriteTS(x)110
WriteTS(x)>TS(T1) and
hence Timestamp order
violated
Strict Timestamp
Ordering
T2
Read(x)
x=x+20
0
Write(x)
Read(x)
x=x+20
0
Write(x)
Timestamps
ReadTS(x)100
ReadTS(x)110
WriteTS(x)100
TS(T2)>WriteTS(x) ,
therefore T2 wiats until
T1 is terminated
ReadTS(x)100
WriteTS(x)110
TS(T1)<WriteTS(x) ,
therefore from TWR
Write(x) operation must
be ignored.
Multiversion
Concurrency Control
For each version the value of the version xk and the following
two timestamps are kept.
WriteTS(xk) is the timestamp of the transaction that created version
xk of the data item.
ReadTS(xk) is largest timestamp of any transaction that successfully
read version xk of the data item.
Validation (Optimistic)
Concurrency Control Schemes
Lock Based and TS Based Protocols have following
overheads:
Lock Based Protocols: Needs to lock items before
performing read or write operation.
Timestamp Based Protocols needs to checks read TS
and write TS before performing read/ write operation
Validation Concurrency Control Scheme Works in three
phases for this concurrency control protocol are:
Read phase: Reads committed and updates only local
copies.
Validation phase:Ensure serializability.
Write phase:If the validation phase is successful updates
adatabase otherwise discarded and the transaction is
restarted.
Validation (Optimistic)
Concurrency Control Schemes
Suppose Ti is in its validation phase, and Tj is any
transaction that has committed or is also in its validation
phase, then one of three conditions must be true for
serializability to hold. If none of these conditions hold, Ti is
aborted
Tj
Read
Validation
Write
Ti
Tj
Ti
Read
Validation
Read
B
Tj
B
Ti
Validation
Write
Write
Validation
Read
Write
Read
Validation
Read
Validation
Write
Write
Multiple Granularity
Databas
e
File
File
File
Page
Page
Page
Record
Record
Record
Field
Field