Dbms Unit - 5 (Concurrency Control)
Dbms Unit - 5 (Concurrency Control)
occurs in case all the database operations are not completed due to some
are multiple resources or users are accessing the data element and
performing the database operations. There are several enterprise systems
such as banking, ticket booking, and traffic light systems that use a
control in DBMS.
1. Lock based
The lock-based protocol is the technique of applying lock condition on
read and write operation until the lock is active. There are mainly two
2. Validation based
The validation based protocol is also known as an optimistic
3. Timestamp based
The timestamp-based protocol uses system time or logical count as a
4. Two-phase protocol
The two-phase protocol (2PL) is a locking mechanism that ensures
expanding phase and shrinking phase to acquire and release the lock
1. Dirty Read
Dirty read or temporary update problems happen while there is an
updated by one transaction and filed before completing it. And another
Transaction T1 Transaction T2
Read(X) Read(X)
X=X+n1
Write(X)
Write(X)
operation Failed
the Value X using a numeric value n with Write (X-n) operation. While
the write operation in action, it got interrupted and not yet reverted to the
(X) operation that represents the value as X-n. This results in a dirty read
problem.
2. Unrepeatable Read
Unrepeatable Read is the scenario where two or more read operations
read the same variable as different values and that value is modified by a
Transaction T1 Transaction T2
Read(X) Read(X)
X=X-n Read(X)
Write(X)
numeric value n, At the Same time T2 reads the value X and captures the
3. Phantom Read
Phantom read problem refers to the scenario where the Transaction reads
a variable once and when it tries to read the variable again it gets an
error showing the variable does not exist, as the variable is deleted by
another transaction.
Transaction T1 Transaction T2
Read(X) Read(X)
Delete(X) Read(X)
able to find the variable. This results in the phantom read problem.
4. Lost updates
Lost updates are the concurrency problem scenario where modification
another transaction.
Transaction T1 Transaction T2
Read(X) X=X+n1
X=X+n Write(X)
Explanation: The Table shows the T1 reads the variable X and modifies
transaction.
5. Incorrect Summary
An incorrect Summary problem in concurrency control scenario appears
Read(X) Read(X)
Sum=0 X=X+n
Sum=Sum+X Write(X)
Conclusion
Concurrency Control in DBMS is a very useful technique to maintain
conflicts
Lock-Based Protocol
1. Shared lock:
2. Exclusive lock:
o In the exclusive lock, the data item can be both reads as well
as written by the transaction.
o This lock is exclusive, and in this lock, multiple transactions
do not modify the same data simultaneously.
Example:
The following way shows how unlocking and locking work with 2-
PL.
Transaction T1:
Transaction T2:
1. Read Phase:
Values of committed data items from the database can
be read by a transaction. Updates are only applied to
local data versions.
2. Validation Phase:
Checking is performed to make sure that there is no
violation of serializability when the transaction updates
are applied to the database.
3. Write Phase:
On the success of the validation phase, the transaction
updates are applied to the database, otherwise, the
updates are discarded and the transaction is slowed
down.
r(x) // x=12
r(x)
x=x-10
r(y) //y=15
y=y+10
r(x)
<validate>
print(x+y)
Tj Ti
<validate>
w(x)
w(y)
Schedule-A is a
validated schedule
Advantages:
1. Avoid Cascading-rollbacks: This validation based scheme
avoid cascading rollbacks since the final write operations to the
database are performed only after the transaction passes the
validation phase. If the transaction fails then no updation
operation is performed in the database. So no dirty read will
happen hence possibilities cascading-rollback would be null.
2. Avoid deadlock: Since a strict time-stamping based
technique is used to maintain the specific order of transactions.
Hence deadlock isn’t possible in this scheme.
Disadvantages:
1. Starvation: There might be a possibility of starvation for long-
term transactions, due to a sequence of conflicting short-term
transactions that cause the repeated sequence of restarts of the
long-term transactions so on and so forth. To avoid starvation,
conflicting transactions must be temporarily blocked for some
time, to let the long-term transactions to finish.
Multiple Granularity
that version.
value.
Now let us understand this concept using an example.
X 10
X 10 15
Now let’s discuss some important cases:
of T1 then
contents.