What Is Concurrency Control
What Is Concurrency Control
Concurrency control is used to address such conflicts which mostly occur with
a multi-user system. It helps you to make sure that database transactions are
performed concurrently without violating the data integrity of respective
databases.
Lost Updates occur when multiple transactions select the same row
and update the row based on the value selected
Uncommitted dependency issues occur when the second transaction
selects a row which is updated by another transaction (dirty read)
Non-Repeatable Read occurs when a second transaction is trying to
access the same row several times and reads different data each time.
Incorrect Summary issue occurs when one transaction takes
summary over the value of all the instances of a repeated data-item,
and second transaction update few instances of that specific data-item.
In that situation, the resulting summary does not reflect a correct result.
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, 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.
Lock-Based Protocols
Two Phase
Timestamp-Based Protocols
Validation-Based Protocols
Lock-based Protocols
A lock is a data variable which is associated with a data item. This lock
signifies that operations that can be performed on the data item. Locks help
synchronize access to the database items by concurrent transactions.
Binary Locks: A Binary lock on a data item can either locked or unlocked
states.
A shared lock is also called a Read-only lock. With the shared lock, the data
item can be shared between transactions. This is because you will never have
permission to update data on the data item.
For example, consider a case where two transactions are reading the account
balance of a person. The database will let them read by placing a shared lock.
However, if another transaction wants to update that account's balance,
shared lock prevent it until the reading process is over.
With the Exclusive Lock, a data item can be read as well as written. This is
exclusive and can't be held concurrently on the same data item. X-lock is
requested using lock-x instruction. Transactions may unlock the data item
after finishing the 'write' operation.
Starvation
Deadlock