XA Disk behaviour

145 views
Skip to first unread message

kristof.de...@gmail.com

unread,
Mar 21, 2014, 12:08:45 PM3/21/14
to xad...@googlegroups.com
Hello,

I am already working 5 years on an application where I work a lot with files. Sometimes it is desired to have some transactional behaviour.

I think XA disk is pretty cool but it doesn't work like I had in mind. But perhaps I am doing something wrong orso ...

I don't think I need a XA session because I stay in the same JVM (as told on the website)

public class XaTransactionExample {

    private static final String XA_NAMESPACE = "D:\\XADiskSystem1";

    public static void main(String[] args) {
        try {
            new XaTransactionExample().execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void execute() throws Exception {

        System.out.println("Creating XA-disk instance ...");

        Session session = null;
        TransactionManager transactionManager = null;
        XAFileSystem fileSystem = null;
        try {
            StandaloneFileSystemConfiguration xaConfiguration = new StandaloneFileSystemConfiguration(XA_NAMESPACE, "1");

            fileSystem = XAFileSystemProxy.bootNativeXAFileSystem(xaConfiguration);
            System.out.println("Creating XA-disk file system ...");

            fileSystem.waitForBootup(-1);
            System.out.println("Successfully started up XA-disk instance ...");

            System.out.println("Creating XA-disk transaction manager ...");

            transactionManager = new UserTransactionManager();
            transactionManager.begin();
            System.out.println("XA-transaction has been started ...");

            session = fileSystem.createSessionForLocalTransaction();
            System.out.println("XA-session has been created ...");

            System.out.println("Performing actions ...");
            session.createFile(new File("D:\\xa\\test.txt"), false);
            session.deleteFile(new File("D:\\xa\\THS - Disc Over.aif"));

            session.commit(); //or transactionManager.commit(); same behaviour...

            System.out.println("XA-transaction has been committed ...");

        } catch (Exception ex) {
            session.rollback();
            System.out.println("XA-transaction has been rolled back ...");

            ex.printStackTrace();
        } finally {
            if(fileSystem != null) {
                System.out.println("XA-disk is shutting down ...");
                fileSystem.shutdown();
            }
        }
    }
}

The example above is almost identic to your example on your website. I am just playing with it before I integrate it in my application.

I have 2 files. 1 I want to create and 1 file should be deleted and this should be transactional. But the file that should be deleted is an audio file that is playing at that moment.

Actual behaviour: file is created and then timeout on delete ... no rollback of created file
Expeted behaviour: file is not created (rollback) and file is not deleted (rollback)

Any thoughts ? :)

Thanks in advance.

Greetings,

Kristof

Nitin Verma

unread,
Mar 21, 2014, 12:41:59 PM3/21/14
to xad...@googlegroups.com, kristof.de...@gmail.com
Hello Kristof,

If a file is under use, it is expected that the commit operation will throw an exception (TransactionFailedException) while trying to delete the file (and hence failing because the file is in use).

Can you please confirm if you receive the TransactionFailedException? If yes, please refer to the javadoc for TransactionFailedException (https://xadisk.java.net/javadoc/1.2.2/org/xadisk/filesystem/exceptions/TransactionFailedException.html) regarding how to handle such failed transactions.

Please let me know if you have any questions.

Thanks,
Nitin

kristof.de...@gmail.com

unread,
Mar 21, 2014, 1:58:04 PM3/21/14
to xad...@googlegroups.com, kristof.de...@gmail.com
Hello Nitin,

I'll check it ASAP and come back to you.

Thanks for info.

Cheers,

Kristof

Op vrijdag 21 maart 2014 17:41:59 UTC+1 schreef Nitin Verma:

Sikke Meister

unread,
Mar 24, 2014, 1:01:44 PM3/24/14
to xad...@googlegroups.com
"C:\Program Files\Java\jdk1.7.0_21\bin\java" -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_21\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_21\jre\lib\ext\zipfs.jar;C:\Development\myprojects\test\target\classes;C:\Development\frameworks\zip4j_1.3.2.jar;C:\Users\kdebruy1\.m2\repository\org\bouncycastle\bcprov-jdk16\1.46\bcprov-jdk16-1.46.jar;C:\Users\kdebruy1\.m2\repository\net\java\xadisk\xadisk\1.2.2\xadisk-1.2.2.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\atomikos-util\3.6.4\atomikos-util-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-api\3.6.4\transactions-api-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-jdbc-deprecated\3.6.4\transactions-jdbc-deprecated-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-jdbc\3.6.4\transactions-jdbc-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-jms-deprecated\3.6.4\transactions-jms-deprecated-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-jms\3.6.4\transactions-jms-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-jta\3.6.4\transactions-jta-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions\3.6.4\transactions-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\com\atomikos\transactions-hibernate3\3.6.4\transactions-hibernate3-3.6.4.jar;C:\Users\kdebruy1\.m2\repository\org\apache\geronimo\specs\geronimo-jta_1.0.1B_spec\1.0.1\geronimo-jta_1.0.1B_spec-1.0.1.jar;C:\Users\kdebruy1\.m2\repository\javax\jms\jms\1.1\jms-1.1.jar;C:\Users\kdebruy1\.m2\repository\org\hibernate\hibernate\3.2.5.ga\hibernate-3.2.5.ga.jar;C:\Users\kdebruy1\.m2\repository\net\sf\ehcache\ehcache\1.2.3\ehcache-1.2.3.jar;C:\Users\kdebruy1\.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;C:\Users\kdebruy1\.m2\repository\commons-collections\commons-collections\2.1.1\commons-collections-2.1.1.jar;C:\Users\kdebruy1\.m2\repository\javax\transaction\jta\1.0.1B\jta-1.0.1B.jar;C:\Users\kdebruy1\.m2\repository\asm\asm-attrs\1.5.3\asm-attrs-1.5.3.jar;C:\Users\kdebruy1\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\kdebruy1\.m2\repository\antlr\antlr\2.7.6\antlr-2.7.6.jar;C:\Users\kdebruy1\.m2\repository\cglib\cglib\2.1_3\cglib-2.1_3.jar;C:\Users\kdebruy1\.m2\repository\asm\asm\1.5.3\asm-1.5.3.jar;C:\Users\kdebruy1\.m2\repository\javax\resource\connector-api\1.5\connector-api-1.5.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain be.base.core.XaTransactionExample
Creating XA-disk instance ...
Creating XA-disk file system ...
Successfully started up XA-disk instance ...
Creating XA-disk transaction manager ...
No properties path set - looking for transactions.properties in classpath...
transactions.properties not found - looking for jta.properties in classpath...
Failed to open transactions properties file - using default values
XA-transaction has been started ...
XA-session has been created ...
Performing actions ...
XA-transaction has been rolled back ...
XA-disk is shutting down ...
org.xadisk.filesystem.exceptions.TransactionFailedException: The transaction has failed and has not completed commit or rollback. The file-system data operated on by the transaction may be in inconsistent state. This exception is not expected to occur in general, and indicates a severe problem.
at org.xadisk.filesystem.NativeSession.commit(NativeSession.java:747)
at org.xadisk.filesystem.NativeSession.commit(NativeSession.java:1339)
at be.base.core.XaTransactionExample.execute(XaTransactionExample.java:55)
at be.base.core.XaTransactionExample.main(XaTransactionExample.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.IOException: The i/o operation could not be completed for the file/directory with path [D:\xa\THS - Disc Over.aif] due to an unknown reason.
at org.xadisk.filesystem.utilities.FileIOUtility.doGCBeforeRetry(FileIOUtility.java:143)
at org.xadisk.filesystem.utilities.FileIOUtility.deleteFile(FileIOUtility.java:62)
at org.xadisk.filesystem.DurableDiskSession.deleteFile(DurableDiskSession.java:148)
at org.xadisk.filesystem.NativeSession.commitDeleteFile(NativeSession.java:868)
at org.xadisk.filesystem.NativeSession.commit(NativeSession.java:689)
... 8 more

Process finished with exit code 0


This is the output. So the file is not deleted but the other file shouldn't be created as well.

Nitin Verma

unread,
Mar 26, 2014, 4:35:15 AM3/26/14
to xad...@googlegroups.com, kristof.de...@gmail.com
As you are receiving TransactionFailedException, it means xadisk itself cannot really commit/rollback this transaction. So, this will need the manual intervention to mark the transaction complete. Please refer to the javadoc for TransactionFailedException. Let me know if you have any questions.

Thanks,
Nitin

Reply all
Reply to author
Forward
0 new messages