Transactions Flashcards
What are the ACID properties?
Atomicity - either all operations of the transaction happens or none of it does
Consistency - execution of a transaction in isolation preserves the consistency of the database
Isolation - it appears to each transaction as though no other transactions are active at the same time
Durability - after a successful transaction, the changes persist after failures
Who are the responsible parties for ACID transactions?
AID: database
C: application
What are the 5 states a transaction can be in?
Active - initial state: the transaction stays in this state while it is executing
Partially committed - after the final statement (in the application logic) has been executed
Failed - after the discovery that normal execution can no longer proceed
Aborted - after the transaction has been rolled back. two options from here: restart or kill the transaction
Committed - after successful completion
What is a transient inconsistent state?
when the database is temporarily inconsistent during execution of a transaction
In what situation can two consecutive write/read on the same data instructions be swapped?
if A and B both read
can’t be done if
A reads and B writes
A writes and B reads
A and B both write
What is conflict equivalence?
Two schedules are conflict equivalent if one can be transformed into the other by a series of swaps of non-conflicting adjacent instructions. All conflict equivalent schedules give the same result.
When is a schedule conflict serialisable?
If it conflict equivalent to some serial schedule
how to draw a directed precedence graph? what is the significance of an edge?
add an edge from A to B if:
- A writes(q) before B reads(q)
- A writes(q) before B writes(q)
- A reads(q) before B writes(q)
an edge A -> B tells us that A must be executed before B in a serial schedule
if the graph has no cycles then the schedule can be conflict serialisable
what are the two locking modes?
exclusive(X). data can be written and read by only this transaction
shared(S). data can only be read, by buy all
in general: X locks require no locks on the thing and prevent all locks on the thing
describe the two phase locking protocol
ensures conflict serialisable schedules phase 1: growing - transaction may only obtain locks phase 2: shrinking - transaction may only release locks
ensures serialisablity
CAN ensure deadlock prevention if all transactions share phases
can have independant phases but doesn’t guarantee deadlock freedom
deadlocks can be determined using a wait-for graph
how can deadlocks be determined?
using a wait-for graph
A points to B if A is waiting for B to release an item
how can we recover from a deadlock?
transaction(s) will have to be rolled back
total rollback: abort the transaction and restart
more effective to partially rollback
when does starvation occur, how is it prevented
when a transaction is always chosen as the victim of a rollback. we can include the number of rollbacks in the cost factor of the rollback to avoid this
name 3 roll back schemes
total rollback
wait-die
- older transactions wait for younger ones
- younger ones will never wait for older ones, they are rolled back instead
- transactions may die several time
wound-wait
- older transaction “wounds” (forces the rollback of) the younger transaction instead of waiting for it
- younger transactioons may wait for older ones
timeout-based
- a transaction waits for a lock only for a specified amount of time
- after that the wait times out and the transaction is rolled back
describe the tree protocol
data items are organised into a tree
- only exclusive locks are allowed
- the first lock by A may be on any data item. subsequently data item X may only be locked by A if the parent of X is also locked by A
- data items may be unlocked at any time
- a data item that has been locked and unlocked cannot be relocked by the same transaction
ensures conflict serialisabilty as well as freedom from deadlock
however, a transaction may have to lock data items tehy dont need in order to access their children
a database has to be amenable to the tree structure