I would like to sketch here my current effort to fix https://issues.jboss.org/browse/JBTM-2124 : Add orphan detection for JTS interposition mode.
The point is to gather feedback about the feature fix and about the way how it's implemented.
The PR currently resides at: https://github.com/jbosstm/narayana/pull/1174
For the basic overview where I started, please, read the comments on the issue
Now, what's the issue and what I'm trying to achieve?
The orphan detection in Narayana is a term used for the process during periodic recovery. If you imagine having a transaction consisting of two resources. Business logic does some work (e.g. inserting data to databases) on those two resources and then it's time for transaction manager to finish the work in an atomic way - commit both resources as a single unit of work. At that time two-phase commit processing comes to work. The transaction manager starts with prepare phase and asks resource one and two to prepare. Each of the resources response 'ok' and make a durable record of its local transaction being prepared to its own transaction log. The prepare phase is now in the end and transaction manager would persist information about the transaction being prepared to its transaction log store. If it succeeds then the transaction is prepared for commit - either immediately in the next step of 2PC or later by periodic recovery process if some failure occurs. But let's imagine that the underlying system crashes before transaction manager durably persist information that the transaction was successfully prepared.
When the transaction manager system is restarted the transaction manager has no idea that there a transaction but resources have locked their data and their local transaction log contains info about the prepared local transaction. Recovery process asks the both resources and they provide that info to the transaction manager. Now the transaction manager should command to roll-back the local transaction on resources.
In Narayana it's concern of orphan filters (XAResourceOrphanFilter). Those are "strategies" applied on in-doubt transactions coming from resources which the Narayana's transaction log is not aware of. The filters vote what should be done with such in-doubt transaction. One of them is JTANodeNameXAResourceOrphanFilter which checks the Xid of the in-doubt transaction, unpack node name (identifier of the transaction manager who creates (prepared) the transaction) and if it's present and it's equal to node identifier of transaction manager running the recovery it votes for rollback. That way the periodic recovery decides to roll-back such in-doubt txn.
This behavior is already implemented for JTA but it misses for JTS. The point here is to mimic the JTA implementation for JTS. My change has two parts (I would say).
First, is enabling handling of NodeName Orphan filter for JTS. Currently, there is format check which permits the rollback being voted only for JTA transaction.
Second, is packing (saving) node name to ServerTransaction implementation where such handling is not provided so far. If the node name is saved to Xid the orphan filter can benefit from it and decide voting to roll back.