I think you are confusing everyone here with the oracle tag. I think you want the Timestamp based concurrency control algorithm based of the first line of your question which is a pretty common algorithm for concurrency control in computer science theory.
Easier to understand link.
Also, your use of rollback is not correct, as the transactions are not rolled back but restarted. (This happens in oracle too)
The algorithm works like this -
Whenever a transaction starts, it is given a timestamp. This is so we
can tell which order that the transactions are supposed to be applied
in. So given two transactions that affect the same object, the
transaction that has the earlier timestamp is meant to be applied
before the other one. However, if the wrong transaction is actually
presented first, it is aborted and must be restarted
Based on this, let's give our transactions a timestamp like t=1,2,3,4,5...
- T5 starts at t=1.
- T2 starts at t=2.
- T1 starts at t=3.
- T3 starts at t=4.
- T4 starts at t=5
- T5 has another operation at t=6, but it's timestamp is still t=1 because timestamp is assigned based on when a transaction started.
Moving on,
Every object in the database has a read timestamp, which is updated whenever the object's data is read, and a write timestamp, which is updated whenever the object's data is changed.
At the beginning both X and Y have their read and write timestamp as 0.
A read request is handled in the following manner:
If TS < W-ts(x) then
reject read request and abort corresponding transaction
else
execute transaction
Set R-ts(x) to max{R-ts(x), TS}
A write request is handled in the following manner:
If TS < R-ts(x) or TS < W-ts(x) then
reject write request
else
execute transaction
Set W-ts(x) to TS.
Let's go through our objects and apply these rules.
- T5 starts and reads X. TS5 = 1. WTS(X) = 0. Goes fine. Set RTS(x) = 1.
- T2 starts and reads Y. TS2 = 2. WTS(Y) = 0. Goes fine. Set RTS(Y) = 2.
- T1 starts and writes to Y. TS1 = 3. RTS(Y) = 1. WTS(Y)=0. Write Completes. Set WTS(Y) = 3.
- T3 starts and writes to Y. TS3 = 4. RTS(Y) = 1. WTS(Y)=3. Write Completes. Set WTS(Y) = 4.
- T4 starts and writes to X. TS4 = 5. RTS(x) = 1. WTS(x) = 0. Write Completes. Set WTS(x) = 5.
- T5 does write(y). TS5 = 1. RTS(y) = 1. WTS(y) = 4. TS5 < WTS(y) . Transaction is rolled back and restarted with a new timestamp. (Probably t=7)
So this gives us an answer different from your TA that is only T5 is rolled back and restarted.
I would love to be corrected and learn why T4 and T1 were aborted and restarted.