Locking Flashcards

1
Q

Locking

A

Used to enforce conflict serialisability.

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

Simple Lock Mechanism

A

Used to ensure that a transaction has to lock an item before it can access it, which are requested and granted by the scheduler.
Each item is locked at most one transaction at a time, and transactions wait until a lock can be granted.
These locks have to be released eventually.
This is SIMILAR in theory to what serialization does in terms of setting the isolation of the transaction.

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

Lock Denoted

A

Locking -> l_i(x)
Unlocking -> u_i(x)

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

Example of locking

A

l_1(x) would request the lock for transaction one for the item x.
u_1(x) would release this lock.
If there was a l_2(x) between these two, then transaction two will have to wait for transaction one to finish what it is doing.

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

Two Phase Locking

A

All lock operations in each transaction precede all unlocks.
Phase 1 is requesting locks, and phase 2 is unlocking.
So in other words, there cannot be an unlock which happens before a lock, even if they lock/unlock different things.

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

Deadlocks

A

Transactions may be forced to wait forever.
If we take the example above, if transaction 2 starts before transaction 1 can get to locking y, then neither can proceed forward since we are waiting for either of them to release their locks.

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

Deadlock Solution

A

Using more flexible locks.

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

Shared Locks (read-locks)

A

Requested by transactions to read an item x.
Granted to several transactions at the same time.
Operation : s-lock(x)
Shared lock on x is granted only if no other transactions hold the exclusive lock for x.

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

Exclusive Locks (write-locks)

A

Requested by transactions to write an item x.
Granted to at most one transaction at a time.
Operation : x-lock(x)
Shared lock on x is granted only if no other transactions hold ANY lock for x.

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

Upgrading Locks

A

A shared lock on item x can be upgraded later to an exclusive lock on x i order to be friendly to other transactions.

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

Deadlock Solution (Shared and exclusive locks)

A

Using shared and exclusive locks can still lead to deadlock. For example:
sl_1(x), r_1(x), sl_2(x), r_2(x)
If both transactions have xl_i(x) after them, then since it requires X having no locks, we are stuck in deadlock.

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

Update Lock

A

Requested by transactions to read (not write) an item, and may be upgraded to exclusive locks.
Granted to at most on transaction at a time.
Operation : u-lock(x)

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

Upgrade System

A

If you have a shared lock, you can upgrade to update lock, but not vice versa (you cannot upgrade from update to shared lock).
We cannot use exclusive locks at all from either shared locks or upgrade locks.
You can go from shared lock to shared lock, but not update lock to update lock.

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

Locking too broadly

A

Low overhead (less locks to be stored, aka less information), but less degree of concurrency (since less locks may cause more concurrent schedules, and may cause delays).

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

Locking too finely

A

High overhead since we have more locks, but high degree of concurrent with no delays.

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

Intention Locks

A

IS requests a shared lock on a sub-item whilst IX requests an exclusive lock on a sub-item.