Transactions Flashcards
What does the A stand for in ACID?
Atomicity: Either all of the transaction should occur or none of it
What does the C stand for in ACID?
Consistency: The transaction should not leave the database in an inconsistent state
What does the I stand for in ACID?
Isolation: Transactions shouldn’t be aware of other transactions
What does the D stand for in ACID?
Durability: All changes made to the database should be persisted to storage.
What are the 5 transaction states?
- Active
- Partially committed
- Committed
- Failed
- Aborted
When is the transaction in the Active state
The initial state and the state the transaction stays in while executing.
When is the transaction in the partially committed state?
After the final statement in the application logic has been executed.
When is the transaction in the committed state?
After successful completion of the transaction.
When is the transaction in the failed state?
After the discovery normal executing can no longer proceed.
When is the transaction in the aborted state?
After the roll back occurs and the database is back in its state prior to the start of the transaction. Two options after abort:
Restart transaction
Kill the transaction
What is a schedule?
Order in which instructions of transactions are executed. Must consist of all instructions for scheduled transactions and preserve their order.
What is a serial schedule?
Transactions are run serially to completion - ensure consistency.
What are non-serial schedules?
Used for concurrent execution, doesn’t always give consistent results.
Why do we need equivalent schedules?
Need to have non-serial schedules function like a serial scheduler in order to have consistent database.
When are two schedules conflict equivalent?
IF:
- One can be transformed into the other by a series of swaps of non-conflicting adjacent instructions.
- It is conflict equivalent to some serial schedule.
How do we construct a directed precedence graph?
Add edge between any vertices that can’t be swapped for a data item (AKA anything that isn’t 2 reads).
What does each edge in a directed precedence graph mean?
Ti-> Tj,
Ti must be executed before Tj in any serial schedule S’ == S
What happens if a directed precedence graph has no cycles?
Schedule is conflict serialisable
When there are cycles in a directed precedence graph, what does that mean?
The schedule is not conflict serialisable.
What modes of locking are there?
Exclusive, lock-X. R/W
Shared, lock-S. R only
What is a locking protocol?
Set of rules followed by all transactions while requesting and releasing locks. Restrict the set of possible schedulers. Deadlocks and starvation may occur.
How are deadlocks and starvation related?
Deadlocks cause rollbacks of the lowest-valued transaction. If the same one is constantly rolled back then it is starved.
How does the 2-phase locking protocol work?
Phase 1: Growing phase. Transaction may only obtain locks.
Phase 2: Shrinking phase. Transaction may only release locks.
What are the advantages of having a 2 phase locking protocol?
Transaction execution schedulers are equivalent to serial schedulers in order of their lock points
What is a lock point?
Point where transaction acquired its final lock.
How do we construct wait for graphs?
When Ti is waiting for Tj to release a data item, then we draw an edge.
How do we recover from deadlocks?
Roll back transaction to break deadlock.
How does the wait-die scheme work?
Older transaction wait for younger to release data item, younger transaction never wait for old ones - roll back instead.
How does the wound-wait scheme work?
Older transaction “wounds” (forces rollback of) younger transactions. Younger transactions may wait for older ones.
How do timeout-based schemes work?
A transaction waits for a lock for a specified amount of time, after which it rolls back.
How do Graph-based protocols work?
Impose partial ordering on the set. If di -> dj then acquiring a lock on dj is only allowed if a lock on the parent Di is obtained first.