Version 23

    Introduction

     

    In this wiki we're going to look at how you can test the recovery capabilities of

    JBossTransactions. We're not going to go into much technical depth here, because the

    manuals cover this in copious detail.

    If you want to know how it works read the manuals. If you want to know why

    it works the way it does, read a good book on transactions.

     

    In the following examples we'll look at recovery in a stand-alone deployment of JBossTransactions. After that, we'll examine recovery when running within JBossAS.

     

    Local JTA Recovery

     

    In this example, we'll use the local JTA implementation that comes with JBossTransactions. In order

    to ensure you've configured JBossTS correctly, check your jbossjts-properties.xml file in the distribution. The following needs to be set:

     

    <property name="com.arjuna.ats.jta.jtaTMImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/>         <property name="com.arjuna.ats.jta.jtaUTImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple"/>

     

    and only the

     

            <property             name="com.arjuna.ats.arjuna.recovery.recoveryExtension5" value="com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule"/>

     

    Clean your ObjectStore directory before proceeding with the examples.

     

    You can remove the jts XARecoveryModule as it is not needed in this example.

     

    Download and build the example code. If you run the example using java Test you'll see output similar to:

     

    ExampleResource: ExampleXAResource (Constructor) ExampleResource: start ExampleResource: ExampleXAResource (Constructor) ExampleResource: isSameRM ExampleResource: start ExampleResource: end ExampleResource: prepare ExampleResource: end ExampleResource: prepare ExampleResource: writeObject (Serialized) ExampleResource: writeObject (Serialized) ExampleResource: commit,xid=< 131075, 51, 25,-3f57fe99:e57e:44742e0f:1--3f57fe99:e57e:44742e0f:0-3f57fe99:e57e:44742e0f:4>,onePhase=false ExampleResource: Sleeping 20000 milliseconds

     

    At this stage the process is blocked and you should kill it. What has happened so far is that two XAResource instances have been created and registered with the transaction. Each has been instructed to prepare and the serialized representation of each instance has been saved within the transaction log. If you look within the ObjectStore directory, you should see a single log entry like:

     

    ObjectStore//HashedActionStore/defaultStore/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/190: total 8 -rw-rr   1 marklitt  wheel  728 May 24 10:57 -3f57fe99_e57e_44742e0f_0

     

    This is the log representing the transaction you have just terminated. We now want recovery to kick in. To do this, run java Test -recover and wait for recovery to run. (You can run recovery explicitly by editing the example or driving it through the Recovery Manager tools: see the manuals for how to do this.)

     

    When recovery runs, you will see something like:

     

    DONE ExampleResource: readObject (Deserialized ExampleResource: readObject (Deserialized ExampleResource: commit,xid=< 131075, 27, 25,1--3f57fe99:e5a0:44743023:e-3f57fe99:e5a0:44743023:f >,onePhase=false ExampleResource: Sleeping 20000 milliseconds ExampleResource: Sleep complete ExampleResource: commit,xid=< 131075, 27, 26,1--3f57fe99:e5a0:44743023:e-3f57fe99:e5a0:44743023:12 >,onePhase=false ExampleResource: Sleeping 20000 milliseconds ExampleResource: Sleep complete

     

    If you look in the ObjectStore, you will see that the log entry has gone because both resources have been fully recovered and committed.

     

    JTS Recovery

     

    In this example, we'll still use the JTA, but this time we will utilise the JTS implementation that comes with JBossTS. First make sure that your jbossjts-properties.xml file is correctly configured. You need:

     

    <property name="com.arjuna.ats.jta.jtaTMImplementation" value="com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple"/>         <property name="com.arjuna.ats.jta.jtaUTImplementation" value="com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple"/>

     

    and

     

            <property             name="com.arjuna.ats.arjuna.recovery.recoveryExtension5" value="com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule"/>

     

    this time.

     

    You also need to add the following to the jta section of your properties file:

     

       <property name="com.arjuna.ats.jta.recovery.XAResourceRecovery2" value="ExampleXAResourceRecovery"/>

     

    Download and compile the example code. The run the example using java Test. You should obtain output similar to:

     

    INFO : oid: 00 14 37 2D 49 49 38 28 01 0C 39                            ..7-II8(..9 object is activated ExampleXAResource1: ExampleXAResource1 (Constructor) ExampleXAResource1: start INFO : oid: 01 14 37 2D 49 49 38 28 01 0C 39                            ..7-II8(..9 object is activated ExampleXAResource2: ExampleXAResource2 (Constructor) ExampleXAResource1: isSameRM ExampleXAResource2: start INFO : oid: 02 14 37 2D 49 49 38 28 01 0C 39                            ..7-II8(..9 object is activated ExampleXAResource1: end ExampleXAResource1: prepare < 131072, 28, 26,1--3f57fe99:e5d9:4474352e:10-3f57fe99:e5d9:4474352e:12 > ExampleXAResource1: writeObject (Serialized) ExampleXAResource2: end ExampleXAResource2: prepare < 131072, 28, 26, 1--3f57fe99:e5d9:4474352e:10-3f57fe99:e5d9:4474352e:16 > ExampleXAResource2: writeObject (Serialized) ExampleXAResource1: commit,xid=< 131072, 28, 26, 1--3f57fe99:e5d9:4474352e:10-3f57fe99:e5d9:4474352e:12 >,onePhase=false ExampleXAResource1: Sleeping 20000 milliseconds

     

    You can safely ignore the JacORB output for the purposes of this test.

     

    Now if you look in the ObjectStore directory you'll see two entries:

     

    PutObjectStoreDirHere//ShadowNoFileLockStore/defaultStore/CosTransactions/XAResourceRecord: total 16 -rw-rr   1 marklitt  wheel  940 May 24 11:27 -3f57fe99_e5d9_4474352e_13 -rw-rr   1 marklitt  wheel  940 May 24 11:27 -3f57fe99_e5d9_4474352e_17

     

    One state log for each registered XAResource. Because the resources are potentially remote, the have responsibility for saving and restoring their own states, rather than being saved within the transaction log as happened previously.

     

    Now execute java Test -recover to start the recovery phase of our example. You'll eventually see:

     

    DONE ExampleXAResource1: readObject (Deserialized INFO : oid: 00 14 37 2D 4A 49 37 1B 10 25                               ..7-JI7..% object is activated ExampleXAResource1: commit,xid=< 131072, 28, 26, 1--3f57fe99:e5d9:4474352e:10-3f57fe99:e5d9:4474352e:12 >,onePhase=false ExampleXAResource1: Sleeping 20000 milliseconds ExampleXAResource2: readObject (Deserialized INFO : oid: 01 14 37 2D 4A 49 37 1B 10 25                               ..7-JI7..% object is activated ExampleXAResource1: Sleep complete INFO : oid: 00 14 37 2D 4A 49 37 1B 10 25                               ..7-JI7..% object is deactivated ExampleXAResource2: commit,xid=< 131072, 28, 26, 1--3f57fe99:e5d9:4474352e:10-3f57fe99:e5d9:4474352e:16 >,onePhase=false ExampleXAResource2: Sleeping 20000 milliseconds ExampleXAResource1: ExampleXAResource1 (Constructor) ExampleXAResource1: recover ExampleXAResource1: recover ExampleXAResource2: ExampleXAResource2 (Constructor) ExampleXAResource2: recover ExampleXAResource2: isSameRM ExampleXAResource2: recover ExampleXAResource2: Sleep complete INFO : oid: 01 14 37 2D 4A 49 37 1B 10 25                               ..7-JI7..% object is deactivated

     

    As each resource is recovered and committed, it's log entry is deleted. So if you look within the ObjectStore, you will see no entries once recovery has completed successfully.

     

    JDBC recovery

     

    See this example for how to do XA recovery for JDBC datasources.

     

    Referenced by: