Skip to content

Commit

Permalink
[CONJ-1189] XA START RESUME even with TMJOIN flag when using pinGloba…
Browse files Browse the repository at this point in the history
…lTxToPhysicalConnection option
  • Loading branch information
rusher committed Jul 10, 2024
1 parent c2904a9 commit f68447f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/mariadb/jdbc/MariaDbPoolPinnedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,19 @@ public boolean setTransactionTimeout(int i) {

@Override
public void start(Xid xid, int flags) throws XAException {
if (flags != TMJOIN && flags != TMRESUME && flags != TMNOFLAGS) {
throw new XAException(XAException.XAER_INVAL);
switch (flags) {
case TMJOIN:
case TMRESUME:
// specific to pinGlobalTxToPhysicalConnection option set,
// force resume in place of JOIN
execute(xid, "XA START " + xidToString(xid) + " RESUME", false);
break;
case TMNOFLAGS:
execute(xid, "XA START " + xidToString(xid), false);
break;
default:
throw new XAException(XAException.XAER_INVAL);
}
execute(xid, "XA START " + xidToString(xid) + " " + flagsToString(flags), false);
}
}
}
16 changes: 16 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/XaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ public void testPinGlobalTxToPhysicalConnection() throws Exception {
c2.getXAResource().commit(txid, false);
}

@Test
public void testPinGlobalTxToPhysicalConnection2() throws Exception {

MariaDbDataSource xads = new MariaDbDataSource(mDefUrl + "&pinGlobalTxToPhysicalConnection");
Xid txid = new MariaDbXid(1, new byte[] {0xf}, new byte[] {0x01});

XAConnection c1 = xads.getXAConnection();
c1.getXAResource().start(txid, XAResource.TMNOFLAGS);
c1.getXAResource().end(txid, XAResource.TMSUCCESS);

XAConnection c2 = xads.getXAConnection();
c2.getXAResource().start(txid, XAResource.TMJOIN);
c2.getConnection().createStatement().executeQuery("SELECT 1");
c2.getXAResource().end(txid, XAResource.TMSUCCESS);
}

@Test
public void xaRmTest() throws Exception {
MariaDbDataSource dataSource1 = new MariaDbDataSource(mDefUrl);
Expand Down

0 comments on commit f68447f

Please sign in to comment.