2: Locks Flashcards

1
Q

What is a lock ?

A

A transaction can acquire a lock on a data item prior to accessing that item.

This guarantees exclusive use of that item, and the lock is released when the transaction is complete.

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

What is the point of a lock ?

A

Locks prevent other transactions from reading inconsistent data, as this cannot be guaranteed during a transaction.

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

Who manages locking procedures ?

A

DMBS lock manager initiates and enforces the procedures.

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

At which levels can lock granularity take place?

A

Database, table, page, row, attribute

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

What are the two lock types?

A
  • Binary locks: 2 states (1 locked, 0 unlocked), has to unlock after termination
  • Shared/ Exclusive locks: shared allows other transactions to read the object, exclusive only the chosen one.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two main locking issues ?

A

Locks prevent data inconsistencies but can cause transactions to be:

  • Non-serialisable
  • Deadlocks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can be used to solve locking issues ?

A

Two Phase Locking Protocol (2PL).

It uses a ‘growing phase’ to acquire all the locks w/o unlocking any that time, and then conversely uses a ‘shrinking time’ to release them without locking anything else in the meantime.

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

What are deadlocks ?

A

T1 accesses items X and Y whilst T2 accesses items Y and X and neither has unlocked each others’ required item.

May happen if one of the transactions wants an exclusive lock on an item.

Does not occur amongst shared locks.

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

What are the 3 ways to control deadlocks ?

A
  • Deadlock Prevention: transaction requesting a new lock is aborted if there is possibility of deadlock. Abort rolls back the transaction and releases all of its locks that are being held at the time. (Wow, this like in the Flash)
  • Deadlock Detection: DMBS tests for deadlocks and aborts one of transactions whilst allowing the other to continue
  • Deadlock Avoidance: Transaction must obtain all locks before it can execute. This avoids rollback but may be slower due to having to acquire all locks that are needed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can deadlock occur when a transaction requests a shared lock on an item?

A

No – deadlock occurs on exclusive lock issues.

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

Which of the following can be used for deadlock detection?

I. Timeout
II. Precedence Graph
III. 2PL Protocol
IV. Wait-For Graph
V. Rolling back a transaction
A

I. Timeout

and

IV. Wait-For Graph

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