Re: XAResource implementation

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: joël Winteregg <joel(dot)winteregg(at)gmail(dot)com>, pgsql-jdbc(at)postgresql(dot)org, Ludovic Orban <ludovic(dot)orban(at)gmail(dot)com>
Subject: Re: XAResource implementation
Date: 2007-11-13 22:52:35
Message-ID: 473A2AB3.2040701@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Kris Jurka wrote:
>
>
> On Tue, 13 Nov 2007, Heikki Linnakangas wrote:
>
>> It looks like there is indeed a bug in the Postgres driver. I believe
>> it was introduced by the recent changes to keep the connection in
>> autocommit mode when no XA-transaction is in progress.
>>
>> It's this call sequence that borks it up:
>>
>> xares.start()
>> conn = xares.getConnection()
>> // do stuff
>> conn.close();
>> conn = xares.getConnection()
>> // do more stuff
>> xares.end()
>> xares.commit()
>>
>> The 2nd getConnection call inadvertently commits the transaction, and
>> opens another one.
>
> When I raised this issue, you said it can't/shouldn't happen. What's
> different now? It's still a bug in the driver, but is the calling code
> doing something it shouldn't?
>
> http://archives.postgresql.org/pgsql-jdbc/2007-06/msg00095.php

Oh, I had forgotten about that. The difference is the close() between
the getConnection()s.

I started having second doubts about that case you posted in June, so I
tested what Derby does if you call getConnection() twice, without a
close in between. You get an error ("Cannot close a connection while a
global transaction is still active."), so at least they consider it
incorrect as well.

Throwing an error in that case would be a nice thing for us to do as
well. Currently, we just silently rollback.

>> Patch attached. I also added a test for this in the test suite.
>
> transaction_timestamp() is an 8.2 feature, but since XA is an 8.1
> feature you should use now() instead. (No need for a new patch, I've
> updated mine here.)

Thanks!

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2007-11-14 22:11:23 Re: XAResource implementation
Previous Message Kris Jurka 2007-11-13 21:10:26 Re: XAResource implementation