1 2 Previous Next 17 Replies Latest reply on Feb 22, 2013 9:08 AM by Steven Hawkins

    Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server

    sivajd Newbie

      Team,

       

      Our environment consists of EclipseLink's JPA with Dynamic Entities going through Teiid subsystem.

      Teiid requires the use of  Local Connections to propagate the Security Principal from the Web Container to the JPA layer all the way to the translator layer.

      We have developed CustomTranslator along with a Custom Connector. Any Create/Update/Delete (CUD) operations

      from the JPA are not getting committed to the database until we shut down the jboss server. As part of the

      JPA logging we would see that all the transactional operations are successful but we would never see the changes in the

      database. As soon as we shutdown the server all of the transactions are sent to the database at once and we would see

      the changes corresponding to the transactions reflect in the database. This behavior is happening only when we use Local Connections.

       

      If we revert back to the Remote / Socket based connection we would not see this behavior. We would see the transactional updates right away.

      We are forced to use the LocalConnections to propage the SecurityPrincipal all the way upto the Translator layer.

       

      One more interesting observation is that this happens only if we use our  Custom Translator. If we use any of the standard translators that are provided

      by Teiid we do not see this behavior in either of the above Connection types.

       

      Can one of you shed some light on this ? Did you see this behavior before ? 

      Please let me know if any of my assumptions are not accurate...

       

      Thanks

      Siva

        • 1. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
          Ramesh Reddy Master

          Siva,

           

          Since the transaction boundaries are controlled in your JPA layer, you need to use LocalTransaction. See this documentation https://docs.jboss.org/author/display/TEIID/Transaction+Support

           

          In the LocalConnection scenario, the transaction context is passed from your JPA layer into Teiid though thread context. For whatever reason the transaction commit is not passed IMO.  Hard to figure out with out looking at code. If you can provide a testcase that would be helpful.

           

          Also, translators are not directly involved transactions but connectors are. Have you used the framework provided in teiid-api project to write your RAR file?

           

          Ramesh..

          • 2. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
            Steven Hawkins Master

            Siva,

             

            If you use the TeiidDataSource through an XA aware transaction pool and you obtain a Teiid connection when the transaction is active, then both the local/socket connections should both be enlisted in the current transaction which will make the Teiid engine behave transactionally.  If you are not getting that behavior with local connections, then there is an issue.

             

            If you manually make a local/socket based connection then it is up to your application logic to make the connection transactionally aware.  In this case if you are only making a connection to Teiid and/or do not need 2 phase commit, then you can just start a local transaction on the connection.

             

            > In the LocalConnection scenario, the transaction context is passed from your JPA layer into Teiid though thread context. For whatever reason the transaction commit is not passed IMO.

             

            We do have code for Teiid Embedded that allows for its connections to be non-pooled yet automatically aware of a thread bound transaction, but otherwise with a server deployment having a thread bound transaction is not suffcient to make Teiid aware of the transaction.  This behavior can be approximated though.  If using a local connection, and you have the engine source concurrency set to 1, and it's using the calling thread (which is the default), then the application thread will be responsible for all processing.  This in turns means that any connections obtained by Teiid from a transactional pool, will be enlisted.  However Teiid itself (mainly for temp table usage) would not be aware of the transaction in this case.

             

            Steve

            • 3. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
              sivajd Newbie

              Steven & Ramesh,

               

              Thank you for your answers. I have few questions though.

               

              Steven Wrote:

              If you use the TeiidDataSource through an XA aware transaction pool and you obtain a Teiid connection when the transaction is active, then both the local/socket connections should both be enlisted in the current transaction which will make the Teiid engine behave transactionally.  If you are not getting that behavior with local connections, then there is an issue.

               

              Q: How can I create an XA aware transaction pool to Teiid dynamically, ie I mean programmatically, and obtain a Teiid Connection from it ?  The documentation mentions only a static way to create a XA aware pool  ie by creating *-ds.xml file and deploying it to the deployments folder in jboss-as7 ?

               

              Steven Wrote:

              If you manually make a local/socket based connection then it is up to your application logic to make the connection transactionally aware.  In this case if you are only making a connection to Teiid and/or do not need 2 phase commit, then you can just start a local transaction on the connection.

               

              Q: Can you give an example on "making a connection transactionally aware " ? or any references to sample code ?

                   Currently in our implementation we are using Dynamic JPA and we are starting transactions using the following code sample given below. Let me know if this is correct or if I have to do something else.

               



              EntityManager em = context.getEntityManager();


              EntityTransaction tx = em.getTransaction();


              tx.begin();

               

               

              Steven Wrote:

              We do have code for Teiid Embedded that allows for its connections to be non-pooled yet automatically aware of a thread bound transaction, but otherwise with a server deployment having a thread bound transaction is not suffcient to make Teiid aware of the transaction.  This behavior can be approximated though.  If using a local connection, and you have the engine source concurrency set to 1, and it's using the calling thread (which is the default), then the application thread will be responsible for all processing.  This in turns means that any connections obtained by Teiid from a transactional pool, will be enlisted.  However Teiid itself (mainly for temp table usage) would not be aware of the transaction in this case.

               

              Q: The first statement in the above paragraph is something that I am very much interested and would like to know how you would make Teiid transaction aware ? Is it possible for you to point me to the class where this is being done in the souce code of Teiid Embedded. I also would like to if there any pointers to the documentation.

               

              I know I am asking for too much...but any help is very much appreciated.

               

              Thanks and regards

              Siva

              • 4. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                Steven Hawkins Master

                > Q: How can I create an XA aware transaction pool to Teiid dynamically, ie I mean programmatically, and obtain a Teiid Connection from it ?  The documentation mentions only a static way to create a XA aware pool  ie by creating *-ds.xml file and deploying it to the deployments folder in jboss-as7 ?

                 

                How are you programatically creating/using connections right now?  What needs to be dynamic that can't be captured by a traditional pool?

                 

                > Q: Can you give an example on "making a connection transactionally aware " ? or any references to sample code ?

                 

                See the link Ramesh gave for transaction support.  A local transaction with JDBC follows the pattern:

                 

                Connection c = ...

                c.setAutoCommit(false); //starts a local transaction

                c.commit() //or c.setAutoCommit(true) or c.rollback() to end the transaction

                 

                > Currently in our implementation we are using Dynamic JPA and we are starting transactions using the following code sample given below. Let me know if this is correct or if I have to do something else.

                 

                That code is fine.  The question is how are you supplying Teiid Connections to the JPA layer.

                 

                > Q: The first statement in the above paragraph is something that I am very much interested and would like to know how you would make Teiid transaction aware ? Is it possible for you to point me to the class where this is being done in the souce code of Teiid Embedded. I also would like to if there any pointers to the documentation.


                org.teiid.runtime.EmbeddedServer has an extension to the TransactionService that looks for thread bound transactions.  That code is of course currently specific to the EmbeddedServer and not utilized by local connections in server deployments (mainly because of the assumption that those connections would be utilized from a transactional pool).

                 

                Steve

                • 5. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                  kchen007 Apprentice

                  Steve:

                   

                  Siva and I worked together. Here is what I find with some debugging into Teiid:

                   

                  First, for local connection, we define the following url:

                       jdbc:teiid:%s;ApplicationName=%s

                      

                  For socket based connection, we use:

                       dbc:teiid:%s@mm://%s:%s;ApplicationName=%s

                   

                   

                  In the socket connection, the working call stack looks like this:

                  OWTXAResource.commit(Xid, boolean) line: 42   // this is our resource adapter that will do the commit work.
                  XAResourceWrapperImpl.commit(Xid, boolean) line: 90
                  XAResourceRecord.topLevelOnePhaseCommit() line: 667
                  AtomicAction(BasicAction).onePhaseCommit(boolean) line: 2283
                  AtomicAction(BasicAction).End(boolean) line: 1466
                  AtomicAction(TwoPhaseCoordinator).end(boolean) line: 98
                  AtomicAction(AtomicAction).commit(boolean) line: 164
                  TransactionImple.commitAndDisassociate() line: 1165
                  TransactionManagerImple(BaseTransaction).commit() line: 117
                  TransactionManagerDelegate(BaseTransactionManagerDelegate).commit() line: 75
                  TransactionServerImpl.commitDirect(TransactionContext) line: 387
                  TransactionServerImpl.commit(String) line: 449

                   

                  but In local connection case, it never reach our commit code, but it did reach the code with underline, I guess somehow the TransactionImple does not know this is XA transaction.

                   

                  So, is there any other attribute we need set for local connection case? I have tried to set the autoCommitTx to OFF and it seems does not help.

                   

                  Thanks

                  Kevin

                  • 6. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                    kchen007 Apprentice

                    Another clarification, even with Teiid built-in translator, in the  local connection case, the data will not be commited to database when you define your JDBC url with autocommit to false.

                     

                    for example, I am using h2 db and use h2 translator, if I define data source as

                         jdbc:h2:C:\Landmark\DSDataServer5000.8.2\ApplicationServer\standalone\data\testdata;AUTOCOMMIT=OFF;AUTO_SERVER=TRUE

                    then the change will not be commited to database.

                     

                    If I remove AUTOCOMMIT=OFF, then it will be commited to database, this is because each update is treated as single transaction.

                     

                    • 7. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                      Steven Hawkins Master

                      (to clarify this is response to message 5) In both cases you are not making connections through an XA pool correct? Presumably EclipseLink is handling associating a transaction with the Connection.  We can infer from the stack trace above by TransactionServerImpl.commit(String) that a local transaction is being used.  So in the socket case you are acting on a new server thread and starting a new transaction that is basically unrelated to the JPA transaction.  In the local connection case we are eventually calling TransactionManager.begin while there should also be a thread bound transaction, implying that a subtransaction is being started.

                       

                      From there it's likely a problem that just the subtransaction is being committed (that's why you're seeing a commit either way) and possibly that by setting a subtransaction with the thread subsequent application logic may not be working as expected.

                       

                      > So, is there any other attribute we need set for local connection case? I have tried to set the autoCommitTx to OFF and it seems does not help.

                       

                      autoCommitTx is for when the connection autoCommit=true, and does not have an effect if you are otherwise under a transaction.

                       

                      If the diagnosis from above is correct then there isn't a straight-forward workaround as the setAutoCommit call by the client in the local case will be the same thread that attempts to start another transaction in the TransactionServerImpl.  There are two possible lines of attack to support this:

                       

                      1. is to attempt to properly support a subtransaction, which ends up being a fair amount of work.

                      2. would be to promote the same basic logic as the EmbeddedServer to use the thread bound transaction rather than starting a new one.  There is already an existing workaround if you then also need to disable EclipseLink's use of the local transaction (the disableLocalTxn property).

                       

                      Steve

                      • 8. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                        kchen007 Apprentice

                        Thanks Steve.

                         

                        How can I tell if the connections is made from XA pool? in the jboss configuration xml file, we define our resource adpater sort of like this:

                         

                                        <resource-adapter>
                                            <archive>
                                                owtconnect.rar
                                            </archive>
                                            <transaction-support>XATransaction</transaction-support>
                                            <connection-definitions>
                                                <connection-definition class-name="OWTManagedConnectionFactory" jndi-name="java:/OW_TEIID" enabled="true" use-java-context="true" pool-name="OW_TEIID">
                                                    <xa-pool>
                                                        <min-pool-size>5</min-pool-size>
                                                        <max-pool-size>10</max-pool-size>
                                                    </xa-pool>
                                                    <security>
                                                        <security-domain>SecurityDomain</security-domain>
                                                    </security>
                                                    <recovery no-recovery="false">
                                                        <recover-plugin class-name="OWTRecoveryPlugin"/>
                                                    </recovery>
                                                </connection-definition>

                        Thanks

                        Kevin

                        • 9. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                          Steven Hawkins Master

                          That's for you source pool below Teiid correct?  That looks fine and will work under normal circumstances.  I've logged https://issues.jboss.org/browse/TEIID-2394 - which is described as option 2 above - to handle your scenario more automatically.

                           

                          Steve

                          • 11. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                            kchen007 Apprentice

                            Steve:

                             

                            I saw you fixed the issed on 02/14, how can I downlad the nightly build to test it?

                             

                            Thanks

                            Kevin

                            • 13. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                              kchen007 Apprentice

                              Thanks Steven. I found the snapshot teiid-8.3.0.Beta3-20130216.081939-1-jboss-dist.zip, it was built on 02/16, and the fix is marked as 02/14.

                               

                              After taking the snapshot, It still does not work. I am using

                                   jdbc:teiid:%s;disableLocalTxn=true;ApplicationName=%s

                               

                              as connection url.

                               

                              Is there any other steps that I need to take?

                               

                              Thanks,
                              Kevin

                              • 14. Re: Local Connections based transactional changes get reflected in the database only on shutdown of the jboss server
                                kchen007 Apprentice

                                Steven:

                                 

                                If I remove disableLocalTxn=true from the connection url, the transaction go through.

                                 

                                Thanks

                                Kevin

                                1 2 Previous Next