2 Replies Latest reply on Aug 16, 2013 3:14 PM by Andreas Hess

    Two phase commit timing issue

    Andreas Hess Newbie



      I'm using JBoss AS 7.1.3 (compiled with Java 6 from the GIT Tag). The application that I'm trying to port does (simplified) the following:


      - requests are stored inside a PostgreSQL 9.1 database table from an external application


      - inside @Singleton a @Schedule method runs every couple of minutes and reads all unprocessed requests from the table (JPA query ...getResultList())

      - inside the same transaction each entity is marked as (P)rocessed and the primary key is send to a persistent JMS queue (HornetQ)


      The primary key is send to the queue for the following reason: The entity is using optimistic locking. When we send the full entity the oplock member/column is not yet updated (will be done at the end of the transaction). Every attempt to modify the entity inside the MDB fails with an OptimicticLockException.


      - an MDB receives the primary key messages and reads the full request from the table em.find(....., primary key) and process the request


      Here the issue happens. For the first 1-5 primary keys the em.find() method still retrieves the old version (not marked as processed and therefore with the wrong oplock member/column); an OptimisticLockException is the result. All other messages work without any issue.


      To solve this temp. I now check the status of the entity and re-read until the status is marked, but this is fixing the symptom and not the cause.



           entity = em.find(...);

      } while entity.status == unprocessed);


      The queue is using the java://JmsXA factory. The MDB starts consuming the messages only after the producer method has successfully finished. That's telling me that the basic transaction handling is fine.


      Am I missing something? Any help is appreciated.


      Thanks in advance


        • 1. Re: Two phase commit timing issue
          Wolf-Dieter Fink Master

          That's sounds like that the message is committed and the entity not. i.e all entities are stored after the work is done from the Singleton but the JMS message get's fired (committed) direct and therefore the first messages will be processed and the entity is not written.


          How do you access the entity and the message.


          I would call another bean with (requiresNew tTx) which mark the entity and fire the message.

          • 2. Re: Two phase commit timing issue
            Andreas Hess Newbie


            It turned out that we have real hardware problems on the database server. These issues slowed the disks so much down until the transaction handling stopped working.



            It looks like I have been chasing phantoms and the issues have not been JBoss related after all.


            We'll fix this on Monday. I'll re-run the tests to see if this is the right conclusion.



            Thank you for trying to help