Database Concurrency
Database Concurrency
Database Concurrency
DATABASE
SYSTEMS
DEVELOPMENT
[CC6001]
WEEK - 06
Database Concurrency
There are three sides of ACID.
ENHANCED LONG TERM MEMORY
DECREASED SHORT TERM MEMORY
AND I FORGOT THE THIRD
- TIMOTHY LARY
Requirement
MOST OF THE
CASES, DATABASE IS
ACCESSED BY
MULTIPLE USERS AT A
TIME
Concurrency Control
ENSURES THAT
CONCURRENT
OPERATIONS ARE
CARRIED OUT
CORRECTLY
EFFICIENTLY
Example
Begin Transaction T1
Read Balance1
Balance1 = Balance1 – 100
If Balance <0
Print insufficient fund
Abort T1
End
Write Balance1
Read Balance2
Balance2 = Balance2 +100
Write Balance2
Commit T1
Points to Remember
Single Multi
Transaction Transaction
Environment Environment
Interleaved Transactions
The operations of the two transactions TA and TB are
said to be interleaved to achieve concurrent execution.
Lost Update
Violation of Integrity
Constraints
Inconsistent Retrieval
Lost Update
two concurrent transactions, say TA and TB, are
allowed to update an uncommitted change on the
same data item, say x.
400
Violation of Integrity Constraints
Integrity Constraint - Question
200
Inconsistent Retrieval
Serialization
Constraints
must be
specified by
DBA using
Concurrency Control
appropriate
language
Transaction Scheduling
Serialization
ONE
Process Disadvantage
TRANSACTI
ON MUST
• Permits SERIAL • Inefficient for COMMIT
EXECUTION of MULTI USER
TRANSACTIONS environment BEFORE
ANOTHER
CAN START.
Concurrency Control
Process Mechanisms
• X (Write) • S (Read)
• Grant read/write access to a • Grant read only access to a
data item to the transaction data item to the transaction
which holds the lock which holds the lock
• Prevent any other transactions • Prevent any transaction
reading or writing the same writing data item.
data item. • Several transactions may hold
a S lock on the same data
item.
Locking Protocol
A transaction must get an S lock on a data item before it wishes to READ it
A transaction must get an X lock on a data item before it wishes to WRITE it
A TRANSACTION already holding an S lock on a data item can promote
itself to an X lock in order to WRITE it, provided there is no other transaction
also holding an S lock on it already.
If a lock request is denied, the transaction goes into a WAIT state
A transaction in a WAIT state resumes operations only when the requested
lock is released by another transaction
X locks are held until COMMIT/ROLLBACK. S locks are normally the same.
Lock Compatibility Matrix
Before operating on
any object (a tuple), a
transaction must
acquire a lock on that
object If all transactions obey
Protocol Theorem the “two–phased
locking protocol”, then
all possible interleaved
schedules are
After releasing a lock a serializable
transaction must never
go on to acquire any
more locks.
Lost Update – Example Revisited
Lost Update – Example Revisited
CORRECT ANSWER
Thank You