Subject XAResource forget issue
Author Ludovic Orban
Hi all,

Looks like I hit another issue related to XA. The XAResource.forget()
implementation seems a bit light:

public void forget(Xid id) throws javax.transaction.xa.XAException {
throw new FBXAException("Not yet implemented");
}

Actually I searched how this should be properly implemented and this
is what I found out:


The RDB$TRANSACTIONS table contains references to all transactions
that once have been in limbo.

The RDB$TRANSACTION_STATE column contains the actual state of the
transaction in the DB: 1 - limbo, 2 - committed, 3 - rolled back.

If an RM that supports 2PC heuristically completes a branch, it should
not forget that branch until TM explicitly tells it to by calling
XAResource.forget. This is correctly implemented in the FB engine
since it keeps rows in the RDB$TRANSACTIONS table.

If you take the former 3 statements into account, I think the correct
implementation of forget() would be to delete the row in the
RDB$TRANSACTIONS that contains the specified XID. You could only call
forget with a XID that points to a row where RDB$TRANSACTION_STATE
equals 2 or 3, state 1 would throw an exception. Any non-existent XID
would also throw an exception.

This also means that recover() is incorrectly implemented since it
should also return XIDs that have been heuristically completed. Check
the javadoc:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/transaction/xa/XAResource.html#recover(int)
The WHERE clause of the RECOVERY_QUERY constant should be dropped to
fix this issue.

Finally, the last problem is that the DB engine does not clear the
RDB$TRANSACTIONS rows when a limbo transaction is finally recovered by
the TM. The TM should not call forget on those according to the
javadoc so it would be the job of the JDBC driver to check that if the
XID passed to commit or rollback was present in RDB$TRANSACTIONS, the
row should be deleted.

I haven't check how this could be done efficiently but I think the
logic is correct. Any opinion ?


Thank you for those who spent some time reading this message.
Ludovic