3 Replies Latest reply on May 19, 2008 3:33 PM by Peter Johnson

    XAResource

    Mohit Anchlia Novice

      Could somebody explain me how global transactions work. I understand there are resource managers etc. but what I don't understand is how a transaction is able to commit or rollback all the resources involved during the process. For eg: if data is updated and then a message is sent. So if message fails then how would it rollback the data that was updated. I am assuming data would have to be committed before committing the message so at that point when the data is already committed how is it going to rollback.

      Also when update is called how does the data source or entity manager know not to commit the data ? I am really confused how transaction manager and resource manager interact and who controls whom.

        • 1. Re: XAResource
          Peter Johnson Master

          Basically, XA transactions work like this.

          A transaction manager (TM) will manage multiple resource managers (RM). The app will start a transaction with the TM. As the app make updates, it could update the data in multiple RMs, each of which is then enlisted into the transaction by the TM. Then when the app is done, it tells the TM to commit the transaction. The TM then asks each RM "can you successfully commit the transaction?" If any of the RMs respond "no," then the TM tells each RM to abort the transaction. If every RM responds "yes," then the TM goes back and tells each RM "please commit now." Now, between the "yes I can commit" response from a given RM and the "commit now" from the TM, the given RM could die. In that case, the RM is responsible to recover the transaction when it comes back up.

          • 2. Re: XAResource
            Mohit Anchlia Novice

            Thanks .. some more questions:

            1. Is resouce manager active only for the scope of the transaction ?
            2. So TM tells RM to not autocommit ? Is it possible to explain how and when that happens ?
            3. Do RM need to register with TM ? How does it register and how does TM communicates with RM
            4. In case if there is a failure between "yes ready to commit" and "please commit now" then would all the transaction(s) involved result in rollback ?
            5. We are using Tibco Server along with Jboss. How would the JTA work in this case ? Would Tibco Server need to register itself as a resource manager with JTA ? Where can I see the settings ?

            I read about XAResource, didn't find good article and ones I did find confused me more.

            • 3. Re: XAResource
              Peter Johnson Master

              1) What do you mean by "active"? Examples of RMs included databases. Consider that the app server maintains a pool of database connections, then the database is always "active".
              2) You need to configure the RM correctly. For example, for a database, in the *-ds.xml file you need to use the xa-datasource. Look at the differences in the *-ds.xml and -xa-ds.xml files for a given database in docs/examples/jca. Thus the database must support XA transactions and be configured for XA. In that event, there is no autocommit.
              3) I'm a little hazy on this, but from what I understand, when you start a transaction woth the TM, the transaction object created gets passed to each of the RMs as you do your work. The RM notes the TM from the transaction object.
              4) Once the "commit now" is issued, all RMs would be expected to commit. If one cannot, it needs to do a recovery. There is no rollback at that point. Once the RM says, "yes I can commit," it has guaranteed that the transaction will commit. Any action to the contrary (such as, oops, the disk crashed and I cannot recover) indicates a bug in the RM.
              5) I'm not sure. There are two different standards for XA TMs. JBoss Transactions follows one of them. Many RMs handle only the other. But there is one thing I do know. Is Tibco Server a Java service that can be deployed within JBossAS? If not, then JTA will not do the job. You will need JTS.

              Have you looked at the JBoss Transactions documentation?