Lecture: Lecture 12 - Introduction to DBMS
Related: Reliability Manager Log Records Undo Redo and Checkpoints · Warm Restart Problem Solving and Cold Restart
Transaction
A transaction is a logical unit of work containing one or more reads or writes. A bank transfer is one transaction because subtracting money from one account and adding it to another must be treated as one operation.
COMMIT confirms successful completion. ROLLBACK cancels the transaction and restores the state from its beginning.
ACID
Atomicity
All operations happen, or none happen. If the debit succeeds but the credit fails, undo removes the debit.
Consistency
The transaction preserves integrity constraints. A foreign key must reference an existing row, a primary key must remain unique and a domain rule such as a non-negative balance must not be violated.
Isolation
Concurrent transactions should not produce incorrect interference. If two customers try to buy one remaining ticket, concurrency control must prevent both from successfully reserving it.
Durability
After commit, the result survives a crash. Log files and recovery can redo committed work that had not yet reached its final storage location.
Crash trace
- Transaction debits account X.
- The system crashes before crediting account Y.
- Recovery identifies the incomplete transaction.
- Undo removes the debit, or recovery completes the committed work when appropriate.
- The database returns to a correct state.
Common confusion
Atomicity prevents partial execution. Durability protects completed execution after a failure. Isolation concerns interactions between concurrent transactions. Consistency concerns database rules and valid states.
Retrieval questions
Why is a transfer one transaction? Its component updates must succeed or fail together.
What does rollback do? It restores the database to the state before the transaction began.
Which ACID property protects a committed payment after a power failure? Durability.