Transactions and ACID Flashcards
Transactions
A sequence of queries.
BEGIN Transaction
…
COMMIT
ACID
- atomicity
- consistency
- isolation
- durability
Atomicity
Guarantees each transaction to be treated as a single unit (everything happens in a transaction or nothing happens).
Consistency
Ensures that a transaction can only bring the database from one consistent state to another; any data wrote must be valid according to all defined rules. A strong way of defining consistency is to say that it should correctly transform the database state to reflect the effect of a real world event.
Isolation
Transactions are executed concurrently; if one transaction starts, and then another one starts and finishes which changes the database itself, the original transaction is not effected (will act on the previous version of the database).
Durability
Guarantees that if a transaction has been committed, it will stay committed even if the system fails.
Types of Isolation
- read uncommitted
- read committed
- repeatable read
- serialisable
Read Uncommitted
Fine to read uncommitted data.
Read Committed
Can only read committed data.
Repeatable Read
If you read the same thing twice in a transaction, you must get the same return value.
Serialisable
Transactions can be performed in a serial manner.
Transaction may abort because of…
- Due to integrity constraints, or other run-time errors etc. For example, poor concurrency (two people book the same flight at the same time).
- Deadlocks when using two-phase locking.
- Explicit request -> rollbacks.
- Media failures -> the medium holding the database becomes unreadable (change of bits, head crash). Safeguards include RAID or archives/copies.
- Catastrophic failures -> the medium is destroyed (explosion, fires). Safeguards include archives and copies at safe/different location.
- System failures -> information about active transition’s state is lost (power failure, software error).