colinwerner opened a new pull request, #2666:
URL: https://github.com/apache/activemq/pull/2666
Closes #2665
When the database commit fails during an XA prepare, or during the commit of
a prepared transaction, `TransactionContext.commit()` rolls back and ends the
store transaction before rethrowing. `JdbcMemoryTransactionStore.prepare()` and
`MemoryTransactionStore.Tx.commit()` then call `rollbackTransaction()` on the
same context, which throws `IOException("Not started.")` and replaces the
original exception. The client sees `Not started.` instead of the store error.
This keeps the original exception and adds any rollback failure to it as
suppressed. The XA error codes are unchanged (`XAER_RMFAIL` for prepare,
`XA_RETRY` for the commit of a prepared transaction).
The rollback of a prepared transaction in
`JdbcMemoryTransactionStore.rollback()` has the same catch block, but its store
commit is outside the `try`, so it isn't affected and is unchanged.
Tests (`JDBCXACommitExceptionTest`): a `DataSource` proxy fails the next
`Connection.commit()` once.
- `testPrepareStoreCommitFailureReportsCause`: the prepare `XAException`
carries the injected failure and not `Not started.`; rolling back afterwards
leaves nothing in the store.
- `testCommitStoreCommitFailureReportsCause`: the commit `XAException`
carries the injected failure, is `XA_RETRY`, and the retried commit succeeds.
Both fail without the fix, with `Not started.` as the only message in the
exception chain.
A second, test-only commit covers the retry path for the commit of a
prepared add. A single failure while committing it (the clear-XID update
matching no rows, the update throwing `SQLException`, or the connection commit
failing) returns `XA_RETRY`, leaves the in-memory state unchanged, and the
retried commit succeeds and delivers the message once:
- `testCommitOfPreparedAddSucceedsOnRetryAfterClearXidMatchesNoRows`
- `testCommitOfPreparedAddSucceedsOnRetryAfterClearXidSqlException`
- `testCommitOfPreparedAddSucceedsOnRetryAfterConnectionCommitFailure`
These pass before and after the fix; they guard against the retry state
regressing.
```
mvn -pl activemq-broker,activemq-jdbc-store,activemq-unit-tests test
-Dtest='JDBCXACommitExceptionTest,JDBCCommitExceptionTest,XACompletionTest,JdbcXARecoveryBrokerTest,JdbcXARecoveryBrokerNoCacheTest'
-Dsurefire.failIfNoSpecifiedTests=false
```
Note: on current `main`, `activemq-broker` test-compile fails in
`ManagementContextSslTest` (`SslContext` is abstract), which is unrelated to
this change. I ran the tests above with that one file moved aside.
Generated with Claude Code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact