I have a value called x in my database and two transactions, T1 & T2. Assume both transactions use the multi-document ACID API MongoDB provides.
Each transaction reads the value of x and decrements it by 1. When reading, the code checks that the value of x is greater than 0.
Now, the value of x is 1 and T1 & T2 are concurrent. Assume the following execution thread
T1 reads x = 1
T2 reads x = 1
T1 writes x = 0
T2 writes x = 0
In this situation will T2 detect that the value of x that it read has been changed and abort the transaction (presumably based on some internal timestamp) or will it continue with the write?
I have tried looking through the MongoDB docs and I can’t find a satisfactory explanation to this.