Locking can be done upon objects at various level of granularity (tables, sets, whole database)
The objective is to:
A typical hierarchy can be:
The lower we put the lock, the higher is concurrency, but also lock manager load is higher.
We have 5 lock modes:
Also intention of locking at lower levels of granularity is defined:
ISL | IXL | SL | SIXL | XL | |
---|---|---|---|---|---|
ISL | OK | OK | OK | OK | NO |
IXL | OK | OK | NO | NO | NO |
SL | OK | NO | OK | NO | NO |
SIXL | OK | NO | NO | NO | NO |
XL | NO | NO | NO | NO | NO |
This way i can identify the conflicts based on the requests of the resources.
Transaction 1: IXL(root)
read(P1) SIXL(P1)
write(t3) XL(t3)
read(t8) ISL(P2) SL(t8)
Page 1 | Page 2 |
---|---|
t1 read | t5 |
t2 read | t6 |
t3 write | t7 |
t4 read | t8 read |
Transaction 2: IXL(root) ISL(P1)
read(t2) SL(t2)
read(t4) SL(t4)
write(t5) IXL(P2) XL(t5)
write(t6) XL(t6)
Page 1 | Page 2 |
---|---|
t1 | t5 write |
t2 read | t6 write |
t3 | t7 |
t4 read | t8 |
The two transactions (read and write operations) are compatible, in fact we have one type of lock for each resource.
Occurs because concurrent transactions hold and, in turn, require resources held by other transactions
A deadlock is represented by a cycle in the wait-for graph of the resources
A transaction is killed after given waiting, assuing it is involved in a deadlock.
Is the simplest, most used method
Timeout value is system-determined, the problem is choosing a proper value:
A possible scheme is:
Options for choosing the transaction to kill:
The problem: too many killings (waiting probability vs deadlock probability)
Deadlock prevention is not used because in any case it generates many killings.
Requires an algorithm to find real cycles in the wait-for graph It consumes resources but works well and is the solution used.