Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC Object Store is not working with a datasource which is using the default transaction setting #33739

Closed
zhfeng opened this issue May 31, 2023 · 9 comments
Labels
area/agroal area/narayana Transactions / Narayana kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency

Comments

@zhfeng
Copy link
Contributor

zhfeng commented May 31, 2023

Describe the bug

I'm testing the camel-quarkus jta-jpa example by using the JDBC Object Store with following configurations:

quarkus.datasource.tslog.db-kind=mysql
quarkus.datasource.tslog.username=admin
quarkus.datasource.tslog.password=admin
quarkus.datasource.tslog.jdbc.url=jdbc:mysql://localhost:3306/testdb

quarkus.transaction-manager.object-store.type=jdbc
quarkus.transaction-manager.object-store.datasource=tslog
quarkus.transaction-manager.object-store.create-table=true

quarkus.transaction-manager.enable-recovery=true

It throws a Exception when doing commit a transaction

ARJUNA012258: JDBCImple:write_state caught exception: java.lang.IllegalStateException: No transaction is running
	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple.getTransactionImple(TransactionSynchronizationRegistryImple.java:228)
	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple.getResource(TransactionSynchronizationRegistryImple.java:125)
	at jakarta.transaction.NarayanaJtaProducers_ProducerMethod_transactionSynchronizationRegistry_6c1ae1f6c0015764ef2a5d1837652baa9054bdb5_ClientProxy.getResource(Unknown Source)
	at io.agroal.narayana.NarayanaTransactionIntegration.getTransactionAware(NarayanaTransactionIntegration.java:72)
	at io.agroal.pool.ConnectionPool.handlerFromTransaction(ConnectionPool.java:267)
	at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:237)
	at io.agroal.pool.DataSource.getConnection(DataSource.java:86)
	at io.quarkus.narayana.jta.runtime.QuarkusDataSource.getConnection(QuarkusDataSource.java:38)
	at com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DirectDataSourceJDBCAccess.getConnection(DirectDataSourceJDBCAccess.java:27)
	at com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCImple_driver.write_state(JDBCImple_driver.java:626)
	at com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore.write_committed(JDBCStore.java:161)
	at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2316)
	at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1508)
	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:96)
	at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1295)
	at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:128)
	at io.quarkus.narayana.jta.runtime.NotifyingTransactionManager.commit(NotifyingTransactionManager.java:70)
	at org.apache.camel.quarkus.component.jta.TransactionalJtaTransactionPolicy.commit(TransactionalJtaTransactionPolicy.java:63)
	at org.apache.camel.quarkus.component.jta.TransactionalJtaTransactionPolicy.runWithTransaction(TransactionalJtaTransactionPolicy.java:53)
	at org.apache.camel.quarkus.component.jta.RequiredJtaTransactionPolicy.run(RequiredJtaTransactionPolicy.java:26)
	at org.apache.camel.jta.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:186)
	at org.apache.camel.jta.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:137)
	at org.apache.camel.jta.TransactionErrorHandler.process(TransactionErrorHandler.java:101)
	at org.apache.camel.jta.TransactionErrorHandler.process(TransactionErrorHandler.java:110)
	at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:475)
	at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181)
	at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:59)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:164)
	at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:379)
	at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:206)
	at io.vertx.core.impl.ContextBase.lambda$null$0(ContextBase.java:137)
	at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
	at io.vertx.core.impl.ContextBase.lambda$executeBlocking$1(ContextBase.java:135)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)

I have to add quarkus.datasource.tslog.jdbc.transactions=disabled to make it working.

Expected behavior

It should commit the transaction when using JDBC object store.

Actual behavior

The exception is throwing and transaction is not committed.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

The potenial issue could be a difference of checking a transaction is running between narayana and agroal.

On narayana side:
https://github.com/jbosstm/narayana/blob/main/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionSynchronizationRegistryImple.java#L226-L229

if (transactionImple == null || (transactionImple.getStatus() != Status.STATUS_ACTIVE && transactionImple.getStatus() != Status.STATUS_MARKED_ROLLBACK)) 

On agroal side:
https://github.com/agroal/agroal/blob/master/agroal-narayana/src/main/java/io/agroal/narayana/NarayanaTransactionIntegration.java#L119-L121

return status != STATUS_UNKNOWN && status != STATUS_NO_TRANSACTION && status != STATUS_COMMITTED && status != STATUS_ROLLEDBACK;
            // other states are active transaction: ACTIVE, MARKED_ROLLBACK, PREPARING, PREPARED, COMMITTING, ROLLING_BACK

Then when writing a transaction log through a jdbc connection in the COMMITTING phase, agroal thinks the transaction is running but narayana does not.

@zhfeng zhfeng added the kind/bug Something isn't working label May 31, 2023
@zhfeng
Copy link
Contributor Author

zhfeng commented May 31, 2023

@mmusgrov I suppose only ACTIVE and MARKED_ROLLBACK is validated when it is checking transaction is running? So it needs to fix agroal?

@zhfeng
Copy link
Contributor Author

zhfeng commented Jun 1, 2023

Anyway, I file https://issues.redhat.com/browse/AG-209

@mmusgrov
Copy link
Contributor

mmusgrov commented Jun 1, 2023

@zhfeng Yes that's correct, a transaction is active when it is in the state Status.STATUS_ACTIVE or Status.STATUS_MARKED_ROLLBACK. We need to include STATUS_MARKED_ROLLBACK because the user can call setRollbackOnly() before the commit phase (which changes the state from active to one of the other states).

Coincidentally we had a long discussion on this topic in the Eclipse jta-dev email list.

@zhfeng
Copy link
Contributor Author

zhfeng commented Jun 2, 2023

Thanks @mmusgrov and it was a interesting discussion about this active topic. I will prepare a PR for fixing AG-209.

@zhfeng
Copy link
Contributor Author

zhfeng commented Jun 5, 2023

@mmusgrov I raise agroal/agroal#70 and would you like to take a review? It seems that agroal has a different view on a transaction is running or active.

@manovotn manovotn added area/narayana Transactions / Narayana area/agroal and removed triage/needs-triage labels Jun 5, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 5, 2023

/cc @Sanne (agroal), @barreiro (agroal), @yrodiere (agroal)

@yrodiere yrodiere added the triage/upstream Used for issues which are caused by issues in upstream projects/dependency label Jun 5, 2023
@zhfeng
Copy link
Contributor Author

zhfeng commented Jun 12, 2023

@yrodiere I just wonder if it is better to update the transaction document with this know issue since it looks like we need more investigation both on agoral and narayana.

@yrodiere
Copy link
Member

@yrodiere I just wonder if it is better to update the transaction document with this know issue since it looks like we need more investigation both on agoral and narayana.

I agree if an extra configuration property is necessary for things to work right now, it should be mentioned in the documentation.

@barreiro
Copy link
Contributor

barreiro commented Mar 6, 2024

AG-209 - fixed with #39072

@barreiro barreiro closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agroal area/narayana Transactions / Narayana kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Projects
None yet
Development

No branches or pull requests

5 participants