Currently stores are activated on demand, i.e. when first accessed, and their
XAResource(s) are enlisted with the TM at that time. However, this reduces
the transaction isolation level to something less than snapshot-isolation and
closer to read-committed. The following scenario illustrates the problem,
assuming two resources (stores):
- Transaction A begins
- Transaction A reads from store 1 (store 1's XAResource is enlisted)
- Transaction B begins
- Transaction B updates store 1
- Transaction B updates store 2
- Transaction B commits
- Transaction A reads from store 2 (store 1's XAResource is enlisted)
At this point transaction A now sees an inconsistent state: it sees B's
modifications to store 2 but not those to store 1.
By always enlisting all XAResources at transaction begin we can reduce the
chance of seeing inconsistent states; additionally, if we do all these
enlistements together in a synchronized block (which synchronizes across all
transactions) then we can completely close the window.