Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47) - Mailing list pgsql-jdbc

From Craig Ringer
Subject Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)
Date
Msg-id 5148507A.1030000@2ndquadrant.com
Whole thread Raw
In response to Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)  (Dave Cramer <pg@fastcrypt.com>)
Responses Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)  (Bryan Varner <bvarner@polarislabs.com>)
List pgsql-jdbc
On 03/16/2013 01:14 AM, Dave Cramer wrote:
I'm looking for opinions on this patch.

On Fri, Mar 15, 2013 at 12:45 PM, Bryan Varner <notifications@github.com> wrote:

The support for interleaving and sharing is implemented by (potentially, only when needed) returning 'logical' connections from the XADataSource, and opening new physical connections to the backend server (when necessary) to handle [performing] work on behalf of a global TX or local TX.

This sounds like you're essentially implementing a connection pool inside PgJDBC to handle transaction suspend, interleave, etc. This has generally been recognised as the only way to achieve these features on most real-world database products, so I don't have a problem with that so long as it's set up and torn down properly, avoids resource leaks, etc. I haven't taken a proper look at the code yet so I'm asking to help me understand what I should be looking for.

Since JTA and the X/Open XA spec it is based on rather unfortunately specifies transaction suspend and interleave as required features it was always going to be necessary to do something awful like this at some level. I thought that JBoss AS 7's JTA implementation took care of this behind the scenes in cases where the JDBC driver didn't support tx suspend and resume, though? Is that not the case? Do other XA clients not do the same thing?

(Looks at some other project code)

Yep. I was using this with JTA, and JBoss AS 7 was taking care of all the transaction suspend/interleave emulation its self:

<?xml version="1.0" encoding="UTF-8"?> 
<datasources> 
  <datasource jndi-name="java:/datasources/XXXXXX" enabled="true" use-java-context="true" 
        pool-name="XXXXX-pool"> 
    <connection-url>jdbc:postgresql:XXXXX</connection-url> 
    <driver>postgresql-driver</driver> 
    <security> 
      <user-name>XXXXX</user-name>
      <password>XXXXX</password>
    </security> 
  </datasource> 
</datasources> 

This isn't a good reason not to fix XADataSource, but it might be informative. If nothing else you can probably learn more about the JTA/XA requirements and tricks for interleaving, etc, from AS7's code.

I was not using 2PC and co-ordinating with other transaction managers, so it's entirely possible this only works for the one-datasource-per-XA-transaction case.

The behavior of opening new physical backends (implementing interleaving) can be disabled by setting the XAAcquireTimeout = 0, in which case the behavior of the old XADataSource implementation is retained, with a minimal performance impact.

Great, we'll almost certainly need that since someone's certain to be relying on it - intentionally or not - and unwilling/unable to change their code or the library they're using.
 
-- Craig Ringer                   http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services

pgsql-jdbc by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Client Certificate Authentication
Next
From: Bryan Varner
Date:
Subject: Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)