2. TIME STAMP ODERING PROTOCOL
Timestamp means a unique value or time attached to a transaction .
Timestamp is denoted by TS
Timestamp tells us the order of transactions i.e, when they enter into the system.
Suppose , transaction T1 enters into the system at time 10:00 and its Timestamp value is 100.
Now lets say transaction T2 enters into the system at time 10:10 and its Timestamp value is 200.
Now T1 becomes old as T2 is the new transaction in the system. The new transaction(T2) will
always have a greater timestamp value then the previous one(T1). So, by comparing the TS of
both transactions we can easily find out the sequence of transactions.
10:00 10:10
T1 T2
100 (old) 200(new)
3. Here , we talk about the three timestamps:
1. Timestamp of the transaction : The timestamp value of a system when it enters into the
system. It is denoted by TS(Ti) where,
TS= Timestamp
Ti=transaction no
From the table , we got
TS(T1)=100
TS(T2)=200
10:00 10:10
T1 T2
100 (old) 200(new)
4. 2. READ__TS(RTS):
Last(latest) transaction number that has performed Read successfully.
Suppose , we take three transactions T1, T2 and T3 whose timestamps are 10, 20 and 30.
HERE, RTS(A)= 30
( Since, RTS says latest transaction that has performed read successfully and here T3 reads at the last
so RTS(A)=30)
TS =10 TS=20 TS=30
T1 T2 T3
R(A)
R(A)
R(A)
5. 2. WRITE _TS(WTS):
Last(latest) transaction number that has performed Write successfully.
Suppose , we take three transactions T1, T2 and T3 whose timestamps are 10, 20 and 30.
HERE, WTS(A)= 20
( Since, WTS says latest transaction that has performed write successfully and here T2 writes at the last so
WTS(A)=20)
NOTE:
In timestamp protocol , the transaction that enters into the system first will be completed first( We
can say older transaction gets priority)
TS =10 TS=20 TS=30
T1 T2 T3
W(A)
W(A)
W(A)
6. RULES OF TIMESTAMP PROTOCOL
There are two rules of timestamp protocol :
RULE 1: (for READ Operation)
Transaction Ti issues a READ operation
if TS( Ti) < WTS(X) then WR
Rollback Ti READ after WRITE
Else
{
perform READ(A)
set RTS(A) = Max{ RTS(A) , TS(Ti) }
}
7. RULE 2: ( for WRITE Operation )
Transaction Ti issues a WRITE operation
If TS( Ti) < RTS(X) then RW
Rollback Ti WRITE after READ
Else If (TS( Ti) < WTS(X) ) then WW
Rollback Ti WRITE after WRITE
Else
{
perform WRITE(A)
set WTS(A) = TS(Ti)
}
8. Q. Find R1(A), R2(A), W1(A) and W2(A)
Let T1 =100
T2 = 200
According to rules of TSP-
We’ll apply RULE 1 (READ Operation) for R1(A) and R2(A)
Initially , RTS =0, WTS=0
TS( T1) < WTS(A) 100<0 (False)
R1(A) performs
RTS (A)= Max(0,100) =100
RTS(A) = 200
Again for R2
200<0 (False)
R2(A) performs
RTS (A)= Max(100,200)
= 200