quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Change transaction isolation level in the @Transactional annotation #17148

Open jendib opened 3 years ago

jendib commented 3 years ago

Description

In Spring, I could change the transaction isolation level in their @Transactional annotation (please see https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html) however Quarkus is using the Java EE annotation which doesn't permit isolation level configuration.

My app is separated between read only API endpoints (high traffic) and write API endpoints (low traffic), so it would be very useful to have serializable isolation level for the write endpoints and default (read uncommitted) isolation level for read only endpoints.

Implementation ideas

Quarkus already has a TransactionConfiguration annotation to configure transaction timeout, it would be a good idea to add an isolation level configuration there.

mmusgrov commented 2 years ago

Enforcement of transaction isolation levels is not under the control of the narayana transaction manager, instead it is enforced by the connection pooling (so either Agroal or vert.x). @geoand is there a better area by which we can track this issue?

geoand commented 2 years ago

I'll just file it under persistence.

gastaldi commented 2 years ago

My app is separated between read only API endpoints (high traffic) and write API endpoints (low traffic), so it would be very useful to have serializable isolation level for the write endpoints and default (read uncommitted) isolation level for read only endpoints.

Thinking out loud, one way to work around this is to create 2 Datasources and set the quarkus.datasource.jdbc.transaction-isolation-level=SERIALIZABLE for the Datasource consumed in the write endpoints.