Get is not really "transactional"; if the transaction contains read only, then the transaction actually does nothing. Performing a read in a transaction guarantees only one thing: if the value returned by the read is no longer the most current value at the time of any write operations in the transaction, the transaction will stop and no records will be executed.
Thus, the following sequence of events is possible:
- Run transaction 1.
- Inside transaction 1, you read object A and returns state A1.
- Inside transaction 1, you update object A from state A1 to state A2.
- When transaction 1 is committed, it is not executed with one of the indicated exceptions.
- Run transaction 2.
- Inside transaction 2, you read object A and returns state A1.
- Transaction 1 is applied to the data warehouse in the background, changing A from state A1 to state A2.
- Complete transaction 2 (no commit because there was no write).
But this sequence of events is different:
- Run transaction 1.
- Inside transaction 1, you read object A and returns state A1.
- Inside transaction 1, you update object A from state A1 to state A2.
- When transaction 1 is committed, it is not executed with one of the indicated exceptions.
- Run transaction 2.
- Inside transaction 2, you read object A and returns state A1.
- Inside transaction 2, you update object A from state A1 to state A3.
- Transaction 1 is applied to the data warehouse in the background, changing A from state A1 to state A2.
- Now transaction 2 will not be successfully completed , because the record that it is going to apply is based on an outdated version of object A. This will fail and A will remain in state A2.
So, adding a question to your step 4, you are in the second sequence of events here. It is possible that in step 3 None is returned, even if the entity exists, but it is impossible for the subsequent record to succeed in this case: the transaction is outdated and, therefore, cannot complete the transaction. The transaction will be repeated, and the second time get will return the object recorded in step 1 that you need.
So, a very short answer: yes, it can return an obsolete value, but it guarantees that if the result was obsolete, subsequent recording of this object in the same transaction will fail, so this should not actually cause a problem.
Torne source share