db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kathey Marsden (JIRA)" <derby-...@db.apache.org>
Subject [jira] Commented: (DERBY-1025) [xa] client XAResource.start() does not commit an active local transaction when auto commit is true
Date Thu, 09 Mar 2006 03:19:56 GMT
    [ http://issues.apache.org/jira/browse/DERBY-1025?page=comments#action_12369590 ] 

Kathey Marsden commented on DERBY-1025:

So on XAResource.start() we need to flowcommit if
1) We are in autocommit mode. 
        conn_.autocommit_ == true
2) We are in a an active local Transaction.
   conn_getXAState() == XA_T0_NOT_ASSOCIATED
   conn_.inUnitOfWork_ == true

For my first shot at fixing this bug I added the folling code to 
	// DERBY-1025 
        // autocommit the local transaction before starting the global transaction
        // if autocommit is set
        if (conn_.autoCommit_  && conn_.inActiveLocalTransaction())
Where in NetXAConnection we have
public boolean inActiveLocalTransaction() {
		return (isInUnitOfWork_() && 
    			(getXAState() == XA_T0_NOT_ASSOCIATED));   

And in Connection.java
	 * @return Returns the inUnitOfWork_.
	public boolean isInUnitOfWork_() {
		return inUnitOfWork_;

With my change, putting this code in I found some very strange behaviour in this case in XATest
1)  I got a commit on start when no local transaction was active after  a suspend
2)  I seemed to lose a totally different suspended transaction in the process.

See comments for behaviour:
    private static void interleavingTransactions(XADataSource xads) {
        try {
            XAConnection xac = xads.getXAConnection("sku", "testxa");
            XAResource xar = xac.getXAResource();

            Xid xid1 = XATestUtil.getXid(1, 93, 18);
            Xid xid2 = XATestUtil.getXid(2, 45, 77);

            xar.start(xid1, XAResource.TMNOFLAGS);

            Connection conn = xac.getConnection();

            Statement s = conn.createStatement();
            s.executeUpdate("insert into APP.foo values (1)");
            xar.end(xid1, XAResource.TMSUSPEND);
            // commit occurred here because inUnitOfWork_ was true
            // when it should be false.
            xar.start(xid2, XAResource.TMNOFLAGS);
            s.executeUpdate("insert into APP.foo values (2)");
            xar.end(xid2, XAResource.TMSUSPEND);
            xar.start(xid1, XAResource.TMRESUME);
            s.executeUpdate("insert into APP.foo values (3)");
            // XAER_NOTA on suspend  of xid1.
            // very strange because the resume worked ok.
            // where did it go?
            xar.end(xid1, XAResource.TMSUSPEND);

I am trying to understand:

1)  When and how inUnitOfWork_ is set and its relation to XA
2)  Why the autocommit after the suspension of xid2 caused xid1 to go away after it resumed
just fine.

All very strange.

> [xa] client XAResource.start() does not commit an active local transaction when auto
commit is true
> ---------------------------------------------------------------------------------------------------
>          Key: DERBY-1025
>          URL: http://issues.apache.org/jira/browse/DERBY-1025
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Reporter: Daniel John Debrunner
>     Assignee: Kathey Marsden

> Embedded XAResource.start() implementation commits the active local transaction on the
Connection associated with the XAResource if the connection is auto-commit mode.
> Client incorrectly throws an XAException with the XAER_RMFAIL error code (see DERBY-1024)
> XATest contains a work-around for client (calling commit) with a comment with this bug

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message