Isolation in distributed (global) transactions using JTA
Asked Answered
A

1

6

As we know Isolation and Atomicity are two different properties. Atomicity is the "all or nothing" property, either a transaction completes successfully or fails altogether. Atomicity is definetly supported by JTA and the X/Open XA Two Phase Commit Standard on which JTA is based upon.

My question is: Does JTA support isolation? I'm referring only to the case when we use EJBs and JDBC, no frameworks (e.g. Spring) or transaction managers other than JTA.

In other words, let's take the case that we have multiple threads, and let's say that one of them executes the global transaction which performs access and modifications on multiple databases. The other threads perform modifications on the databases but each thread performs modification on only one database and it does it within a transaction.

Are we going to have any concurrency issues like dirty/repeatable/phantom reads inside the global transaction?

AFAIK there is no way to specify the isolation level in JTA.

Agustinaah answered 30/4, 2017 at 18:0 Comment(0)
W
3

Isolation is the black sheep of the ACID family. It's not, strictly speaking, a property of the transaction manager. It's entirely controlled by the resource manager i.e. the database. All transactions against the database run at some isolation level. The difference in XA (JTA) transactions is in how that level is selected.

For the most part it isn't possible to achieve the per-transaction isolation level selection control you have with regular transactions, though some resource managers may allow SQL set transaction isolation commands as the first statement in an XA controlled transaction branch. The other model sometimes used is custom flags to XAResource.start, an approach taken by e.g. oracle. For database engines supporting neither of these, the XA transaction defaults to the isolation level configured globally for the database server.

Note that even for 'serializable' transactions, JTA or otherwise, you are still going to have headaches. Read Peter Bailis's excellent ACIDRain paper and then go find a corner to weep quietly in.

http://www.bailis.org/papers/acidrain-sigmod2017.pdf

Witten answered 4/5, 2017 at 15:24 Comment(2)
Ok, I'm actually in the process of learning all the specifics of a simple JTA global transaction implementation so allow a silly question. If let's say I have a JTA transaction that accesses 2 different databases through JDBC, can't I call the Connection.setTransactionIsolation with the desired isolation level which could actually be different for each one of them and solve my problem of atomicity? As I understand from my little research I can't "propagate" a common isolation level for all resources of a transaction but that doesn't mean that I can't set it separately for each resource. Right?Agustinaah
And also, If I set the isolation level to "TRANSACTION_SERIALIZABLE" on all transaction resources then I won't have any isolation (i.e. data consistency) issues because of possible concurrent access right?Agustinaah

© 2022 - 2024 — McMap. All rights reserved.