pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ludovic orban <ludovic.orban@gmail.com>
To: Heikki Linnakangas <heikki@enterprisedb.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: XA end then join fix for WebLogic
Date: Fri, 10 Nov 2006 14:43:05 +0100
Message-ID: <c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com> (raw)
In-Reply-To: <455378EB.4060409@enterprisedb.com>
References: <c016d00b0610310758s3dadc02w954de80c678be462@mail.gmail.com>
	<4547C128.40404@enterprisedb.com>
	<c016d00b0611010202m3438da13t4035164c822f1b78@mail.gmail.com>
	<45487C70.6000604@enterprisedb.com>
	<c016d00b0611010407vfa765bfx53da8c128e0e1108@mail.gmail.com>
	<45507CB9.2020206@enterprisedb.com>
	<c016d00b0611080139t1f4ec672n8f216b7fbd0b759@mail.gmail.com>
	<4551B0C5.3010708@enterprisedb.com>
	<c016d00b0611090122m4c833aabr37c966955563583b@mail.gmail.com>
	<455378EB.4060409@enterprisedb.com>

Heikki,

> > It might be that some DB would suffer from the problem you describe
> > (client blocks because the connection is busy) and maybe this is what
> > would happen with Postgres (if it supported tx interleaving) but some
> > other DB might well be able to run everything asynchronously.
>
> You're right that if the DBMS is capable of receiving and processing
> messages incoming asynchronously, there's no problem. However, I think
> such systems are an exception, not a norm.
>
> And no, I don't think it's sensible to expect a DBMS to redesign it's
> client/server protocol just to support this behavior. There's nothing
> that can't be done without it.

I totally agree with you but I think the ones supporting this feature
have a serious advantage over the ones that don't.

On the other hand, you've had good argument indicating that this
advantage might not exist if increasing the connection pool just gives
the same performance.

I'll dig the subject deeper next time I run a benchmark.



> > This has absolutely nothing to do
> > with XA nor interleaved transactions and you could reproduce the exact
> > same behavior with two different connections.
>
> I challenge you to do so. ;)

Done. See attached test case.


> Actually I tend to agree that heuristics as you define them would be
> useful. What I disagree about is that it's a required and essential part
> of the JTA/XA spec. Doing it would be a small patch to both the server
> and driver. I don't think I care enough to write it myself, but feel
> free to submit a patch!

I agree with you: heuristics are not mandated by any of these two
specs but I'd personally would not go on production with a system not
supporting them.

I'll consider writing that patch if time permits.

Ludovic

Attachments:

XATest.java (text/x-java, 4.2K) download import java.sql.Connection; import java.sql.Statement; import java.util.Arrays; import java.util.Random; import javax.sql.XAConnection; import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; import org.firebirdsql.pool.FBConnectionPoolDataSource; /** * Prior to running the test, adjust the hard-coded connection parameters, and create test table: * * CREATE TABLE foo (bar INTEGER); * * Expected output if it the driver could issue an out-of-band commit: * * Initialized * Doing first update * Doing second update * Trying to commit * Commit finished * Second update committed * * Instead, it will hang at "Trying to commit" line until DEADLOCK_TIMEOUT is reached (default * 10 seconds). */ public class XATest { public static void main(String[] args) throws Exception { Xid initxid = new CustomXid(1); FBConnectionPoolDataSource ds = new FBConnectionPoolDataSource(); ds.setDatabase("foo.fdb"); ds.setUserName("SYSDBA"); ds.setPassword("masterkey"); XAConnection xaconn1 = ds.getXAConnection(); XAResource xares1 = xaconn1.getXAResource(); Connection conn1 = xaconn1.getConnection(); XAConnection xaconn2 = ds.getXAConnection(); XAResource xares2 = xaconn2.getXAResource(); Connection conn2 = xaconn2.getConnection(); // Initialize table xares1.start(initxid, XAResource.TMNOFLAGS); Statement stmt = conn1.createStatement(); stmt.executeUpdate("DELETE FROM foo"); stmt.executeUpdate("INSERT INTO foo VALUES (1234)"); xares1.end(initxid, XAResource.TMSUCCESS); xares1.commit(initxid, true); System.out.println("Initialized"); // Start updating transaction that is ended but not committed Xid neverfinishxid = new CustomXid(2); xares1.start(neverfinishxid, XAResource.TMNOFLAGS); System.out.println("Doing first update"); conn1.createStatement().executeUpdate("UPDATE foo SET bar = 5678"); xares1.end(neverfinishxid, XAResource.TMSUCCESS); // Launch a committer thread that will try to commit neverfinishxid after a while Committer committer = new Committer(); committer.xares = xares1; committer.commitThis = neverfinishxid; Thread t = new Thread(committer); t.start(); // Start another update that blocks because it waits for neverfinishxid Xid blockxid = new CustomXid(3); xares2.start(blockxid, XAResource.TMNOFLAGS); System.out.println("Doing second update"); // conn2.createStatement().executeUpdate("INSERT INTO foo VALUES(0000)"); conn2.createStatement().executeUpdate("UPDATE foo SET bar = 0000"); System.out.println("Second update committed"); xares2.end(blockxid, XAResource.TMSUCCESS); xares2.commit(blockxid, true); conn1.close(); conn2.close(); t.join(); xaconn1.close(); xaconn2.close(); } public static class Committer implements Runnable { Xid commitThis; XAResource xares; public void run() { try { Thread.sleep(2000); System.out.println("Trying to commit"); xares.commit(commitThis, true); System.out.println("Commit finished"); } catch(Exception ex) { ex.printStackTrace(); } } } static class CustomXid implements Xid { private static Random rand = new Random(System.currentTimeMillis()); byte[] gtrid = new byte[Xid.MAXGTRIDSIZE]; byte[] bqual = new byte[Xid.MAXBQUALSIZE]; CustomXid(int i) { rand.nextBytes(gtrid); gtrid[0] = (byte)i; gtrid[1] = (byte)i; gtrid[2] = (byte)i; gtrid[3] = (byte)i; gtrid[4] = (byte)i; bqual[0] = 4; bqual[1] = 5; bqual[2] = 6; } public int getFormatId() { return 0; } public byte[] getGlobalTransactionId() { return gtrid; } public byte[] getBranchQualifier() { return bqual; } public boolean equals(Object o) { Xid other = (Xid)o; if (other.getFormatId() != this.getFormatId()) return false; if (!Arrays.equals(other.getBranchQualifier(), this.getBranchQualifier())) return false; if (!Arrays.equals(other.getGlobalTransactionId(), this.getGlobalTransactionId())) return false; return true; } } }

view thread (21+ messages)  latest in thread

Message-ID: <c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com>
Permalink:  ../c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com/
Also on:    postgresql.org/message-id/c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: ludovic.orban@gmail.com, heikki@enterprisedb.com
  Subject: Re: XA end then join fix for WebLogic
  In-Reply-To: <c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com>
  References: <c016d00b0610310758s3dadc02w954de80c678be462@mail.gmail.com> <4547C128.40404@enterprisedb.com> <c016d00b0611010202m3438da13t4035164c822f1b78@mail.gmail.com> <45487C70.6000604@enterprisedb.com> <c016d00b0611010407vfa765bfx53da8c128e0e1108@mail.gmail.com> <45507CB9.2020206@enterprisedb.com> <c016d00b0611080139t1f4ec672n8f216b7fbd0b759@mail.gmail.com> <4551B0C5.3010708@enterprisedb.com> <c016d00b0611090122m4c833aabr37c966955563583b@mail.gmail.com> <455378EB.4060409@enterprisedb.com> <c016d00b0611100543v63e31d0dwd7840b07129d557@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox