Validation based protocol avoids the concurrency of the transactions and works based on the assumption that if no transactions are running concurrently then no interference occurs. This is why it is also called Optimistic Concurrency Control Technique.
In this protocol, a transaction doesn’t make any changes to the database directly, instead it performs all the changes on the local copies of the data items that are maintained in the transaction itself. At the end of the transaction, a validation is performed on the transaction. If it doesn’t violate any serializability rule, the transaction commit the changes to the database else it is updated and restarted.
Three phases of Validation based Protocol
- Read phase: In this phase, a transaction reads the value of data items from database and store their values into the temporary local variables. Transaction then starts executing but it doesn’t update the data items in the database, instead it performs all the operations on temporary local variables.
- Validation phase: In this phase, a validation check is done on the temporary variables to see if it violates the rules of serializability.
- Write phase: This is the final phase of validation based protocol. In this phase, if the validation of the transaction is successful then the values of temporary local variables is written to the database and the transaction is committed. If the validation is failed in second phase then the updates are discarded and transaction is slowed down to be restarted later.
Let’s look at the timestamps of each phase of a transaction:
Start(Tn): It represents the timestamp when the transaction Tn starts the execution.
Validation(Tn): It represents the timestamp when the transaction Tn finishes the read phase and starts the validation phase.
Finish(Tn): It represents the timestamp when the transaction Tn finishes all the write operations.
This protocol uses the Validation(Tn) as the timestamp of the transaction Tn because this is actual phase of the transaction where all the checks happen. So it is safe to say that TS(Tn) = Validation(Tn).
If there are two transactions T1 & T2 managed by validation based protocol and if Finish(T1) < Start(T2) then the validation will be successful as the serializability is maintained because T1 finished the execution well before the transaction T2 started the read phase.