Concurrency Control
Concurrency Control
Concurrency Control
• Dirty read
• Unrepeatable read
• Lost updates
Dirty read
• Reading the data written by an
uncommitted transaction is called as dirty
read
• In this example,
• T2 reads the dirty value of A written by
the uncommitted transaction T1.
• T1 fails in later stages and roll backs.
• Thus, the value that T2 read now stands to
be incorrect.
• Therefore, database becomes
inconsistent.
Unrepeatable read
• This problem occurs when a transaction
gets to read unrepeated i.e. different
values of the same variable in its
different read operations even when it
has not updated its value. Example:
• T1 reads the value of X (= 10 say).
• T2 reads the value of X (= 10).
• T1 updates the value of X (from 10 to 15
say) in the buffer.
• T2 again reads the value of X (but = 15).
Lost updates(w/w conflict)
• This problem occurs when multiple
transactions execute concurrently and
updates from one or more transactions get
lost. example:
• T1 reads the value of A (= 10 say).
• T2 updates the value to A (= 15 say) in the
buffer.
• T2 does blind write A = 25 (write without
read) in the buffer.
• T2 commits.
• When T1 commits, it writes A = 25 in the
database.
Reasons for using Concurrency control
method is DBMS:
• To apply Isolation through mutual exclusion between conflicting
transactions
• To resolve read-write and write-write conflict issues
• To preserve database consistency through constantly preserving
execution obstructions
• The system needs to control the interaction among the concurrent
transactions. This control is achieved using concurrent-control
schemes.
• Concurrency control helps to ensure serializability
Conflict Example
• You and your brother have a joint bank account, from which you both
can withdraw money. Now let’s say you both go to different branches
of the same bank at the same time and try to withdraw 5000 INR,
your joint account has only 6000 balance. Now if we don’t have
concurrency control in place you both can get 5000 INR at the same
time but once both the transactions finish the account balance would
be -4000 which is not possible and leaves the database in inconsistent
state.
Solution of Conflicts: Locks