Skip to content

Commit 0d642f5

Browse files
committed
Fix for Bug#72036 (Bug#18403804), XA isSameRM() shouldn't take database into account.
Change-Id: I99fdd11c63cfb6cf99077894f88649fb14a7a4b4
1 parent cdb5880 commit 0d642f5

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 9.5.0
55

6+
- Fix for Bug#72036 (Bug#18403804), XA isSameRM() shouldn't take database into account.
7+
68
- Fix for Bug#62693 (Bug#16722068), XAConnection savepoint capability.
79

810
- Fix for Bug#81128 (Bug#23146631), Master host list overwritten by slave list when loadBalanceConnectionGroup used.

src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,38 +1417,21 @@ public boolean isSameResource(JdbcConnection otherConnection) {
14171417
return false;
14181418
}
14191419

1420-
boolean directCompare = true;
1421-
14221420
String otherHost = ((ConnectionImpl) otherConnection).origHostToConnectTo;
1423-
String otherOrigDatabase = ((ConnectionImpl) otherConnection).origHostInfo.getDatabase();
1424-
String otherCurrentDb = ((ConnectionImpl) otherConnection).database;
1425-
1426-
if (!StringUtils.nullSafeEqual(otherHost, this.origHostToConnectTo)) {
1427-
directCompare = false;
1428-
} else if (otherHost != null && otherHost.indexOf(',') == -1 && otherHost.indexOf(':') == -1) {
1429-
// need to check port numbers
1430-
directCompare = ((ConnectionImpl) otherConnection).origPortToConnectTo == this.origPortToConnectTo;
1431-
}
1432-
1433-
if (directCompare) {
1434-
if (!StringUtils.nullSafeEqual(otherOrigDatabase, this.origHostInfo.getDatabase())
1435-
|| !StringUtils.nullSafeEqual(otherCurrentDb, this.database)) {
1436-
directCompare = false;
1437-
}
1421+
if (StringUtils.nullSafeEqual(otherHost, this.origHostToConnectTo)) {
1422+
return true;
14381423
}
14391424

1440-
if (directCompare) {
1425+
if (otherHost != null && otherHost.indexOf(',') == -1 && otherHost.indexOf(':') == -1 && // need to check port numbers
1426+
((ConnectionImpl) otherConnection).origPortToConnectTo == this.origPortToConnectTo) {
14411427
return true;
14421428
}
14431429

14441430
// Has the user explicitly set a resourceId?
14451431
String otherResourceId = ((ConnectionImpl) otherConnection).getPropertySet().getStringProperty(PropertyKey.resourceId).getValue();
14461432
String myResourceId = this.propertySet.getStringProperty(PropertyKey.resourceId).getValue();
1447-
14481433
if (otherResourceId != null || myResourceId != null) {
1449-
directCompare = StringUtils.nullSafeEqual(otherResourceId, myResourceId);
1450-
1451-
if (directCompare) {
1434+
if (StringUtils.nullSafeEqual(otherResourceId, myResourceId)) {
14521435
return true;
14531436
}
14541437
}

src/test/java/testsuite/BaseTestCase.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
import java.sql.Statement;
4545
import java.util.ArrayList;
4646
import java.util.Arrays;
47-
import java.util.Enumeration;
4847
import java.util.HashSet;
4948
import java.util.List;
5049
import java.util.Locale;
5150
import java.util.Properties;
5251
import java.util.Set;
5352
import java.util.StringJoiner;
5453
import java.util.concurrent.Callable;
54+
import java.util.stream.Collectors;
5555

5656
import javax.net.ssl.SSLContext;
5757

@@ -494,24 +494,18 @@ protected String getEncodedHostPortPairFromTestsuiteUrl() throws SQLException {
494494
}
495495

496496
protected String getNoDbUrl(String url) throws SQLException {
497+
return getReplacedDbUrl(url, "");
498+
}
499+
500+
protected String getReplacedDbUrl(String url, String dbReplacement) throws SQLException {
497501
Properties props = getPropertiesFromUrl(ConnectionUrl.getConnectionUrlInstance(url, null));
498502
final String host = props.getProperty(PropertyKey.HOST.getKeyName(), "localhost");
499503
final String port = props.getProperty(PropertyKey.PORT.getKeyName(), "3306");
500504
props.remove(PropertyKey.DBNAME.getKeyName());
501505
removeHostRelatedProps(props);
502506

503-
final StringBuilder urlBuilder = new StringBuilder("jdbc:mysql://").append(host).append(":").append(port).append("/?");
504-
505-
Enumeration<Object> keyEnum = props.keys();
506-
while (keyEnum.hasMoreElements()) {
507-
String key = (String) keyEnum.nextElement();
508-
urlBuilder.append(key);
509-
urlBuilder.append("=");
510-
urlBuilder.append(props.get(key));
511-
if (keyEnum.hasMoreElements()) {
512-
urlBuilder.append("&");
513-
}
514-
}
507+
final StringBuilder urlBuilder = new StringBuilder("jdbc:mysql://").append(host).append(":").append(port).append("/").append(dbReplacement).append("?");
508+
urlBuilder.append(props.stringPropertyNames().stream().map(k -> k + "=" + props.getProperty(k)).collect(Collectors.joining("&")));
515509
return urlBuilder.toString();
516510
}
517511

src/test/java/testsuite/regression/ConnectionRegressionTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12582,4 +12582,40 @@ public void testBug62693() throws Exception {
1258212582
}
1258312583
}
1258412584

12585+
/**
12586+
* Tests fix for Bug#72036 (Bug#18403804), XA isSameRM() shouldn't take database into account.
12587+
*
12588+
* @throws Exception
12589+
*/
12590+
@Test
12591+
public void testBug72036() throws Exception {
12592+
final String dbA = "testBug72036A";
12593+
final String dbB = "testBug72036B";
12594+
createDatabase(dbA);
12595+
createDatabase(dbB);
12596+
12597+
MysqlXADataSource xaDS = new MysqlXADataSource();
12598+
xaDS.getStringProperty(PropertyKey.sslMode.getKeyName()).setValue("DISABLED");
12599+
xaDS.getBooleanProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName()).setValue(true);
12600+
12601+
xaDS.setUrl(getReplacedDbUrl(dbUrl, dbA));
12602+
XAConnection testXaConA1 = xaDS.getXAConnection();
12603+
XAResource testXaResA1 = testXaConA1.getXAResource();
12604+
assertEquals(dbA, testXaConA1.getConnection().getCatalog());
12605+
12606+
XAConnection testXaConA2 = xaDS.getXAConnection();
12607+
XAResource testXaResA2 = testXaConA2.getXAResource();
12608+
assertEquals(dbA, testXaConA2.getConnection().getCatalog());
12609+
12610+
assertTrue(testXaResA1.isSameRM(testXaResA2));
12611+
12612+
xaDS.setUrl(getReplacedDbUrl(dbUrl, dbB));
12613+
XAConnection testXaConB = xaDS.getXAConnection();
12614+
XAResource testXaResB = testXaConB.getXAResource();
12615+
assertEquals(dbB, testXaConB.getConnection().getCatalog());
12616+
12617+
assertTrue(testXaResA1.isSameRM(testXaResB));
12618+
assertTrue(testXaResA2.isSameRM(testXaResB));
12619+
}
12620+
1258512621
}

0 commit comments

Comments
 (0)