Concurrency Control Flashcards

1
Q

What is meant by pessimistic and optimistic techniques for concurrency control?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is meant by locking?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is meant by two-phase locking?

A

Two-phase locking is a technique where we allow our transactions to acquire and release locks in phases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the growing phase in two-phase locking?

A

The growing phase is where new locks are able to be acquired, but none are allowed to be released.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the shrinking phase in two-phase locking?

A

The growing phase is where new locks are able to be released, but none are allowed to be acquired.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is serialisability?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does two-phase locking assure serialisability?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an issue we may run into when dealing with two-phase locking, and why does it happen?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Wait-For-Graph, and how is it used to combat deadlock?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is starvation?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are timeouts used for to prevent deadlock?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we prevent a deadlock entirely using timestamping?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between wait-die and wound-wait algorithms?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between timestamping and a timestamp?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly