LOCKING AND TIME STAMPS Flashcards

1
Q

What is locking?

A

A procedure used to control concurrent access to data. When one transaction is accessing the database, a lock may deny access to other transactions to prevent incorrect results.
In this method, a scheduler uses the locks to ensure serializability

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

How does a transaction obtain a lock?

A

Transactions must request and release locks in addition to reading and writing database elements.
A transaction obtains locks on the database elements it accesses , to prevent other transactions from accessing these elements, at roughly the same time, thereby incurring the risk of un-serializability .

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

What are the two types of locks?

A
  1. Shared lock If a transaction has a shared lock on a data item, it can read the item but not update it. Since read operations cannot conflict, it is permissible for more than one transaction to hold shared locks simultaneously on the same item
  2. Exclusive lock If a transaction has an exclusive lock on a data item, it can both read and update the item. As long as a transaction holds the exclusive lock on the item, no other transactions can read or update that data item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are locks used?

A

Any transaction that needs to access a data item must first lock the item, requesting a shared lock for read only access or an exclusive lock for both read and write access.

If the item is not already locked by another transaction, the lock will be granted.

If the item is currently locked, the DBMS determines whether the request is compatible with the existing lock.
If a shared lock is requested on an item that already has a shared lock on it, the request will be granted; otherwise, the transaction must wait until the existing lock is released

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

When is a lock released

A

A transaction continues to hold a lock until it explicitly releases it either during execution or when it terminates (aborts or commits). It is only when the exclusive lock has been released that the effects of the write operation will be made visible to other transactions

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

Describe an incorrect locking Schedule

A

*See doc for pic

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

What is two-phase locking (2PL)?

A

A protocol concerning the positioning of the lock and unlock operations in every transaction in order to guarantee conflict serializability.

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

What is conflict serializability?

A

A schedule is called conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations.

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

What are conflicting operaions?

A

Conflicting operations: Two operations are said to be conflicting if all conditions satisfy:

They belong to different transactions
They operate on the same data item
At Least one of them is a write operation

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

What are the two phases of a transaction according to 2PL?

A
  • Growing phase, in which it acquires all the locks needed but cannot release any locks.
  • Shrinking phase, in which it releases its locks but cannot acquire any new locks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the rules of 2PL?

A
  • A transaction must acquire a lock on an item before operating on the item. The lock maybe read or write, depending on the type of access needed.
  • Once the transaction releases a lock, it can never acquire any new locks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe how 2PL can prevent lost update problem, uncommitted dependency problem and inconsistent analysis problem using 2PL

A

*See phone for pics

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

What is a deadlock?

A

several transactions are forced by the scheduler to wait for a lock held by another transaction
Results when two (or more) transactions are each waiting for locks to be released that are held by the other.

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

How can one break deadlock?

A

Abort one or more of the transactions usually involving undoing all the changes made by aborted transaction(s)

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

Describe deadlock prevention and how is it carried out?

A

DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur.

Could order transactions using transaction timestamps:

Wait-Die - only an older transaction can wait for younger one, otherwise transaction is aborted (dies) and restarted with same timestamp.
Wound-Wait - only a younger transaction can wait for an older one. If older transaction requests lock held by younger one, younger one is aborted (wounded).

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

Describe deadlock detection and recovery?

A

DBMS allows deadlock to occur but recognizes it and breaks it.
Usually handled by construction of wait-for graph (WFG) showing transaction dependencies:
Create a node for each transaction.
Create edge Ti -> Tj, if Ti waiting to lock item locked by Tj.
Deadlock exists if and only if WFG contains cycle.
WFG is created at regular intervals

17
Q

Describe timeouts as a method of deadlock detection and recovery

A

Transaction that requests lock will only wait for a system-defined period of time.
If lock has not been granted within this period, lock request times out.
In this case, DBMS assumes transaction may be deadlocked, even though it may not be, and it aborts and automatically restarts the transaction

18
Q

Describe time stamping

A

Transactions ordered globally so that older transactions, transactions with smaller timestamps, get priority in the event of conflict.

Conflict is resolved by rolling back and restarting transaction.

No locks so no deadlock.

19
Q

What are the advantages and disadvantages of locks and timestamps

A
Locks:
Great when there are many conflicts
Poor when there are few conflicts
Great for read/write transactions.
Timestamps:
Poor when there are many conflicts (many rollbacks)
Great when there are few conflicts
Great for read only transactions
20
Q

How does 2PL guarantee conflict serializability

A

Each Xact must obtain a S (shared) lock on object before reading, and an X (exclusive) lock on object before writing.
 A transaction can release its locks once it has performed its desired operation (R or W). A transaction cannot request additional locks once it releases any locks.
 If an Xact holds an X lock on an object, no other Xact can get a lock (S or X) on that object. lock).

21
Q

unrepeatable read problem?

A

The unrepeatable problem occurs when two or more read operations of the same transaction read different values of the same variable.
EG. T1 Read(x), T2 Read(x), T1 Write(x), T2 Read(x)