You are on page 1of 27

Topic: Concurrency Control

Group Members:
Name Roll No
Himani Vilas Bhirud 221081
Anjali Upendra More 221082
Shraddha Umesh Mulay 221083
Preeti Chandrakant Alegaonkar 221084
1.
Concurrency Control

2
Concurrency Execution :

In a multi-user system, multiple users can access and use


the same database at one time, which is known as the
concurrent execution of the database.

3
What is Concurrency Control ?

• Concurrency Control is the management procedure that


is required for controlling concurrent execution of the
operations that take place on a database.
• Concurrency Control is the working concept that is
required for controlling and managing the concurrent
execution of database operations and thus avoiding the
inconsistencies in the database.

4
Need of Concurrency Control :

• It is needed to ensure that the database transactions are


performed concurrently and accurately to produce
correct results.
• To resolve read-write and write-write conflict issues
• To maintain consistency in database.
• Concurrency control helps to ensure atomicity, isolation
serializability

5
Example
• Assume that two people who go to electronic kiosks at the same
time to buy a movie ticket for the same movie and the same show
time.
• However, there is only one seat left in for the movie show in that
particular theatre. Without concurrency control in DBMS, it is
possible that both moviegoers will end up purchasing a ticket.
However, concurrency control method does not allow this to
happen. Both moviegoers can still access information written in the
movie seating database. But concurrency control only provides a
ticket to the buyer who has completed the transaction process first.

6
Methods of Concurrency Control :

1. Locking Methods
2. Time-Stamp Methods

7
2.
Locking Methods of
Concurrency Control

8
Locking Methods of Concurrency Control
A lock is a variable, associated with the data item, which
controls the access of that data item.

Locks are further divided into three fields:


1. Lock Granularity
2. Lock Types
3. Deadlocks

9
Lock Granularity :
Lock granularity indicates the level of access to a database
defined by a lock manager.
Locking can take place at the following level :
1. Database level.
2. Table level.
3. Page level.
4. Row (Tuple) level.
5. Attributes (fields) level.
10
To be continued…
1. Database level: Only one transaction has access to the database.
2. Table level: Each table allows only one transaction to interact at a
time.
3. Page level: Number of rows locked across one or multiple tables.
4. Row(tuple) level: Each locked row allows one transaction to
interact with it at a time.
5. Attribute(field) level: Each locked attribute allows only one
transaction to interact with it at a time.

11
Lock Types:
The DBMS mainly uses following types of locking
techniques:
1. Binary Locking
2. Shared / Exclusive Locking
3. Two - Phase Locking (2PL)

12
Binary Locking: Shared/Exclusive Two-Phase
Locking : Locking (2PL):
Shared lock(s): Growing phase:
A binary lock can
have two states or Transaction locked In which a
values: locked and data item in shared transaction acquires
unlocked (or 1 and mode then allowed all the required
0, for simplicity). to read only. locks without
unlocking any data.
shrinking phase:
Operations: Exclusive lock(x):
In which a
1. Lock_item(X) Transaction locked
transaction releases
2.Unlock_item (X) data item in
all locks and cannot
exclusive mode then
obtain any new
allowed to read and
lock.  
write both. 13
3.
Deadlock

14
What is Deadlock in DBMS?
Bridge

A deadlock is an unwanted situation in which two or more


transactions are waiting indefinitely for one another to give
up locks.

15
Lets see an example….
Transaction A  =  access data items X and Y
Transaction B  =  access data items Y and X
• Transaction-A has acquired lock on X and is waiting to acquire lock on Y.
• Transaction-B has acquired lock on Y and is waiting to acquire lock on X.

A B
Req
ues
t

Hold
Hold

q uest
X Re Y

NONE OF THEM CAN EXECUTE FURTHER


16
Deadlock Avoidance
• Aborting a transaction is not always a practical approach. Instead,
deadlock avoidance mechanisms can be used to detect any
deadlock situation in advance.
• Deadlock avoidance method is suitable for smaller databases
whereas deadlock prevention method is suitable for larger
databases.
• One method of avoiding deadlock is using application-consistent
logic.
A B
Ac
qui
re

Hold
Hold

u ire
q
X Ac Y
17
Deadlock Detection
• When a transaction waits indefinitely to obtain a lock, The database
management system should detect whether the transaction is
involved in a deadlock or not. 
• Wait-for-graph
• In this method a graph is drawn based on the transaction and their
lock on the resource. If the graph created has a closed loop or a
cycle, then there is a deadlock.  Wait for Lock(X)

T1 T2

Wait for Lock(X) 18


Deadlock Prevention
• A deadlock can be prevented if the resources are allocated in such
a way that deadlock never occur.
• The DBMS analyses the operations whether they can create
deadlock situation or not, If they do, that transaction is never
allowed to be executed. 

1. Wait-Die Scheme
2. Wound Wait Scheme 

19
4.
Time-Stamp Methods
for Concurrency control

20
Timestamps must have two properties
namely :
1. Uniqueness :  The uniqueness property assures that
no equal timestamp values can exist.
2. Monotonicity  :  The monotonicity assures that
timestamp values always increase.

21
Example:
Suppose there are three transactions T1, T2, and T3.

T1 has entered at time 10:00


T2 has entered at time 10:05
T3 has entered at time 10:10

Priority will be given to transaction T1,


then transaction T2 and lastly Transaction T3.

22
Timestamp Ordering Protocol

• The timestamp of transaction Ti is denoted as TS(Ti).


• Read time-stamp of data-item X is denoted by
R-timestamp(X).
• Write time-stamp of data-item X is denoted by
W-timestamp(X).

23
• Suppose transaction Ti issues a read(X) operation:
• If TS(Ti) < W-timestamp(X)
Operation rejected.
• If TS(Ti) >= W-timestamp(X)
Operation executed.
• All data-item timestamps updated.

• Suppose transaction Ti issues a write(X) operation:


• If TS(Ti) < R-timestamp(X)
Operation rejected.
• If TS(Ti) < W-timestamp(X)
Operation rejected and Ti rolled back.
• Otherwise, operation executed.

24
Timestamp Ordering is divided
into further fields :

• Total Timestamp Ordering


• Partial Timestamp Ordering
• Multiversion Timestamp Ordering

25
Drawbacks of Time-stamp
• Each value stored in the database requires two
additional timestamp fields, one for the last time the
field (attribute) was read and one for the last update. 

• processing
It increases the memory requirements and the
overhead of database.

26
Thank You!

27

You might also like