Unit 3 - 1
Unit 3 - 1
• A transaction may be granted a lock on an item if the requested lock is compatible with
locks already held on the item by other transactions
• Any number of transactions can hold shared locks on an item,
But if any transaction holds an exclusive on the item no other transaction may hold any
• Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3 to
release its lock on B, while executing lock-X(A) causes T3 to wait for T4 to release its lock
on A.
• Such a situation is called a deadlock.
• To handle a deadlock one of T3 or T4 must be rolled back
and its locks released.
CS3492/Database Management Systems /II CSBS/IV SEM/KG-KiTE
Deadlocks (Cont.)
• Two-phase locking does not ensure freedom from deadlocks.
• In addition to deadlocks, there is a possibility of starvation.
• Starvation occurs if the concurrency control manager is badly designed. For example:
• A transaction may be waiting for an X-lock on an item, while a sequence of other
transactions request and are granted an S-lock on the same item.
• The same transaction is repeatedly rolled back due to deadlocks.
• Concurrency control manager can be designed to prevent starvation.
• Variant: “First-updater-wins”
• Check for concurrent updates when write occurs by locking item
• But lock should be held till all concurrent transactions have finished
• (Oracle uses this plus some extra features)
• Differs only in when abort occurs, otherwise equivalent
CS3492/Database Management Systems /II CSBS/IV SEM/KG-KiTE
Benefits of SI
• Reading is never blocked,
• and also doesn’t block other txns activities
• Performance similar to Read Committed
• Avoids the usual anomalies
• No dirty read
• No lost update
• No non-repeatable read
• Predicate based selects are repeatable (no phantoms)
• Problems with SI
• SI does not always give serializable executions
• Serializable: among two concurrent txns, one sees the effects of the other
• In SI: neither sees the effects of the other
• Result: Integrity constraints can be violated
CS3492/Database Management Systems /II CSBS/IV SEM/KG-KiTE
Snapshot Isolation
• E.g. of problem with SI
• T1: x:=y
• T2: y:= x
• Initially x = 3 and y = 17
• Serial execution: x = ??, y = ??
• if both transactions start at the same time, with snapshot isolation: x = ?? , y =
??
• Called skew write
• Skew also occurs with inserts
• E.g:
• Find max order number among all orders
• Create a new order with order number = previous max + 1