atomikos / transactions-essentials

Development repository for next major release of
https://www.atomikos.com/Main/TransactionsEssentials
Other
462 stars 139 forks source link

Support LRCO / Last Resource Gambit in XA Transaction with Two-Phase Commit #193

Open karge-itestra opened 11 months ago

karge-itestra commented 11 months ago

There are cases where one of the resources participating in a transaction cannot be XA / Two-Phase Commit capable. Atomikos does not support committing if there are other XA capable resources in the same transaction.

When using the NonXADataSourceBean, the transaction where its resource gets registered should enlist it as a "Last resource". Upon committing, the participating XA resources should be prepared, then the non-XA resource should be committed, and if that succeeds, the XA resources can be committed as well.

Currently, in the prepare phase, any non-readonly non-XA resource will throw an exception in the prepare phase implemented due to https://github.com/atomikos/transactions-essentials/issues/83 . However, the non-XA resource should not even be involved in the prepare phase by the transaction coordinator.

I found several resources concerning the topic:

  1. Official Documentation: https://www.atomikos.com/Documentation/NonXaDataSource This needs some clarifications regarding the fact that Atomikos DOES NOT implement an equivalent to LRC. It does not allow at most one non-XA resource with XA resources in a transaction. If a non-XA resource is needed, NO other resources can participate in the transaction.
  2. Forum entry from 2008: https://fogbugz.atomikos.com/defaultcd15.html?community.6.250.5 The comment and discussion here make it very clear that Atomikos does not support anything similar to LRC, which seems not to have changed since then.
  3. Documentation about how LRC is supposed to work: https://access.redhat.com/documentation/de-de/jboss_enterprise_application_platform_common_criteria_certification/5/html/administration_and_configuration_guide/lrco-overview https://aries.apache.org/documentation/modules/tx-control/lastResourceGambit.html https://github.com/bitronix/btm/blob/master/btm-docs/src/main/asciidoc/LastResourceCommit2x.adoc As you can see, all popular XA transaction manager implementations support a true version of LRC.

In all posts that @GuyPardon wrote about LRC, he warned about that it is unsafe. I assume (since no references were given) he refers to the warning that Bitronix also wrote in the documentation. I think, that tradeoff is something that an informed user can deal with. So please, at least provide the option.

If any help is wanted on the topic, I am glad to be given pointers to the places where changes need to be implemented and topics that need to be taken care of.

karge-itestra commented 10 months ago

If you want, you can take a look at the rudimentary implementation in the linked commits. I assume they violate dozens of invariants or safety considerations, so feel free to constructively critisize them!