DBMS-21
DBMS-21
Timestamp Based
Protocols
Chittaranjan Pradhan
Database Management
Two-Phase Locking
System 21 Protocol
Variations of Two-Phase
Locking
Lock Conversions
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
21.1
Two-Phase Locking &
Two-Phase Locking Protocol Timestamp Based
Protocols
Chittaranjan Pradhan
Timestamp-Based
Protocols
This protocol requires that each transaction issues lock and Timestamps
unlock requests in two phases. The two phases are: Timestamp Ordering
Protocols
Problems with Timestamp
• Growing phase: Here, a transaction acquires all required Ordering Protocols
Thomas’ Write Rule
locks without unlocking any data, i.e. the transaction may
not release any lock
• Shrinking phase: Here, a transaction releases all locks
and cannot obtain any new lock
The point in the schedule where the transaction has obtained
its final lock is called the lock point of the transaction
21.2
Two-Phase Locking &
Two-Phase Locking Protocol... Timestamp Based
Protocols
Chittaranjan Pradhan
Two-Phase Locking
Protocol
Variations of Two-Phase
Locking
Lock Conversions
Timestamp-Based
Protocols
Timestamps
Timestamp Ordering
Protocols
Problems with Timestamp
Ordering Protocols
Thomas’ Write Rule
21.4
Two-Phase Locking &
Variations of Two-Phase Locking... Timestamp Based
Protocols
Chittaranjan Pradhan
Two-Phase Locking
Protocol
Variations of Two-Phase Locking... Variations of Two-Phase
Locking
Lock Conversions
Rigorous 2PL
Timestamp-Based
• A transaction T doesn’t release any of its locks until after it Protocols
Timestamps
21.5
Two-Phase Locking &
Lock Conversions Timestamp Based
Protocols
T7 Chittaranjan Pradhan
Read(a1);
Read(a2);
Read(a3); Two-Phase Locking
... Protocol
Variations of Two-Phase
Read(an); Locking
Write(a1); Lock Conversions
Timestamp-Based
T8 Protocols
Read(a1); Timestamps
Timestamp Ordering
Read(a3); Protocols
Display(a1+a3); Problems with Timestamp
Ordering Protocols
Thomas’ Write Rule
Lock Conversions
Lock Upgrade: This is the process in which a shared lock is
upgraded to an exclusive lock
If the exclusive locks are held until the end of the transaction,
then the schedules became cascadeless
21.7
Two-Phase Locking &
Lock Conversions... Timestamp Based
Protocols
Chittaranjan Pradhan
T7 T8
Lock-S(a1); Two-Phase Locking
Protocol
Read(a1); Variations of Two-Phase
Lock-S(a1); Locking
Lock Conversions
Read(a1); Timestamp-Based
Lock-S(a2); Protocols
Timestamps
Read(a2); Timestamp Ordering
Lock-S(a3); Protocols
Problems with Timestamp
Read(a3); Ordering Protocols
Thomas’ Write Rule
Schedule8 Lock-S(a3);
Read(a3);
Display(a1+a3);
Unlock(a1);
Unlock(a3);
...
Lock-S(an);
Read(an);
Upgrade(a1);
Write(a1);
21.8
Two-Phase Locking &
Timestamp-Based Protocols Timestamp Based
Protocols
Timestamp-Based Protocols Chittaranjan Pradhan
Timestamp-Based
Locking methods generally prevent conflicts by making Protocols
conflicting situation are simply rolled back and restarted Ordering Protocols
Thomas’ Write Rule
Timestamps
Two-Phase Locking
Protocol
Timestamp TS(Ti ) is assigned by the database system before Variations of Two-Phase
Locking
the transaction Ti starts its execution Lock Conversions
Timestamp-Based
Protocols
The timestamps of the transactions determine the serializability Timestamps
order. Thus, if TS(Ti ) < TS(Tj ), then the system must ensure Timestamp Ordering
Protocols
that the produced schedule is equivalent to a serial schedule in Problems with Timestamp
Ordering Protocols
21.10
Two-Phase Locking &
Timestamp Ordering Protocols Timestamp Based
Protocols
Chittaranjan Pradhan
Timestamp Ordering Protocols
This ensures that any conflicting read and write operations are Two-Phase Locking
executed in timestamp order Protocol
Variations of Two-Phase
Locking
• Suppose transaction Ti issues read(Q): Lock Conversions
Two-Phase Locking
Protocol
If a transaction Ti is rolled back by the concurrency-control Variations of Two-Phase
Timestamp-Based
T1 T2 T1 T2 T1 T2 Protocols
Read(A); Read(A); Read(A); Timestamps
A:=A-100; A:=A-100; A:=A-100; Timestamp Ordering
Write(A); Read(A); Write(A); Protocols
Read(A); Temp:=0.2*A; Read(A); Problems with Timestamp
Ordering Protocols
Temp:=0.2*A; A:=A-Temp; Temp:=0.2*A;
Thomas’ Write Rule
A:=A-Temp; Write(A); A:=A-Temp;
Write(A); Read(B); Read(B);
Read(B); Write(A); B:=B+100;
B:=B+100; Read(B); Write(A);
Write(B); B:=B+100; Read(B);
Read(B); Write(B); B:=B+ Temp;
B:=B+ Temp; B:=B+ Temp; Write(B);
Write(B); Write(B); Write(B);
Schedule3 Schedule4 Schedule5
21.12
Two-Phase Locking &
Timestamp Ordering Protocols... Timestamp Based
Protocols
Chittaranjan Pradhan
From the above examples, we can say that the timestamp Two-Phase Locking
Protocol
ordering protocol always ensures conflict serializability. This is Variations of Two-Phase
Locking
because conflicting operations are processed in timestamp Lock Conversions
order Timestamp-Based
Protocols
Timestamps
Timestamp Ordering
The protocol ensures freedom from deadlock, since no Protocols
Problems with Timestamp
transaction ever waits Ordering Protocols
Thomas’ Write Rule
21.13
Two-Phase Locking &
Problems with Timestamp Ordering Protocols Timestamp Based
Protocols
Chittaranjan Pradhan
Then, Tj must abort; if Tj had been allowed to omit earlier, the Lock Conversions
Timestamp-Based
schedule is not recoverable. Further, any transaction that has Protocols
read a data item written by Tj must abort. This can lead to Timestamps
Timestamp Ordering
21.14
Two-Phase Locking &
Thomas’ Write Rule Timestamp Based
Protocols
Chittaranjan Pradhan
Timestamp-Based
Protocols
A modification to the basic timestamp ordering protocol that Timestamps
Timestamp Ordering
relaxes the conflict serializability can be used to provide Protocols
Problems with Timestamp
greater concurrency by rejecting obsolete write operations Ordering Protocols
Thomas’ Write Rule
T9 T10
Read(Q);
Write(Q);
Schedule9
Write(Q);
Read(M);
Write(M);
21.15
Two-Phase Locking &
Thomas’ Write Rule... Timestamp Based
Protocols
Chittaranjan Pradhan
Two-Phase Locking
Protocol
Thomas’ Write Rule... Variations of Two-Phase
Locking
Timestamp-Based
• Remains same Protocols
Timestamps
• Ti issues write(Q): Timestamp Ordering
Protocols
• If TS(Ti ) < R-TS(Q), Ti is aborted, rolled back and is Problems with Timestamp
Ordering Protocols
restarted with a new timestamp Thomas’ Write Rule
21.16