0% found this document useful (0 votes)
6 views31 pages

Concurrency Control

The concurrency control Protocols

Uploaded by

Neha Mendjoge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views31 pages

Concurrency Control

The concurrency control Protocols

Uploaded by

Neha Mendjoge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

CONCURRENCY CONTROL

NEHA KATRE
Concurrency
Control
Schemes

Lock Based Protocols


Time Stamp Based
(Two Phase Locking
Sharing
Protocols)
NEHA KATRE
LOCK BASED PROTOCOLS
• Allow transactions to access data only if it is
holding a lock on the data

NEHA KATRE
LOCK BASED PROTOCOL
• SHARED MODE LOCK: If transaction Ti has
obtained a shared mode lock on data item Q,
then Ti can read Q but cannot write Q.
Other transactions can also access the data
but in READ ONLY mode.
• EXCLUSIVE MODE LOCK: If transaction Ti has
obtained a exclusive mode lock on data item
Q, then Ti can both read and write Q.
Data item Q is not visible to other
transaction.
NEHA KATRE
• UPGRADING LOCKS: If a transaction changes
its mode of lock from shared mode to
exclusive mode it is called as upgrading of
locks.
• DOWNGRADING LOCKS: If a transaction
changes its mode of lock from exclusive
mode to shared mode it is called as
downgrading of locks.

NEHA KATRE
COMPATIBILITY FUNCTION
Ti now requests a lock of mode A
on the same data Q.
Tj If Ti can be granted the lock then
LOCK OF MODE we say mode A is compatible
B
with mode B.

DATA Q
Shared mode is compatible with
shared mode but it is not
compatible with exclusive mode.

NEHA KATRE
• It is not desirable for a transaction to unlock
the data immediately after its final access.
• Serializability may not be ensured

NEHA KATRE
Initial Value of A = 100 and B = 200
T1: Lock-X(B) T2: Lock-S(A)
Read(B) Read(A)
B:=B-50 Unlock(A)
Write(B) Lock-S(B)
Unlock (B) read(B)
Lock-X(A) Unlock (B)
Read(A) display (A+B)
A:=A+50
Write(A)
Unlock(A)

NEHA KATRE
NEHA KATRE
With delayed unlocking

NEHA KATRE
Granting Locks
The concurrency control manager can grant Ti
lock of mode M on data Q if
1.There is no other transaction holding a lock on
Q in a mode that conflicts with M
2.There is no other transaction that is waiting
for a lock on Q and that made its lock request
before Ti

NEHA KATRE
TWO PHASE LOCKING PROTOCOL
• Growing Phase: Transactions can acquire
locks but cannot issue unlocks.
• Shrinking Phase: Transactions can issue
unlock commands to release the data it had
locked. No locks can be issued.

NEHA KATRE
T0 T1

Lock_x(A)
i ng
row e Lock_X(B)
G as Lock_s(C)
Ph
A=A+B
B=B+C
Write(A)
Write(B)
as ing

Unlock (A)
Ph rink

Unlock (B)
e

Lock_x(A)
Sh

Unlock(C)
Read (A)
Read (B)
NEHA KATRE
Cascading rollback can occur in 2PL

NEHA KATRE
Strict Two-Phase Locking Protocol
• This protocol require
– 2PL
– All exclusive mode locks be realized only after
transaction commits

NEHA KATRE
DBMS: Hashing Chapter

NEHA KATRE
Implementation of Locking

NEHA KATRE
TIMESTAMP BASED PROTOCOLS

NEHA KATRE
• Determines the order in which transactions
are to be executed.
• To decide the order, a TIMESTAMP is
allocated to the transaction when it issues a
request for the data.

NEHA KATRE
There are two methods for implementing
timestamps
1. current time on system clock

2. using a logical counter: A transaction’s


timestamp is equal to the value of the
counter when the transaction enters the
system.

NEHA KATRE
These techniques can be implemented
using the following validations
• W-Time Stamp: is the largest time-stamp of
any transaction that executed write(Q)
successfully.

• R-time Stamp: is the largest time-stamp of any


transaction that executed read(Q)
successfully.

NEHA KATRE
THE TIMESTAMP ORDERING PROTOCOL

• Suppose a transaction Ti issues a read(Q)


1. If TS(Ti) < W-timestamp(Q), then Ti needs to read
a value of Q that was already overwritten.
 Hence, the read operation is rejected, and Ti is rolled
back.

2. If TS(Ti) W-timestamp(Q), then the read


operation is executed, and R-timestamp(Q) is set
to max(R-timestamp(Q), TS(Ti)).

NEHA KATRE
• Suppose that transaction Ti issues write(Q).
1. If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is
producing was needed previously, and the system
assumed that that value would never be produced.
 Hence, the write operation is rejected, and Ti is rolled back.

2. If TS(Ti) < W-timestamp(Q), then Ti is attempting to write


an obsolete value of Q.
 Hence, this write operation is rejected, and Ti is rolled back.

3. Otherwise, the write operation is executed, and W-


timestamp(Q) is set to TS(Ti).

NEHA KATRE
What will happen if we apply
timestamp ordering protocol?

NEHA KATRE
THOMAS WRITE RULE
• Suppose that transaction Ti issues write(Q).
1. If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is
producing was needed previously, and the system
assumed that that value would never be produced.
 Hence, the write operation is rejected, and Ti is rolled back.

2. If TS(Ti) < W-timestamp(Q), then Ti is attempting to write


an obsolete value of Q.
 Hence, this write is ignored.

3. Otherwise, the write operation is executed, and W-


timestamp(Q) is set to TS(Ti).
NEHA KATRE
NEHA KATRE
Assume basic timestamp ordering protocol and that time starts from
1, each operation takes unit amount of time and start of transaction Ti
is denoted as Si. The table of timestamp is given below:
OPERATION
R1(a)
R2(b)
W2(b)
W1(a)
W3(a)
W3(b)

Find RTS(a), WTS(a), RTS(b), WTS(b)

NEHA KATRE
Consider the following schedule. Assume TS(T1) =100, TS(T2) =200 and TS(T3)
=300.Apply timestamp ordering protocol to the following schedule justify the rule
applied at each step.

T1 T2 T3
R(A)
R(B)
W(C)
R(B)
R(C)
W(B)
W(A)

NEHA KATRE
VALIDATION BASED PROTOCOL
• Read phase:

• Validation phase: Transaction Ti performs a


``validation test'‘ to determine if local
variables can be written to the database

• Write phase:

NEHA KATRE
• Each transaction Ti has 3 timestamps
1. Start(Ti) : the time when Ti started its execution

2. Validation(Ti): the time when Ti entered its


validation phase

3. Finish(Ti) : the time when Ti finished its write


phase

NEHA KATRE
Validation Test for Transaction Tj
• If for all Ti with TS (Ti) < TS (Tj) either one of
the following condition holds:
– finish(Ti) < start(Tj)
– start(Tj) < finish(Ti) < validation(Tj) and the set of
data items written by Ti does not intersect with
the set of data items read by Tj.

NEHA KATRE

You might also like