Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-10675

JdbcAggregationRepository for Camel Aggregator requires JTA Transactionmanager with global transaction scope(xa=true)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Major
    • None
    • fuse-7.2
    • Camel
    • None
    • % %
    • -
    • Hide

      Test Overview

      Using this reproducer, please try following 4 tests. Detailed instruction to setup/run reproducer is guided at the end of this section.

      Test 1

      Using <delay> component and fixing com.arjuna.ats.arjuna.coordinator.defaultTimeout(3), transaction timeout occurs at all the time.
      So none of aggregate should be completed.

      The test result is all of messages are aggregated, and there are 2 files under /tmp/output directory.
      I guess the reason is <transacted/> is JTA transaction, thus DataSourceTransactionManager could not join the JTA transaction.

      blueprint.xml

      <reference filter="(dataSourceName=datasource4reproducer)"
                 id="datasource4reproducer" interface="javax.sql.DataSource"/>
              
      <!--  PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation.
          If datasource's xa option is false, none of insert query does not persist into postgresql db.
          If xa option is true, it works as expected
                 
          <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
      -->
      
          <!--  DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation -->
      <bean
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <property name="dataSource" ref="datasource4reproducer"/>
      </bean>
         <!-- -->
      

      org.ops4j.datasource-reproducer.cfg

      ~skip~
      pool = dbcp2
      xa = false
      

      Test 2

      For Test 2,fix the transaction manager from DataSourceTransactionManager to PlatformTransactionManager.

      With this settings, none of messages was aggregated. So there is no file under /tmp/output directory. It looks good, but not so really.

      blueprint.xml

      <reference filter="(dataSourceName=datasource4reproducer)"
                 id="datasource4reproducer" interface="javax.sql.DataSource"/>
              
          <!--  PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation.
              If datasource's xa option is false, none of insert query does not persist into postgresql db.
              If xa option is true, it works as expected
          -->           
      <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
          <!-- -->
      
          <!--  DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation
          <bean
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
            <property name="dataSource" ref="datasource4reproducer"/>
          </bean>
          -->
      

      Test 3

      Now, Test 3 is for success pattern test with the test 2 settings. This route would aggregate all of messages.
      Please comment out the <delay> component for sleep, and set back to default com.arjuna.ats.arjuna.coordinator.defaultTimeout.

      The result was none of message was aggregated. There is no file under /tmp/output directory.

      blueprint.xml

      <reference filter="(dataSourceName=datasource4reproducer)"
                 id="datasource4reproducer" interface="javax.sql.DataSource"/>
              
          <!--  PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation.
              If datasource's xa option is false, none of insert query does not persist into postgresql db.
              If xa option is true, it works as expected
          -->           
      <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
          <!-- -->
      
          <!--  DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation
          <bean
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
            <property name="dataSource" ref="datasource4reproducer"/>
          </bean>
          -->
      ~~skip~~    
          <!-- Delay t make a transaction timeout exception
          <delay id="_delay1">
            <constant id="5sec">5000</constant>
          </delay>
          -->
      

      org.ops4j.datasource-reproducer.cfg

      pool = dbcp2
      xa = false
      

      Test 4

      believe or not, please fix the datasource settings file to enable xa option.
      With this setting, it works as expected.

      blueprint.xml

      <reference filter="(dataSourceName=datasource4reproducer)"
                 id="datasource4reproducer" interface="javax.sql.DataSource"/>
              
          <!--  PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation.
              If datasource's xa option is false, none of insert query does not persist into postgresql db.
              If xa option is true, it works as expected
          -->           
      <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
          <!-- -->
      
          <!--  DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation
          <bean
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
            <property name="dataSource" ref="datasource4reproducer"/>
          </bean>
          -->
      ~~skip~~    
          <!-- Delay t make a transaction timeout exception
          <delay id="_delay1">
            <constant id="5sec">5000</constant>
          </delay>
          -->
      

      org.ops4j.datasource-case02383718.cfg

      pool = dbcp2
      xa = true
      

      Detailed Instruction For This Reproducer

      (1) setup Postgresql

      create database reproducer;
      CREATE DATABASE
      # \c reproducer
      You are now connected to database "reproducer" as user "postgres".
      
      CREATE TABLE aggregation (
       id varchar(255) NOT NULL,
       exchange bytea NOT NULL, 
       constraint aggregation_pk PRIMARY KEY (id) 
      );
        
      CREATE TABLE aggregation_completed (
       id varchar(255) NOT NULL,
       exchange bytea NOT NULL,
       constraint aggregation_completed_pk PRIMARY KEY (id) 
      );
      

      (2) build reproducer

      download and unzip the attached reproducer.zip
      cd reproducer
      mvn clean install
      

      (3) set up Fuse 7.2 standalone karaf

      cp org.ops4j.datasource-reproducer.cfg $FUSE_HOME/etc
      ./bin/fuse
      karaf@root()> feature:repo-add  file://${FULLPATH_TO}/features.xml
      Adding feature url file://${FUSEPATH_TO}/features.xml
      feature:install datasource4reproducer
      // tuning transaction timeout to  force timeout
      karaf@root()> config:edit org.ops4j.pax.transx.tm.narayana
      karaf@root()> config:property-set com.arjuna.ats.arjuna.coordinator.defaultTimeout 3
      karaf@root()> config:update
      // install reproducer
      karaf@root()> osgi:install -s mvn:support.redhat/reproducer/1.0.0-SNAPSHOT
      
      Show
      Test Overview Using this reproducer, please try following 4 tests . Detailed instruction to setup/run reproducer is guided at the end of this section . Test 1 Using <delay> component and fixing com.arjuna.ats.arjuna.coordinator.defaultTimeout(3), transaction timeout occurs at all the time. So none of aggregate should be completed. The test result is all of messages are aggregated, and there are 2 files under /tmp/output directory. I guess the reason is <transacted/> is JTA transaction, thus DataSourceTransactionManager could not join the JTA transaction. blueprint.xml <reference filter="(dataSourceName=datasource4reproducer)" id="datasource4reproducer" interface="javax.sql.DataSource"/> <!-- PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation. If datasource's xa option is false, none of insert query does not persist into postgresql db. If xa option is true, it works as expected <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/> --> <!-- DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation --> <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager"> <property name="dataSource" ref="datasource4reproducer"/> </bean> <!-- --> org.ops4j.datasource-reproducer.cfg ~skip~ pool = dbcp2 xa = false Test 2 For Test 2,fix the transaction manager from DataSourceTransactionManager to PlatformTransactionManager. With this settings, none of messages was aggregated. So there is no file under /tmp/output directory. It looks good, but not so really. blueprint.xml <reference filter="(dataSourceName=datasource4reproducer)" id="datasource4reproducer" interface="javax.sql.DataSource"/> <!-- PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation. If datasource's xa option is false, none of insert query does not persist into postgresql db. If xa option is true, it works as expected --> <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/> <!-- --> <!-- DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager"> <property name="dataSource" ref="datasource4reproducer"/> </bean> --> Test 3 Now, Test 3 is for success pattern test with the test 2 settings. This route would aggregate all of messages. Please comment out the <delay> component for sleep, and set back to default com.arjuna.ats.arjuna.coordinator.defaultTimeout. The result was none of message was aggregated. There is no file under /tmp/output directory. blueprint.xml <reference filter="(dataSourceName=datasource4reproducer)" id="datasource4reproducer" interface="javax.sql.DataSource"/> <!-- PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation. If datasource's xa option is false, none of insert query does not persist into postgresql db. If xa option is true, it works as expected --> <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/> <!-- --> <!-- DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager"> <property name="dataSource" ref="datasource4reproducer"/> </bean> --> ~~skip~~ <!-- Delay t make a transaction timeout exception <delay id="_delay1"> <constant id="5sec">5000</constant> </delay> --> org.ops4j.datasource-reproducer.cfg pool = dbcp2 xa = false Test 4 believe or not, please fix the datasource settings file to enable xa option. With this setting, it works as expected. blueprint.xml <reference filter="(dataSourceName=datasource4reproducer)" id="datasource4reproducer" interface="javax.sql.DataSource"/> <!-- PlatformTransactionManager: does rollback when transaction timeout occurs after aggregation. If datasource's xa option is false, none of insert query does not persist into postgresql db. If xa option is true, it works as expected --> <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/> <!-- --> <!-- DataSourceTransactionManager: does not rollback as expected when transaction timeout occurs after aggregation <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager"> <property name="dataSource" ref="datasource4reproducer"/> </bean> --> ~~skip~~ <!-- Delay t make a transaction timeout exception <delay id="_delay1"> <constant id="5sec">5000</constant> </delay> --> org.ops4j.datasource-case02383718.cfg pool = dbcp2 xa = true Detailed Instruction For This Reproducer (1) setup Postgresql create database reproducer; CREATE DATABASE # \c reproducer You are now connected to database "reproducer" as user "postgres". CREATE TABLE aggregation ( id varchar(255) NOT NULL, exchange bytea NOT NULL, constraint aggregation_pk PRIMARY KEY (id) ); CREATE TABLE aggregation_completed ( id varchar(255) NOT NULL, exchange bytea NOT NULL, constraint aggregation_completed_pk PRIMARY KEY (id) ); (2) build reproducer download and unzip the attached reproducer.zip cd reproducer mvn clean install (3) set up Fuse 7.2 standalone karaf cp org.ops4j.datasource-reproducer.cfg $FUSE_HOME/etc ./bin/fuse karaf@root()> feature:repo-add file://${FULLPATH_TO}/features.xml Adding feature url file://${FUSEPATH_TO}/features.xml feature:install datasource4reproducer // tuning transaction timeout to force timeout karaf@root()> config:edit org.ops4j.pax.transx.tm.narayana karaf@root()> config:property-set com.arjuna.ats.arjuna.coordinator.defaultTimeout 3 karaf@root()> config:update // install reproducer karaf@root()> osgi:install -s mvn:support.redhat/reproducer/1.0.0-SNAPSHOT

    Description

      JdbcAggregationRepository for Camel Aggregator requires JTA Transactionmanager with global transaction scope(xa=true).
      With DataSourceTransactionManager, aggregator does not rollback when transaction timeout occurs after aggregation.
      With PlatformTransactionManager without enabling xa option for datasource, aggregator does not persist any message even there is no exception occurs.

      Attachments

        1. features.xml
          0.4 kB
        2. org.ops4j.datasource-reproducer.cfg
          0.3 kB
        3. reproducer.zip
          12 kB

        Activity

          People

            ggrzybek Grzegorz Grzybek
            rhn-support-hfuruich Hisao Furuichi
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: