- 2074 Chaitra · 4+4 marks
Locks in transactions; lost update
Short answer
Locks guarantee serial equivalence with 2PL, prevent dirty reads and cascading aborts with strict locking. Drawbacks are deadlock, overhead, and reduced concurrency. Lost update occurs when two transactions read the same value and both write, overwriting each other; for example, account 100, T adds 10, U adds 20, final 120 not 130. Exclusive lock prevents it.
What are the benefits and drawbacks of using lock in Transaction Processing? Explain the lost-update problems with suitable example.
Locks in transaction processing
A lock is a variable associated with a data item that controls concurrent access. A transaction must obtain the lock before it reads or writes the item, and releases it when finished. Common modes are read (shared) lock and write (exclusive) lock; several transactions can hold read locks together, but a write lock excludes all others. In two-phase locking (2PL) a transaction has a growing phase (acquires locks) followed by a shrinking phase (releases locks, never acquires again). Strict 2PL holds all locks until commit or abort, which prevents dirty reads and cascading aborts.
Benefits
- They guarantee serial equivalence (isolation) when 2PL is used.
- Simple, well-understood and widely implemented.
- Strict locking prevents dirty reads and cascading aborts.
Drawbacks
- Deadlock can occur when transactions wait for each other in a cycle.
- Lock management has overhead (lock table, acquiring and releasing).
- Locks reduce concurrency; short transactions wait for long ones.
- Locks may be held across a network in distributed systems, and a crashed holder blocks others until timeout.
- Early release (non-strict) can cause cascading aborts.
Lost update problem
The lost update problem occurs when two transactions read the same value and both write back results based on it, so one update overwrites the other.
Example: account A has Rs 100. T reads A (100) and adds Rs 10; U reads A (100) and adds Rs 20.
T: bal = A.get() -> 100
U: bal = A.get() -> 100
T: A.set(bal + 10) -> 110
U: A.set(bal + 20) -> 120 (T's update is lost)
The correct final value is 130 in any serial order. Locking prevents this: with an exclusive lock on A, U cannot read A until T commits and releases the lock, so U sees 110 and writes 130.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Parent-child transactions; locking problems · Distributed System, chapter 8
- Lock; distributed CC; deadlock situation · Distributed System, chapter 8
- Transaction, nested transaction, atomicity · Distributed System, chapter 8
- Flat/nested transactions; optimistic CC · Distributed System, chapter 8
- Nested vs distributed transaction; 2PC · Distributed System, chapter 8 · asked 2×
- Distributed and nested distributed transactions · Distributed System, chapter 8
- Random access file transaction processing · Object Oriented Programming, chapter 8
- Benefits and problems of reuse; reuse planning · Software Engineering, chapter 5
- Interpret: computers and word processing · Communication English, chapter 1
- Apriori on 8 transactions, 25% support · Data Mining, chapter 4