JDBC XA resource bug?

From: Andrey Vorobiev <andrey(dot)o(dot)vorobiev(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: JDBC XA resource bug?
Date: 2011-09-02 10:05:31
Message-ID: CAPSK6ngYLaRAy_FGGQqknTPE9FUDCRn32UShxuncWEyD+swD=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There is a view named pg_prepared_xacts which contains list of
prepared transactions in all databases of current instance.

PGXAConnection uses following query to retrive prepared transactions:
"SELECT gid FROM pg_prepared_xacts".

Shouldn't it be the following: "SELECT gid FROM pg_prepared_xacts
where owner = current_user" in order to retrive prepared transactions
that only belongs to current database (connection is opened to)?

My test case is the following:

I have two database: "a" and "b"

Following source code is executing under JBoss AS

DataSource aDS = (DataSource) new InitialContext().lookup("java:jdbc/a-DS");
DataSource bDS = (DataSource) new InitialContext().lookup("java:jdbc/b-DS");

UserTransaction tx = (UserTransaction) new
InitialContext().lookup("java:comp/UserTransaction");

try
{
tx.begin();

Connection aConnection = aDS.getConnection();
aConnection.createStatement().execute("insert into t values (1)");
aConnection.close();

Connection kamailioConnection = bDS.getConnection();
bConnection.createStatement().execute("insert into t values (1)");
bConnection.close();

tx.commit();
}
catch (Exception e)
{
tx.rollback();
e.printStackTrace();
}

In this example I do the following:

1. Start the global transaction.
2. Insert a row into each database.
3. Tell transaction manager (TM) to commit changes in both databases.
4. TM tells each resource to prepare for commit.
5. Two rows appear in pg_prepared_xacts.
6. Kill JBoss in order to test recovery mechanism.
7. Start JBoss.

After JBoss is started I expect both transactions to be committed. But
during commit of prepared transaction in database "b" I've got this
error:
Must be superuser or the user that prepared the transaction.
at org.postgresql.xa.PGXAConnection.commitPrepared(PGXAConnection.java:444)
at org.postgresql.xa.PGXAConnection.commit(PGXAConnection.java:371)
at org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.commit(XAManagedConnection.java:279)
at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelCommit(XAResourceRecord.java:442)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doCommit(BasicAction.java:2789)
at com.arjuna.ats.arjuna.coordinator.BasicAction.doCommit(BasicAction.java:2705)
at com.arjuna.ats.arjuna.coordinator.BasicAction.phase2Commit(BasicAction.java:1788)
at com.arjuna.ats.arjuna.recovery.RecoverAtomicAction.replayPhase2(RecoverAtomicAction.java:72)
at com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule.doRecoverTransaction(AtomicActionRecoveryModule.java:153)
at com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule.processTransactionsStatus(AtomicActionRecoveryModule.java:252)
at com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule.periodicWorkSecondPass(AtomicActionRecoveryModule.java:110)
at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.doWorkInternal(PeriodicRecovery.java:789)
at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.run(PeriodicRecovery.java:371)

As far as I've understood from JBoss source code it gets
PGXAConnection to database "a" instead of "b" due to implementation of
PGXAConnection.recover method (all prepared transactions xids
returned during recover method call).

--
Best regards.

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2011-09-02 10:46:38 Re: UPDATE using query; per-row function calling problem
Previous Message Vincent de Phily 2011-09-02 09:44:55 Re: md5 of table