Transaction rollback not rolling back other committed transactions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Transaction rollback not rolling back other committed transactions

Ben Courliss
Transaction rollback not rolling back other committed transactions Hi, I’m a little new to Bitronix and user transactions in general.  I’m having a problem with some code I’ve written that uses Spring 3.x, Tomcat 6, and Bitronix 2.1.0.  I have two DAO’s each connected to the same Oracle XA datasource that modifies two tables.  I have a servlet that calls a service class (SyncEngine.sync) method which in turn calls other methods in the service (SyncEngine.importCE, SyncEngine.importPOR) that then call each of the DAO’s (ceDaoImpl and porDaoImpl).  The problem is I’m seeing the first DAO complete successfully, but I intentionally cause the second DAO call to throw an Exception which causes a rollback.  However it doesn’t rollback the first DAO’s transaction.

Any ideas on where I can go from here?  I’m sure it’s something I don’t have configured correctly.  BTW, thanks for the great library!  

Here’s my configuration and log output:
In Tomcat’s context.xml:
  
<Resource auth="Container" driverClassName="oracle.jdbc.xa.client.OracleXADataSource"
    maxActive="5" maxIdle="2" maxWait="5000" name="jdbc/xacdt" password="***"
    removeAbandoned="true" removeAbandonedTimeout="60" testOnBorrow="true"
    type="javax.sql.DataSource" url="jdbc:oracle:thin:@mydb.com:1521:mysid"
    username="***" validationQuery="select * from dual" />

Spring app context:
  <!-- create BTM transaction manager -->
  <bean id="BitronixTransactionManager" factory-method="getTransactionManager"
    class="bitronix.tm.TransactionManagerServices"
    destroy-method="shutdown" />

  <!-- Spring JtaTransactionManager -->
  <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="BitronixTransactionManager" />
    <property name="userTransaction" ref="BitronixTransactionManager" />
  </bean>

  <jee:jndi-lookup id="cdtXADatasource" jndi-name="jdbc/xacdt" resource-ref="true" />

  <bean id="bulkCEDaoTarget" class="ceDaoImpl">
    <property name="dataSource" ref="cdtXADatasource"/>
  </bean>
  <bean id="bulkCEDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="jtaTransactionManager"/>
    <property name="target" ref="bulkCEDaoTarget"/>
    <property name="transactionAttributes">
      <props>
        <prop key="*">PROPAGATION_MANDATORY, -Exception</prop>
      </props>
    </property>
  </bean>

  <bean id="bulkPORDaoTarget" class="porDaoImpl">
    <property name="dataSource" ref="cdtXADatasource"/>
  </bean>
  <bean id="bulkPORDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="jtaTransactionManager"/>
    <property name="target" ref="bulkPORDaoTarget"/>
    <property name="transactionAttributes">
      <props>
        <prop key="*">PROPAGATION_MANDATORY, -Exception</prop>
      </props>
    </property>
  </bean>
  
  <bean id="syncEngineTarget" class="SyncEngineImpl">
    <property name="customerExpectationDao" ref="bulkCEDao"/>
    <property name="planOfRecordDao" ref="bulkPORDao"/>
  </bean>
  <bean id="syncEngine" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="jtaTransactionManager"/>
    <property name="target" ref="syncEngineTarget"/>
    <property name="transactionAttributes">
      <props>
        <prop key="*">PROPAGATION_REQUIRED, -Exception</prop>
      </props>
    </property>
  </bean>
  
Here is the log file:
2011-01-11 11:19:06 BitronixTransactionManager [DEBUG] beginning a new transaction
2011-01-11 11:19:06 BitronixTransactionManager [DEBUG] dumping 0 transaction context(s)
2011-01-11 11:19:06 TransactionManagerServices [DEBUG] using SyncExecutor
2011-01-11 11:19:06 BitronixTransaction [DEBUG] creating new transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000]
2011-01-11 11:19:06 BitronixTransactionManager [DEBUG] creating new thread context
2011-01-11 11:19:06 BitronixTransactionManager [DEBUG] changing current thread context to a ThreadContext with transaction null, default timeout 60s
2011-01-11 11:19:06 ThreadContext [DEBUG] assigning <a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=NO_TRANSACTION, 0 resource(s) enlisted (started null)> to <a ThreadContext with transaction null, default timeout 60s>
2011-01-11 11:19:06 BitronixTransaction [DEBUG] changing transaction status to ACTIVE
2011-01-11 11:19:06 TransactionLogAppender [DEBUG] between 11656 and 11721, writing a Bitronix TransactionLogRecord with status=ACTIVE, recordLength=57, headerLength=28, time=1294762746792, sequenceNumber=1, crc32=1543153380, gtrid=746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000, uniqueNames=
2011-01-11 11:19:06 TransactionLogAppender [DEBUG] disk journal appender now at position 11721
2011-01-11 11:19:06 BitronixTransaction [DEBUG] transaction status is changing from NO_TRANSACTION to ACTIVE - executing 0 listener(s)
2011-01-11 11:19:06 TaskScheduler [DEBUG] scheduling transaction timeout task on a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011) for Tue Jan 11 11:20:06 EST 2011
2011-01-11 11:19:06 TaskScheduler [DEBUG] removing task by a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011)
2011-01-11 11:19:06 TaskScheduler [DEBUG] scheduled a TransactionTimeoutTask on a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011) scheduled for Tue Jan 11 11:20:06 EST 2011, total task(s) queued: 2
2011-01-11 11:19:06 BitronixTransactionManager [DEBUG] begun new transaction at Tue Jan 11 11:19:06 EST 2011

In here is where my DAO's get called and one of them commits, the other throws an exception.

2011-01-11 11:19:22 BitronixTransactionManager [DEBUG] rolling back transaction a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011)
2011-01-11 11:19:22 TaskScheduler [DEBUG] cancelling transaction timeout task on a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011)
2011-01-11 11:19:22 TaskScheduler [DEBUG] removing task by a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011)
2011-01-11 11:19:22 TaskScheduler [DEBUG] cancelled a TransactionTimeoutTask on a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ACTIVE, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011) scheduled for Tue Jan 11 11:20:06 EST 2011, total task(s) still queued: 1
2011-01-11 11:19:22 BitronixTransaction [DEBUG] rolling back, 0 enlisted resource(s)
2011-01-11 11:19:22 BitronixTransaction [DEBUG] changing transaction status to ROLLING_BACK
2011-01-11 11:19:22 TransactionLogAppender [DEBUG] between 11721 and 11786, writing a Bitronix TransactionLogRecord with status=ROLLING_BACK, recordLength=57, headerLength=28, time=1294762762960, sequenceNumber=2, crc32=1129958291, gtrid=746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000, uniqueNames=
2011-01-11 11:19:22 TransactionLogAppender [DEBUG] disk journal appender now at position 11786
2011-01-11 11:19:22 BitronixTransaction [DEBUG] transaction status is changing from ACTIVE to ROLLING_BACK - executing 0 listener(s)
2011-01-11 11:19:22 AbstractPhaseEngine [DEBUG] executing phase on 0 resource(s) enlisted in 0 position(s) in reverse position order
2011-01-11 11:19:22 Rollbacker [DEBUG] rollback executed on resources []
2011-01-11 11:19:22 Rollbacker [DEBUG] rollback succeeded on resources []
2011-01-11 11:19:22 BitronixTransaction [DEBUG] changing transaction status to ROLLEDBACK
2011-01-11 11:19:22 TransactionLogAppender [DEBUG] between 11786 and 11851, writing a Bitronix TransactionLogRecord with status=ROLLEDBACK, recordLength=57, headerLength=28, time=1294762762961, sequenceNumber=3, crc32=-1796651783, gtrid=746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000, uniqueNames=
2011-01-11 11:19:22 TransactionLogAppender [DEBUG] disk journal appender now at position 11851
2011-01-11 11:19:22 BitronixTransaction [DEBUG] transaction status is changing from ROLLING_BACK to ROLLEDBACK - executing 0 listener(s)
2011-01-11 11:19:22 BitronixTransaction [DEBUG] successfully rolled back a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ROLLEDBACK, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011)
2011-01-11 11:19:22 XAResourceManager [DEBUG] clearing XAResourceHolder states on 0 resource(s)
2011-01-11 11:19:22 BitronixTransaction [DEBUG] after completion, 1 synchronization(s) to execute
2011-01-11 11:19:22 BitronixTransaction [DEBUG] executing synchronization a ClearContextSynchronization for a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ROLLEDBACK, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011) with status=ROLLEDBACK
2011-01-11 11:19:22 BitronixTransactionManager [DEBUG] clearing thread context: a ThreadContext with transaction a Bitronix Transaction with GTRID [746F6D6361742D62746D2D6E6F6465300000012D75DFA39A00000000], status=ROLLEDBACK, 0 resource(s) enlisted (started Tue Jan 11 11:19:06 EST 2011), default timeout 60s

Reply | Threaded
Open this post in threaded view
|

Re: Transaction rollback not rolling back other committed transactions

Ludovic Orban
Administrator
Hi Ben,

This is the log explaining it all:

2011-01-11 11:19:22 BitronixTransaction [DEBUG] rolling back, 0 enlisted resource(s)


you basically didn't configure nor use the BTM connection pool which is mandatory to run 2PC.

From what I've seen in your config, you've configured the transaction manager in Spring but configured a Tomcat connection pool in your context.xml instead of a BTM one.

You have the choice between configuring the transaction manager and connection pool in Spring (as documented in http://docs.codehaus.org/display/BTM/Spring+Framework2x) or in Tomcat (as documented in http://docs.codehaus.org/display/BTM/Tomcat2x) and doing JNDI lookups for both the transaction manager and the connection pools from Spring.

Let me know if this helps or if you need more details.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Transaction rollback not rolling back other committed transactions

Ben Courliss
Thanks Ludovic!  That's exactly what I needed.  I added the XA datasource
configuration to my Spring config file and it seems that worked. I was
trying to configure my datasources in Tomcat and access them as JNDI
references from Spring.  Configuring the datasources in my Spring config
leaves the userid/pwd for the database in my source code, but that's ok for
now until I can configure everything better in the future.

In case anyone who comes across this thread in the future, what I did was
comment out my jndi-lookup from Spring and the Resource section from my
context.xml file and added the following bean reference in my Spring config:
<!--  <jee:jndi-lookup id="cdtXADatasource" jndi-name="jdbc/xacdt"
resource-ref="true" /> -->
<bean id="cdtXADatasource"
class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init"
destroy-method="close">
  <property name="className"
value="oracle.jdbc.xa.client.OracleXADataSource" />
  <property name="uniqueName" value="cdtXADatasource" />
  <property name="maxPoolSize" value="5" />
  <property name="driverProperties">
    <props>
      <prop key="URL">jdbc:oracle:thin:@mydb.com:1521:mysid</prop>
      <prop key="user">***</prop>
      <prop key="password">***</prop>
    </props>
  </property>
</bean>

Ben


On 1/11/11 3:12 PM, "Ludovic Orban" <[hidden email]> wrote:

>
> Hi Ben,
>
> This is the log explaining it all:
>
> 2011-01-11 11:19:22 BitronixTransaction [DEBUG] rolling back, 0 enlisted
> resource(s)
>
>
> you basically didn't configure nor use the BTM connection pool which is
> mandatory to run 2PC.
>
> From what I've seen in your config, you've configured the transaction
> manager in Spring but configured a Tomcat connection pool in your
> context.xml instead of a BTM one.
>
> You have the choice between configuring the transaction manager and
> connection pool in Spring (as documented in
> http://docs.codehaus.org/display/BTM/Spring+Framework2x) or in Tomcat (as
> documented in http://docs.codehaus.org/display/BTM/Tomcat2x) and doing JNDI
> lookups for both the transaction manager and the connection pools from
> Spring.
>
> Let me know if this helps or if you need more details.
>
> Ludovic


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email