Monday, September 21, 2009

WebLogic XA Transaction Order Of Commit

Recently I came across an interesting discussion at WebLogic forum thread about XA transaction 2PC commit involving JMS resource.

Let me describe the scenario where order of commit becomes very important to achieve expected behavior,
· JDBC database call and JMS send event on local JMS server are part of the single XA transaction.
· MDB receives published message and relies on database update made in XA transactions for further processing.
It was reported at many instances MDB receives the messages and attempts to access database even before database updates in XA transaction are committed. This behavior raised two questions,
· How to guarantee that by the time MDB receive message, database update to have been in committed in database?
· Is it possible to control order of commit so that database update committed before commit in JMS resource?

Expected Behavior?
WebLogic 2PC transactions commit for XA resource runs in parallel in it’s own execution threads and there is no guarantee that which particular XAResource will commit first. Since WebLogic JMS is a local WebLogic XAResource it generally wins race of the 2PC commit over remote database XAResource. Considering this behavior of MDB receiving message before database commit is not a bug or an unexpected behavior. There is nothing, which can be done in WebLogic to force a specific commit order.

It is also important to know that even when JMSStore is a JDBC store and uses same database as SQL requests, JMSStore is committed independently of the SQL requests in XA transactions.

Workaround
It is possible to delay MDB message consumption before database update is committed. JMS Connection factory for message producer can be configured with small time delay using "Default Time-to-Deliver" attribute. Couples of other workarounds are suggesting at discussion thread, however I haven’t validated yet and it may require change in existing implementation.

Labels: