XaDisk error on timeout transaction

Showing 1-8 of 8 messages
XaDisk error on timeout transaction Alex Escot 11/27/13 7:20 AM
Hello,

I am using Xadisk 1.2.2 with JDK 1.7 into a standalone application using JTA (Bitronix). I get an exception when the transaction manager rollback the transaction due to a timeout.

I have tried to debug it. In method endXid xid, int flag) of class XAResourceImpl, the line below return null, the system can't find my SessionOfTransaction. Error with code XAER_INVAL.

Session sessionOfTransaction = xaFileSystem.getSessionForTransaction(internalXid);
        if (sessionOfTransaction == null) {
            throw MiscUtils.createXAExceptionWithCause(XAException.XAER_INVAL, null);
        }

Method public NativeSession getSessionForTransaction(Xid xid) of class NativeXaFileSystem return null.



stack trace :

org.xadisk.filesystem.exceptions.TransactionRolledbackException: The method call expected a transaction to be associated, but no such transaction exists. An associated transaction that could be expected by the client had been rolled back earlier.

Do you know why ?


You can see here my part of my code :

TransactionManager tm ...
tm.begin();
Transaction tx = tm.getTransaction();
try {
...

XAFileSystem xaf = XAFileSystemProxy.getNativeXAFileSystemReference(INSTANCE_XADISK);
XASession xaSession = xaf.createSessionForXATransaction();
XAResource xaResource = xaSession.getXAResource();
EhCacheXAResourceProducer.registerXAResource("test", xaResource);
tx.enlistResource(xaResource);

File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "fileOperation.txt");
Thread.sleep(11000); ==> Time out transaction
xaSession.createFile(file, false);
} catch (Exception e) {
   tm.rollback();
}


This code works fine except when transaction time out, if there any other exception, transaction is well rollbacked without any error. Maybe is it due to thread.sleep(..) ?

Thanks for your helps.

Alex


Re: XaDisk error on timeout transaction Nitin Verma 11/27/13 10:23 AM
Hello Alex,

Can you please send the complete stacktrace for the TransactionRolledbackException (including the "cause" exceptions).

Due to some reason, the xadisk session has got rolled back. As part of cleanup during this rollback, the entry from the xid->session map for the transaction is removed. That can be the reason when the TransactionManager calls XAResource.end for xadisk, we see NPE.

Thanks,
Nitin
Re: XaDisk error on timeout transaction Alex Escot 11/28/13 12:27 AM
Hello Nitin, 

Thanks for your quick response. You can see here the complete stacktrace :
 
WARN  bitronix.tm.BitronixTransaction.delistUnclosedResources(BitronixTransaction.java:463) - error delisting resource, assuming unilateral rollback: an XAResourceHolderState with uniqueName=fileOperation XAResource=org.xadisk.connector.XAResourceImpl@31ed2fda (ended) with XID a Bitronix XID [4B49532D4A564D000000000427E44500000001 : 4B49532D4A564D000000000427E4E800000003]
bitronix.tm.internal.BitronixSystemException: cannot delist an XAResourceHolderState with uniqueName=fileOperation XAResource=org.xadisk.connector.XAResourceImpl@31ed2fda (ended) with XID a Bitronix XID [4B49532D4A564D000000000427E44500000001 : 4B49532D4A564D000000000427E4E800000003], error=XAER_INVAL
at bitronix.tm.BitronixTransaction.delistResource(BitronixTransaction.java:203)
at bitronix.tm.BitronixTransaction.delistUnclosedResources(BitronixTransaction.java:456)
at bitronix.tm.BitronixTransaction.rollback(BitronixTransaction.java:311)
at bitronix.tm.BitronixTransactionManager.rollback(BitronixTransactionManager.java:152)
at com.asis.kis.poc.poc10.TestJPA.commitedTransaction(TestJPA.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.transaction.xa.XAException
at org.xadisk.filesystem.utilities.MiscUtils.createXAExceptionWithCause(MiscUtils.java:18)
at org.xadisk.connector.XAResourceImpl.end(XAResourceImpl.java:70)
at bitronix.tm.internal.XAResourceHolderState.end(XAResourceHolderState.java:172)
at bitronix.tm.internal.XAResourceManager.delist(XAResourceManager.java:133)
at bitronix.tm.BitronixTransaction.delistResource(BitronixTransaction.java:186)
... 27 more
ERROR com.asis.kis.poc.poc10.TestJPA.commitedTransaction(TestJPA.java:148)             - org.xadisk.filesystem.exceptions.TransactionRolledbackException: The method call expected a transaction to be associated, but no such transaction exists. An associated transaction that could be expected by the client had been rolled back earlier.


Thanks for your helps. 
Re: XaDisk error on timeout transaction Nitin Verma 11/28/13 11:25 PM
Hello Alex,

Actually I wanted the stack trace for the "TransactionRolledbackException". As you can see in the source for TransactionRolledbackException, the only constructor for this class is:

public TransactionRolledbackException(Throwable cause).

So, whenever anyone see this exception, he can also find out the "cause". I am looking for the complete stacktrace for this exception, including the inner cause(s).

Thanks,
Nitin
Re: XaDisk error on timeout transaction Alex Escot 12/2/13 2:32 AM
Hello Nitin,

Sorry for the wrong stack trace. You can see here the stack trace of the cause.

org.xadisk.filesystem.exceptions.TransactionTimeoutException: The transaction associated earlier was rolled back by XADisk because the transaction was open for more than the transaction timeout value.
at org.xadisk.filesystem.exceptions.TransactionRolledbackException.<init>(TransactionRolledbackException.java:44)
at org.xadisk.filesystem.NativeSession.checkIfCanContinue(NativeSession.java:1228)
at org.xadisk.filesystem.NativeSession.createFile(NativeSession.java:221)
at org.xadisk.filesystem.NativeXASession.createFile(NativeXASession.java:84)
at com.asis.kis.poc.poc10.TestJPA.failedTransaction(TestJPA.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Thanks for your helps.
Re: XaDisk error on timeout transaction Nitin Verma 12/2/13 6:59 AM
Sorry, I meant "sessionOfTransaction" as null, not "NPE" in my above message.
Re: XaDisk error on timeout transaction Nitin Verma 12/2/13 8:41 AM
Hello Alex,

XADisk itself can rollback its transactions in some cases, eg after a transaction timeout, or detecting a deadlock.

For the transaction timeout case, with JTA (eg the current case of Bitronix) too, it can rollback its own transaction after a timeout. This timeout can be set by the Transaction-Manager (TM), using XAResource.setTransactionTimeout.

It is likely that the Bitronix TM is setting the same timeout value in the XADisk's XAResource as its own. When the timeout occurs, the xadisk's own timeout detection triggers and rolls back the xadisk transaction. This rollback erases the transaction information local to xadisk, and this is the reason that, when the TM rollsback the transaction (due to TM's timeout detection mechanism) and invokes xadisk's XAResource, the XAResource reports that it is not aware of the transaction.

So, yes, the reason for these errors is nothing but the Thread.sleep in above code.

I think, the place where xadisk can improve here is throwing away the right kind of exception in the XAResource.end call. I have logged a tracking bug for that: https://java.net/jira/browse/XADISK-156

I hope this gives you some idea. Feel free to discuss further.

Thanks,
Nitin
Re: XaDisk error on timeout transaction Alex Escot 12/4/13 12:30 AM
Hello Nitin,

Okay, I understand why I got a NPE now.

Thank you for your help and your Jira.

Alex