Sunday, 2 July 2023

Time Stamp Ordering Protocol

Time Stamp Ordering Protocol:


A timestamp is a tag that can be attached to any transaction or any data item, which denotes a specific time on which the transaction or the data item had been used in any way. A timestamp can be implemented in 2 ways. One is to directly assign the current value of the clock to the transaction or data item. The other is to attach the value of a logical counter that keeps increment as new timestamps are required.

The timestamp of a data item can be of 2 types:


(i) W-timestamp(X): 

This means the latest time when the data item X has been written into.


(ii) R-timestamp(X):


This means the latest time when the data item X has been read from. 

These 2 timestamps are updated each time a successful read/write operation is performed on the data item X. 

Every transaction is issued a timestamp based on when it enters the system. Suppose, if an old transaction Ti has timestamp TS(Ti), a new transaction Tj is assigned timestamp TS(Tj) such that TS(Ti) < TS(Tj).The protocol manages concurrent execution such that the timestamps determine the serializability order. 

The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order. Whenever some Transaction T tries to issue a R_item(X) or a W_item(X), the Basic TO algorithm compares the timestamp of T with R_TS(X) & W_TS(X) to ensure that the Timestamp order is not violated. This describes the Basic TO protocol in following two cases.


Whenever a Transaction T issues a W_item(X) operation, check the following conditions:


• If R_TS(X) > TS(T) or if W_TS(X) > TS(T), then abort and rollback T and reject the operation. else, Execute W_item(X) operation of T and set W_TS(X) to TS(T).


Whenever a Transaction T issues a R_item(X) operation, check the following conditions:


•If W_TS(X) > TS(T), then abort and reject T and reject the operation, else If W_TS(X) <= TS(T), then execute the R_item(X) operation of T and set R_TS(X) to the larger of TS(T) and current R_TS(X).


Whenever the Basic TO algorithm detects two conflicting operation that occur in incorrect order, it rejects the later of the two operation by aborting the Transaction that issued it. Schedules produced by Basic TO are guaranteed to be conflict serializable. Already discussed that using Timestamp, can ensure that our schedule will be deadlock free. One drawback of Basic TO protocol is that it Cascading Rollback is still possible. Suppose we have a Transaction T1 and T2 has used a value writtenby T1. If T1 is aborted and resubmitted to the system then, T must also be aborted and rolled back. So the problem of Cascading aborts still prevails. 

 

Validation Based Protocol

Validation phase is also known as optimistic concurrency control technique. In the validation based protocol, the transaction is executed in the following three phases:


1. Read phase: In this phase, the transaction T is read and executed. It is used to read the value of various data items and stores them in temporary local variables. It can perform all the write operations on temporary variables without an update to the actual database.


2. Validation phase: In this phase, the temporary variable value will be validated against the actual data to see if it violates the serializability.


3. Write phase: If the validation of the transaction is validated, then the temporary results are written to the database or system otherwise the transaction is rolled back.


Here each phase has the following different timestamps:


Start(Ti): It contains the time when Ti started its execution.


Validation (Ti): It contains the time when Ti finishes its read phase and starts its validation phase. 

Finish(Ti): It contains the time when Ti finishes its write phase.


o This protocol is used to determine the time stamp for the transaction for serialization using the time stamp of the validation phase, as it is the actual phase which determines if the transaction will commit or rollback.


o Hence TS(T) = validation(T).


o The serializability is determined during the validation process. It can't be decided in advance.


o While executing the transaction, it ensures a greater degree of concurrency and also less number of conflicts.


o Thus it contains transactions which have less number of rollbacks 

 

Multiple Granularity

 
Let's start by understanding the meaning of granularity.


Granularity: It is the size of data item allowed to lock.


Multiple Granularity:
o It can be defined as hierarchically breaking up the database into blocks which can be
locked.
o The Multiple Granularity protocol enhances concurrency and reduces lock overhead.
o It maintains the track of what to lock and how to lock.
o It makes easy to decide either to lock a data item or to unlock a data item. This type
of hierarchy can be graphically represented as a tree.


For example: Consider a tree which has four levels of nodes.
o The first level or higher level shows the entire database.
o The second level represents a node of type area. The higher level database consists of
exactly these areas.
o The area consists of children nodes which are known as files. No file can be present in 

more than one area.
o Finally, each file contains child nodes known as records. The file has exactly those
records that are its child nodes. No records represent in more than one file.
o Hence, the levels of the tree starting from the top level are as follows:
1. Database
2. Area
3. File
4. Record

No comments:

Post a Comment

Timestamp-Based Protocols

Timestamp-Based Protocols Each transaction T i  is issued a timestamp TS( T i ) when it enters the system. •        Each transac...