2: Locks Flashcards Preview

207: Databases > 2: Locks > Flashcards

Flashcards in 2: Locks Deck (11)
Loading flashcards...
1

What is a lock ?

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.

2

What is the point of a lock ?

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

3

Who manages locking procedures ?

DMBS lock manager initiates and enforces the procedures.

4

At which levels can lock granularity take place?

Database, table, page, row, attribute

5

What are the two lock types?

- 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.

6

What are the two main locking issues ?

Locks prevent data inconsistencies but can cause transactions to be:

- Non-serialisable
- Deadlocks

7

What can be used to solve locking issues ?

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.

8

What are deadlocks ?

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.

9

What are the 3 ways to control deadlocks ?

- 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.

10

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

No – deadlock occurs on exclusive lock issues.

11

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

I. Timeout

and

IV. Wait-For Graph