DBMS
DBMS
DBMS PRESENTATION
Topic :- Lock Based Protocol for Concurrency
Control
-presented by Ravinder Gangwar and Pawan Kumar
ODUCTION
E
yansaction TOPICS COVERED
ve D
oncurrency
ques
C IN THIS
B PRESENTATION
A
INTRODUCTION
Conflicts
Suppose we have 2 transaction T1 and T2
T1 T2 Conflict(Yes/No)
R(A) R(A) No conflict
R(A) W(A) Yes
W(A) R(A) Yes
W(A) W(A) Yes
Understand by an Example………………
Suppose we have 2 transaction T1 &T2 and it perform simultaneously………….
T1 T2
R(A)
W(A)
R(A)
W(A)
R(A)
T1 T2
Lock X(A)
R(A)
Exclusive
A-50
lock
W(A)
Unlock (A) Lock S(A)
Shared
R(A) lock R(A)
Binary Lock
• A binary lock can have 2 sates or values locked and unlocked.
• A distinct lock is associated with each database item A.
• These 2 values are:-
1. Lock- 1
2. Unlock- 0
• If the value of the lock on A is 1, item A cannot be accessed by a database operation that requests the item.
• If the value of the lock on A is 0 then item can be accessed when requested.
Two Phase Locking
According to the rules of protocol, every transaction can be divides into two phases.
1. First a Growing phase, in which it acquires all the locks released but can not release any
locks.
2. Lastly a Shrinking Phase, in which it release its locks but can not acquire any new locks
Rules for 2 phase locking:-
• A transaction must acquire a lock on an item before
operating on the item. The lock may be read or write,
depending on the access needed.
• Once the transaction release a lock, it can never acquire any
new locks.
Example:-
T1 T2
L1(A) L2(A)
R(A) R2(A)
A=A+100 A=2*A
W1(A) W2(A)
L1(B) L2(B)
U1(A) U2(A)
R1(B) R2(B)
B=B+100 B=2*B
W1(B) W2(B)
U1(B) U2(B)
Variations of 2 phase locking protocol:-