Transaction MGT 2
Transaction MGT 2
management-II
Transaction Failure
Transaction Failure
A transaction failure occurs when a transaction cannot complete
successfully due to errors, system crashes, or conflicts. Types of failures
include:
• Logical Errors: Incorrect data, integrity constraint violations, or
deadlocks.
• System Crashes: Hardware/software failures, power outages.
• Deadlocks: Multiple transactions waiting indefinitely for each other’s
locks.
Shadow Paging
• Maintains two copies of the database (current and shadow).
• Changes are made in the shadow copy; only committed
changes replace the current copy.
Concurrency Control in Databases
Concurrency control ensures correct execution of multiple
transactions simultaneously while maintaining ACID
properties.
Problems Due to Lack of Concurrency Control
• Lost Update: Two transactions overwrite each other’s
changes.
• Dirty Read: A transaction reads uncommitted data from
another transaction.
• Non-Repeatable Read: A transaction reads the same data
twice but gets different values.
• Phantom Read: New rows appear in a re-executed query.
Concurrency Control Techniques
Lock-Based Protocols
• Shared Lock (S-lock): Allows multiple transactions to read
but not write.
• Exclusive Lock (X-lock): Allows only one transaction to
read/write.
• Two-Phase Locking (2PL): Ensures serializability by dividing
transactions into growing (acquire locks) and shrinking
(release locks) phases.
Example (2PL)
Consider two transactions T1and T2:
Correct 2PL Execution:
• T1acquires X-lock on A (Growing Phase).
• T1writes A.
• T1acquires X-lock on B (still Growing Phase).
• T1writes B.
• T1releases X-lock on A (Shrinking Phase begins).
• T1releases X-lock on B and commits.