Concurrency Control Flashcards
What is meant by pessimistic and optimistic techniques for concurrency control?
Pessimistic techniques are where we assume that something will go wrong if left unchecked. We will take proactive action to prevent it from happening in the first place.
Optimistic techniques, instead, simply hope that nothing will happen, and try to fix it afterwards.
What is meant by locking?
A ‘lock’ denies access to other transactions to prevent incorrect result. This is similar to the synchronized method in Java.
A transaction must manually issue read_lock or write_lock before any read. Then, a transaction must issue unlock afterwards to release it to other transactions.
What is meant by two-phase locking?
Two-phase locking is a technique where we allow our transactions to acquire and release locks in phases.
What is the growing phase in two-phase locking?
The growing phase is where new locks are able to be acquired, but none are allowed to be released.
What is the shrinking phase in two-phase locking?
The growing phase is where new locks are able to be released, but none are allowed to be acquired.
What is serialisability?
A system is serializable if and only if the results of the system would be the same regardless of which transaction started first. In other words - it is deterministic.
How does two-phase locking assure serialisability?
We ensure that all locks are acquired at the same time, meaning that our transactions will always run in the same order we specify it to.
What is an issue we may run into when dealing with two-phase locking, and why does it happen?
Because the transaction is not considered committed until all locks are released in the shrinking phase, if a transaction is waiting for another to finish, and it never does, we enter a state called deadlock, where we will hang forever.
What is a Wait-For-Graph, and how is it used to combat deadlock?
A Wait-For-Graph contains a node for each transaction, and a directed node from T1 to T2 if T1 is waiting to lock an item currently held by T2.
If the graph contains a cycle, the transaction contains a deadlock, and therefore we may detect and recover from this state by rolling back/aborting one of the transactions.
What is starvation?
If we always choose the same ‘victim’ to be rolled back, we may enter a state called starvation. This will cause the transaction to hog the lock, causing the shrinking phase to never end.
What are timeouts used for to prevent deadlock?
A transaction will wait for a database defined amount of time to acquire a lock. If the time runs out, the entire transaction gets rolled back and restarted.
How do we prevent a deadlock entirely using timestamping?
We timestamp each transaction. When a transaction requests a lock on a resource, if it is held by another transaction, we may ‘wound’ or ‘wait’ it based on its age in comparison to the holder. If we ‘wound’ it, it will abort and retry later with a new timestamp. If we ‘wait’ it, it will wait for the lock to be released.
What is the difference between wait-die and wound-wait algorithms?
Wait-die ‘wounds’ younger transactions making a request for a lock that is being held by an older transaction, while wound-wait wounds the older transaction instead.
What is the difference between timestamping and a timestamp?
A timestamp is a unique identifier created by the DBMS that indicates the starting time of a transaction, whereas timestamping is a protocol that orders transactions so that older transactions are given priority in the case of conflict.