scalar-labs / btm

JTA Transaction Manager
Apache License 2.0
426 stars 151 forks source link

Clarify requirements for XAResourceProducer unique name #88

Closed klr8 closed 7 years ago

klr8 commented 7 years ago

Each XAResourceProducer needs to have a unique name that is used by the ResourceRegistrar to keep track of the resource. The JavaDoc of XAResourceProducer simply says:

Get the resource name as registered in the transactions journal.

The JavaDoc of ResourceBean additionally states:

Specify the resource unique name to be used to identify this resource during recovery. This name will be registered in the transactions journal so once assigned it must never be changed.

What exactly does this mean?

klr8 commented 7 years ago

Having looked at the source code a bit more I indeed see that for instance the Recoverer class looks up a resource using the unique name that it gets from the journal (TransactionLogRecord / DanglingTransaction).

If I understand things correctly, this implies:

lorban commented 7 years ago

Both your statements are correct. For completeness sake I would also add that the configured serverId must also stay unchanged "for eternity".

Fortunately, BTM is reasonably lenient in case you changed one of those names by mistake. As long as you did not use resource A's name for an unrelated B resource -in which case the recoverer would try to reapply totally unrelated transactions and would log heuristic errors- once you restore the names to their original value, the recoverer will manage to resume everything as it should, thanks to its ability to perform incremental recovery. I wouldn't advise to rely on that, though.

If you feel the need to rename anything, just make sure to exit properly so that no resource has any in-doubt transaction, then simply delete the existing journal fragments.

klr8 commented 7 years ago

Thanks for confirming that!