Professional Documents
Culture Documents
CH 16
CH 16
Lock-Based Protocols
Timestamp-Based Protocols
Validation-Based Protocols
Multiple Granularity
Multiversion Schemes
Deadlock Handling
Insert and Delete Operations
Concurrency in Index Structures
16.1
Lock-Based Protocols
A lock is a mechanism to control concurrent access to a data item
Data items can be locked in two modes :
16.2
16.3
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
Locking as above is not sufficient to guarantee serializability if A and B
get updated in-between the read of A and B, the displayed sum would be
wrong.
16.4
16.5
starvation.
16.6
16.7
16.8
16.9
Lock Conversions
Two-phase locking with lock conversions:
First Phase:
can acquire a lock-S on item
can acquire a lock-X on item
can convert a lock-S to a lock-X (upgrade)
Second Phase:
can release a lock-S
can release a lock-X
can convert a lock-X to a lock-S (downgrade)
This protocol assures serializability. But still relies on the
16.10
if Ti has a lock on D
then
read(D)
else
begin
if necessary wait until no other
transaction has a lock-X on D
grant Ti a lock-S on D;
read(D)
end
Database System Concepts 3rd Edition
16.11
if Ti has a lock-X on D
then
write(D)
else
begin
if necessary wait until no other trans. has any lock on D,
if Ti has a lock-S on D
then
upgrade lock on D to lock-X
else
grant Ti a lock-X on D
write(D)
end;
All locks are released after commit or abort
16.12
Implementation of Locking
16.13
Lock Table
Black rectangles indicate granted
16.14
Graph-Based Protocols
data items.
16.15
Tree Protocol
16.16
16.17
Timestamp-Based Protocols
Each transaction is issued a timestamp when it enters the system. If an
In order to assure such behavior, the protocol maintains for each data Q
16.18
16.19
16.20
read(X)
T2
T3
read(Y)
write(Y)
write(Z)
read(X)
abort
write(Z)
abort
16.21
T4
T5
read(X)
read(Z)
write(Y)
write(Z)
transaction
with larger
timestamp
But the schedule may not be cascade-free, and may not even be
recoverable.
16.22
Solution:
A transaction is structured such that its writes are all performed at
the end of its processing
All writes of a transaction form an atomic action; no transaction may
execute while a transaction is being written
A transaction that aborts is restarted with a new timestamp
16.23
protocol.
16.24
Validation-Based Protocol
Execution of transaction Ti is done in three phases.
executes fully in the hope that all will go well during validation
16.25
16.26
If for all Ti with TS (Ti) < TS (Tj) either one of the following
condition holds:
16.27
T14
T15
read(B)
read(A)
(validate)
display (A+B)
read(B)
B:- B-50
read(A)
A:- A+50
(validate)
write (B)
write (A)
16.28
Multiple Granularity
tree-locking protocol)
16.29
16.30
16.31
IS
IX
S IX
IS
IX
S IX
16.32
16.33
Multiversion Schemes
concurrency.
immediately.
16.34
16.35
serializability.
16.36
transactions
Update transactions acquire read and write locks, and hold all
16.37
occurs:
16.38
Deadlock Handling
T 1:
write (X)
write(Y)
T2:
write(Y)
write(X)
T1
lock-X on X
write (X)
T2
lock-X on Y
write (X)
wait for lock-X on X
16.39
Deadlock Handling
16.40
older transaction may wait for younger one to release data item.
Younger transactions never wait for older ones; they are rolled back
instead.
a transaction may die several times before acquiring needed data
item
wound-wait scheme preemptive
16.41
Timeout-Based Schemes :
16.42
Deadlock Detection
of a pair G = (V,E),
When Ti requests a data item currently being held by Tj, then the
16.43
16.44
Deadlock Recovery
break deadlock.
16.45
16.46
One solution:
Associate a data item with the relation, to represent the information
about what tuples the relation contains.
Transactions scanning the relation acquire a shared lock in the data
item,
Transactions inserting or deleting a tuple acquire an exclusive lock on
the data item. (Note: locks on the data item do not conflict with locks on
individual tuples.)
Above protocol provides very low concurrency for
insertions/deletions.
16.47
16.48
Cursor stability:
16.49
T1 may see some records inserted by T2, but may not see
others inserted by T2
16.50
16.51
are available; see Section 16.9 for one such protocol, the B-link
tree protocol
16.52
End of Chapter
16.54
16.55
Lock Table
16.56
16.57
16.58
Schedule 3
16.59
Schedule 4
16.60
16.61
Granularity Hierarchy
16.62
Compatibility Matrix
16.63
16.64
16.65
16.66
16.67
16.68
Lock-Compatibility Matrix
16.69