Timestamp Ordering Protocol
- The timestamp ordering protocol is helpful in ordering transactions according to their timestamps. The ascending order of the creation of transaction is called the order of transaction.
- The older transaction is executed first due to high priority. The protocol uses time of system or logical counter to determine transaction timestamp.
- At the time of execution, the lock-based protocol manages the order of conflicting pairs in transactions. But as soon as the creation of transaction takes place, the timestamp protocol comes into play.
- For example, the transactions T1 and T2 enter the system at different times say 007 times and 009 times, respectively. T1 will get executed first at it is old and has higher priority.
- This protocol also keeps operations last ‘read’ and last ‘write’ on a given data.
Working of basic timestamp ordering protocol:
- When a transaction Ti publishes a Read(X) operation, the following conditions are checked:
- If W_TS(X) > TS (Ti), operation gets rejected.
- If W_TS(X) <=TS (Ti), operation gets executed.
- Timestamps of all get updated.
- When a transaction Ti publishes a Write(X) operation, the following conditions are checked:
- If TS (Ti) < R_TS(X), operation gets rejected.
- If TS (Ti) < W_TS(X), the operation gets rejected and Ti gets rolled back, or else operation gets executed.
TS (Ti) is the transaction timestamp.
R_TS(X) is the read timestamp.
W_TS(X) is the Write timestamp.
Advantages of Timestamp Ordering Protocol
Observe the precedence graph given below:
- The figure shows Serializability by TO protocol.
- Also, no transaction ever needs to wait as there is freedom from deadlock.
Disadvantages of TO Protocol
- The schedule here is not necessarily recoverable or free of a cascade.