Re: PostgreSQL XAResource & GlassFish 3.1.2.2

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Bryan Varner <bvarner(at)polarislabs(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2
Date: 2013-02-12 18:36:28
Message-ID: 511A8BAC.7080400@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 12.02.2013 18:01, Bryan Varner wrote:
> What should be valid (and is not considered interleaving), is:
>
> Thread A Thread B
> -------- ---------
> xares.start(1234, TMNOFLAGS);
> doStuff();
> xares.end(1234);
> xares.start(1234, TMJOIN);
> doStuff();
> xares.end(1234);
> xares.start(1234, TMJOIN);
> doStuff();
> xares.end(1234);
>
> So long as the TM is serializing execution of A and B and not allowing
> branch interleaving.
>
> In this case, the XAResource is preforming work on behalf of more than
> one thread, but in the same XID context. The problem I think I'm seeing
> at this point (still trying to coordinate with the glassfish devs) is
> that the XAResource isn't fully completing execution of end() prior to
> the other thread invoking start(), even though the method invocation
> appears to be happening 'in order'. This would manifest as a classic
> race condition, and would not constitute transaction interleaving, since
> the XID in use is the same TX branch.

I see. I think there's yet another potential explanation: even if
glassfish is careful to invoke the end() only after start() has fully
finished in the other thread, the java memory model does not guarantee
that the effects of the end() in one thread are visible to the other
thread doing the start(). The update of the PGXAConnection's
state-variable might be sitting in the CPU cache of the CPU running the
first thread, not yet visible to the second thread. However, I'm not
sure if glassfish could guarantee that the start() has really finished
before end() is called, without using some operation that would also
force the CPU cache to be flushed, making the effects visible.

In any case, it seems like we should add "synchronized" to all the
public methods in PGXAConnection. The performance penalty should be
minimal, and it would fix any race conditions of that sort.

Can you test the attached patch?

- Heikki

Attachment Content-Type Size
synchronize-pgxaconnection.patch text/x-diff 4.9 KB

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Florent Guillaume 2013-02-12 18:41:39 Re: PostgreSQL XAResource & GlassFish 3.1.2.2
Previous Message Bryan Varner 2013-02-12 18:28:31 Re: PostgreSQL XAResource & GlassFish 3.1.2.2