Can't fetch token when using JTA transaction

Hi,
We are trying to use JTA transaction in our project.
But it seems when using JTA transaction, tracking processors can’t fetch the token from tokenstore.
The problem is JdbcTokenStore trying to commit the connection while fetching token(I know it has to be commited otherwise token won’t be locked):

org.axonframework.eventhandling.tokenstore.jdbc.JdbcTokenStore#fetchToken (3.2.2)

TrackingToken result = loadOrInsertToken(resultSet, processorName, segment);
if (!connection.getAutoCommit()) {
connection.commit();
}

Then it’ll trigger “com.atomikos.jdbc.AtomikosSQLException: Cannot call method ‘commit’ while a global transaction is running”
Is there any solution for this problem?

Thanks.

Hi Tian,

it does look like the combination of an aggressive commit() by the JdbcTokenStore and the lack of “blocking” of this call in the NoOpCloseHandler will cause a transaction to be committed, even when a UnitOfWorkAwareConnectionProviderWrapper is used. We will investigate whether it is desirable to block calls to commit until the Unit of Work completes.

However, there is a solution that will definitely work in your case. Since you’re using an explicit transaction manager, you could return a connection that blocks “external” calls to commit, while configuring the transaction manager to commit the underlying transaction directly when the transaction manager wants to commit.

Hope this helps.
Cheers,

Allard

Hi Allard,
I think blocking the connection to commit won’t work for this case.
The process is like this:

  1. start the transaction
  2. the tracking processor tries to acquire a token if success it needs to commit, so other processors will know.
  3. process event
  4. commit the transaction

So step2 need to commit its change, something like propagation.REQUIRES_NEW.

Thanks.

Hi Tian,

I am not 100% sure on this, as ideally Allard would answer now, but I’d nonetheless wanted to give you this update.

I believe Allard investigated your use case a little further and he did find a culprit in the code base.

If I am correct, this PR would pose as a solution to your problem.
Would you mind checking and verifying if this is the case?

It is part of Axon Framework release 3.3.4 if you were wondering.

Cheers,

Steven

Hi Steven,
I think PR 706 will solve this (https://groups.google.com/forum/#!topic/axonframework/q0SGPqi-_gY) problem instead of the JTA transaction one.

When tracking processor tries to acquire a token, it has to write tokenentry table and commit, and this was done in another started transaction, so it got the “AtomikosSQLException: Cannot call method ‘commit’ while a global transaction is running”.
To fix this, I think either tracking processor tries to acquire token before the transaction started, or it commits in its own transaction ( a nested one)

Best regards,