2011-08-10 48 views
3

在兩個Websphere節點中運行的Java程序中,以下競爭場景發生在由Websphere Transaction Manager管理的分佈式事務中。事務跨越JMS(Websphere-MQ)事務源和數據庫(Oracle)事務源。我想了解爲什麼在stage3CommitProcessing期間事務回滾?

  • 爲什麼這個(例外在線程2,在步驟B6)的例外發生了什麼?我期望沒有問題發生。線程2只有在事務TX2中確保T1被鎖定之後才能繼續進行,因此線程1正在等待T1表鎖定(在事務TX1內)釋放。我想知道的是爲什麼線程2遇到stage3CommitProcessing異常?我怎麼能得到更多的細節,因爲這個例外沒有透露任何有關它的信息?
  • 如何調試這種事務相關的比賽場景?我知道這可能很難重現。但是我認爲可能會有一些Websphere相關的日誌,我可以在Stage3中看到提交失敗的原因。如果有人能指出我的這個方向,那將會很棒。
  • 如何避免/解決?

線程1(在WebSphere節點運行1)

A1: Start TX1 
A2: Read messages (maximum of 1000 at a time) from Queue Q1 
A3: LOCK TABLE T1 IN EXCLUSIVE MODE 
     Got exception "ORA-02049": distributed transaction waiting for lock. 
Refer Log 1 for stack trace 

線程2(運行在WebSphere節點2)

B1: Start TX2 
B2: Read messages (maximum of 1000 at a time) from Queue Q1 
B3: LOCK TABLE T1 IN EXCLUSIVE MODE 
B4: Batch execute 
    MERGE INTO T1 the messages read 
B5: Batch insert messages into T2 
B6: Commit TX2 
    Got JTA transaction unexpectedly rolled back (maybe due to a timeout). Refer Log 2 for stack trace. This was while ***stage3CommitProcessing***. 

日誌1:

org.springframework.jdbc.BadSqlGrammarException:StatementCallback;錯誤的SQL語法[LOCK TABLE T1 IN EXCLUSIVE MODE];嵌套異常是java.sql.SQLSyntaxErrorException:ORA-02049:超時:分佈式事務等待鎖

at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:94) 
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:406) 
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:518) 
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:248) 
at com.test.OracleTableLock.processMessage(OracleTableLock.java:52) 
at sun.reflect.GeneratedMethodAccessor833.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
at $Proxy153.receiveMessage(Unknown Source) 
at com.test.BatchProcessor.processMessage(BatchProcessor.java:343) 
at sun.reflect.GeneratedMethodAccessor779.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
at $Proxy155.receiveMessage(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor778.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) 
at org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.java:65) 
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:51) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:453) 
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:329) 
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:162) 
at org.springframework.scheduling.commonj.TimerManagerTaskScheduler$TimerScheduledFuture.timerExpired(TimerManagerTaskScheduler.java:112) 
at com.ibm.ws.asynchbeans.timer.TimerImpl.callListenerMethod(TimerImpl.java:298) 
at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:216) 
at com.ibm.ws.asynchbeans.J2EEContext$RunProxy.run(J2EEContext.java:264) 
at java.security.AccessController.doPrivileged(AccessController.java:224) 
at javax.security.auth.Subject.doAs(Subject.java:495) 
at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:131) 
at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:89) 
at com.ibm.ws.asynchbeans.J2EEContext$DoAsProxy.run(J2EEContext.java:335) 
at java.security.AccessController.doPrivileged(AccessController.java:251) 
at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1146) 
at com.ibm.ws.asynchbeans.timer.TimerImpl.runListenerAsCJWork(TimerImpl.java:425) 
at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:333) 
at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:230) 
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) 
Caused by: java.sql.SQLSyntaxErrorException: ORA-02049: timeout: distributed transaction waiting for lock 

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91) 
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133) 
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206) 
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455) 
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413) 
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034) 
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:183) 
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:942) 
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222) 
at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1706) 
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1674) 
at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:275) 
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.pmiExecuteUpdate(WSJdbcStatement.java:1683) 
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeUpdate(WSJdbcStatement.java:1041) 
at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:508) 
at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:1) 
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395) 
... 50 more 

日誌2:

org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException 
    at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1012) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) 
    at com.test.BatchProcessor.processMessage(BatchProcessor.java:359) 
    at sun.reflect.GeneratedMethodAccessor1541.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
    at java.lang.reflect.Method.invoke(Method.java:600) 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy204.receiveMessage(Unknown Source) 
    at sun.reflect.GeneratedMethodAccessor1540.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
    at java.lang.reflect.Method.invoke(Method.java:600) 
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) 
    at org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.java:65) 
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:51) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:453) 
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:329) 
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java) 
    at org.springframework.scheduling.commonj.TimerManagerTaskScheduler$TimerScheduledFuture.timerExpired(TimerManagerTaskScheduler.java:112) 
    at com.ibm.ws.asynchbeans.timer.TimerImpl.callListenerMethod(TimerImpl.java:298) 
    at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:216) 
    at com.ibm.ws.asynchbeans.J2EEContext$RunProxy.run(J2EEContext.java:264) 
    at java.security.AccessController.doPrivileged(AccessController.java:224) 
    at javax.security.auth.Subject.doAs(Subject.java:495) 
    at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:131) 
    at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:89) 
    at com.ibm.ws.asynchbeans.J2EEContext$DoAsProxy.run(J2EEContext.java:335) 
    at java.security.AccessController.doPrivileged(AccessController.java:251) 
    at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1146) 
    at com.ibm.ws.asynchbeans.timer.TimerImpl.runListenerAsCJWork(TimerImpl.java:425) 
    at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:333) 
    at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:230) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) 
Caused by: javax.transaction.RollbackException 
    at com.ibm.tx.jta.TransactionImpl.stage3CommitProcessing(TransactionImpl.java:1217) 
    at com.ibm.tx.jta.TransactionImpl.processCommit(TransactionImpl.java:991) 
    at com.ibm.tx.jta.TransactionImpl.commit(TransactionImpl.java:913) 
    at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:377) 
    at com.ibm.tx.jta.TranManagerSet.commit(TranManagerSet.java:161) 
    at com.ibm.ws.tx.jta.UserTransactionImpl.commit(UserTransactionImpl.java:293) 
    at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009) 
    ... 37 more 

回答

1

假設這是一個WebSphere MQ資源的操作,讓我們試着依次回答你的問題。

爲什麼這個(線程2中的異常,在步驟B6)異常發生?
爲什麼線程2遇到stage3CommitProcessing異常?
我怎麼能得到更多的細節呢?

有可能是QMgr所涉及的配置沒有足夠的日誌空間來包含同步點下的所有消息。儘管您已經小心地序列化了對數據庫的訪問,但隊列並未序列化,因此QMgr必須一次管理最多2000個記錄。更多細節可以在QMgr的錯誤日誌中找到。

如何調試這種交易相關的比賽場景?
是否有Websphere相關的日誌,我可以啓用它來查看在階段3中提交失敗的原因?

查看/var/mqm/qmgrs/[QMgr name]/errors/AMQERR01.log以獲取是否爲WebSphere MQ回滾事務的詳細信息。

另外,打印JMS鏈接的異常。總是。 JMS提供了多級異常,其中較低級別包含特定於提供者的錯誤信息。通常,這些信息會嚮應用程序傳達相同的信息,否則您將不得不通過QMgr的錯誤日誌進行挖掘。

如果我對問題的原因是正確的,測試它的最簡單方法是讓兩個實例嘗試在同步點下讀取100條記錄。

如何避免/解決?

調整日誌的大小,以便它們可以包含在任何給定時刻可能處於同步點下的所有消息。例如,如果郵件的大小爲1k,並且每個10個實例的同步點需要1000個郵件,則至少需要大約10MB的日誌擴展盤區。這些由QMgr的主要和次要日誌大小和計數設置定義。請記住,QMgr還會維護同步點,例如管理通道時,所以無論您計算的空間需要考慮通道批量大小還是QMgr內部事務處理的幾MB。

有關更多詳細信息,請參閱calculating log file sizes的信息中心部分。有關更多背景信息,請參閱IBM developerWorks中的Circular vs. Linear Logs