Saturday, 2 June 2012

Understand the Timestamp Based Protocol with example


Hi, how are you? In this tutorial I will clarify you the timestamp based protocol with explanation. I think this tutorial may help you to understand the timestamp based protocol easily. Now think the given picture. 

This is a picture of real timestamp. Real timestamp show you the time. But database timestamp what is it? Yes, database timestamp is same as real timestamp. 
What is a database timestamp?
Database timestamp is nothing but it counts the time of any transaction. It builds with sequence of character which show you the time of any transaction. We use the timestamp to compare transaction duration between transaction. So we say that database timestamp is same as the real timestamp but we use these types of timestamp in different purpose.
Why we use Timestamp in the database?
To compare one transaction to another we use the timestamp. We count the transaction duration using timestamp. If one transaction timestamp is greater than another transaction timestamp. The priority is given for the first transaction. Such a transaction T1 timestamp is 10 and transactions T2 timestamp is  5. If the two transaction wants to write A we give the chance T1 because T1 timestamp is greater than T2 timestamp. 
Kinds of timestamp?
There are two kinds of transaction we use in the database system. The first one is R-timestamp(Q) and the second one is W-timestamp(Q). Where Q is the data item for these transactions.  
1.  R-timestamp(Q) that executed readQ) operation successfully in any transaction.
2.  W-timestamp(Q) that executed write (Q) operation successfully in any transaction.

Explanation of Timestamp based protocol?
The timestamp based protocol ensures read and write operations are executed in timestamp order.  In database to maintain serializability the transaction maintains ordering that is called timestamp ordering based protocol or timestamp protocol. Let a unique timestamp is denoted by TS(Ti) where Ti is the transaction number. This timestamp TS(Ti) is assigned by the database system before new transaction Tj enters the database system because timestamp of Ti is produced before Tj. Timestamp protocol must maintain this following condition. 
Let transaction T wants to read the data item Q. This procedure maintains two timestamp rules. 
1. read_TS(Q) < W-timestamp(Q)
 Where write timestamp is greater than our read timestamp. So the T cannot able to read the data item Q. 
2. read_TS(Q) => W-timestamp(Q)
where our timestamp T is greater than W-timstamp(Q). So our timestamp T read the data item successfully. 


Now let another transaction T wants to write the data item Q. This procedure maintains two timestamp rules. 
1. write_TS(Q) < R-timestamp(Q)
Where read timestamp is greater than our timestamp. So read is possible in this transaction but write cannot be possible. 
2. write_TS(Q) < W-timestamp
where our timestamp write_TS(Q) is less than the write transaction. So our transaction cannot be able to write. 
Other wise our transaction can be able to write the data item Q. If you want to learn more just follow this tutorial Timestamp based protocol . To improve this blog content please make sure your comment. We highly appreciate you. Tanks everyone. 

No comments:

Post a Comment