Skip to content

Commit

Permalink
Alleviate the connection leak caused by Seata Client throwing excepti…
Browse files Browse the repository at this point in the history
…ons in `CONNECTION_STRICTLY` connection mode
  • Loading branch information
linghengqian committed Jan 25, 2025
1 parent 252b0dd commit 23d7773
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 106 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

### Bug Fixes

1. JDBC: Alleviate connection leaks caused by Seata Client throwing exceptions - [#34463](https://github.com/apache/shardingsphere/pull/34463)
1. JDBC: Alleviate the connection leak caused by Seata Client throwing exceptions in `MEMORY_STRICTLY` connection mode - [#34463](https://github.com/apache/shardingsphere/pull/34463)
1. JDBC: Alleviate the connection leak caused by Seata Client throwing exceptions in `CONNECTION_STRICTLY` connection mode - [#34498](https://github.com/apache/shardingsphere/pull/34498)

### Change Logs

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f7c3fca2710"},
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f510bcc3d10"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
Expand Down Expand Up @@ -138,6 +138,9 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"},
"pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\QMETA-INF/services/javax.sql.rowset.RowSetFactory\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
"pattern":"\\QMETA-INF/services/javax.xml.datatype.DatatypeFactory\\E"
Expand Down Expand Up @@ -252,6 +255,9 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.metadata.database.system.SystemDatabase"},
"pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.metadata.database.system.DialectSystemDatabase\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.resultset.ResultSetMapper"},
"pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.resultset.DialectResultSetMapper\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.props.TypedPropertyValue"},
"pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType\\E"
Expand Down Expand Up @@ -423,6 +429,15 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"},
"pattern":"\\Qcom/atomikos/icatch/provider/imp/transactions.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\Qcom/sun/rowset/RowSetResourceBundle_zh.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\Qcom/sun/rowset/RowSetResourceBundle_zh_Hans.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"\\Qcom/sun/rowset/RowSetResourceBundle_zh_Hans_CN.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
"pattern":"\\Qcontainer-license-acceptance.txt\\E"
Expand Down Expand Up @@ -2103,6 +2118,24 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.database.hive.metadata.data.loader.HiveMetaDataLoader"},
"pattern":"\\Qyarn-site.xml\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qcom/sun/rowset/RowSetResourceBundle.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qcom/sun/rowset/RowSetResourceBundle_zh.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qcom/sun/rowset/RowSetResourceBundle_zh_CN.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qcom/sun/rowset/RowSetResourceBundle_zh_Hans.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qcom/sun/rowset/RowSetResourceBundle_zh_Hans_CN.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"},
"pattern":"java.sql.rowset:\\Qjavax/sql/rowset/rowset.properties\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.database.hive.metadata.data.loader.HiveMetaDataLoader"},
"pattern":"java.xml:\\Qcom/sun/org/apache/xml/internal/serializer/Encodings.properties\\E"
Expand All @@ -2128,5 +2161,8 @@
}, {
"name":"com.sun.org.apache.xml.internal.serializer.XMLEntities",
"locales":["zh-CN"]
}, {
"name":"com.sun.rowset.RowSetResourceBundle",
"locales":["zh-CN"]
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@
"allPublicMethods": true,
"allDeclaredFields": true
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableRowDataPersistService"},
"name":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics",
"allPublicMethods": true
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.opengauss.ddl.OpenGaussCreateTableStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.opengauss.ddl.OpenGaussCreateTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTableStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerCreateTableStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerCreateTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData"},
"name":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,17 @@ private List<Connection> createConnections(final String databaseName, final Stri
final TransactionConnectionContext transactionConnectionContext) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
for (int i = 0; i < connectionSize; i++) {
Connection connection = createConnection(databaseName, dataSourceName, dataSource, transactionConnectionContext);
try {
Connection connection = createConnection(databaseName, dataSourceName, dataSource, transactionConnectionContext);
methodInvocationRecorder.replay(connection);
result.add(connection);
} catch (final SQLException ex) {
connection.close();
for (Connection each : result) {
each.close();
}
throw new OverallConnectionNotEnoughException(connectionSize, result.size(), ex).toSQLException();
}
result.add(connection);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm;

import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;

import java.util.Collection;

public final class TOrderItemShardingTableAlg implements StandardShardingAlgorithm<Integer> {

@Override
public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Integer> shardingValue) {
String resultTableName = "t_order_item_" + shardingValue.getValue() % 2;
for (String each : availableTargetNames) {
if (each.equals(resultTableName)) {
return each;
}
}
return null;
}

@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Integer> shardingValue) {
throw new RuntimeException("This algorithm class does not support range queries.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm;

import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;

import java.util.Collection;

public final class TOrderShardingTableAlg implements StandardShardingAlgorithm<Integer> {

@Override
public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Integer> shardingValue) {
String resultTableName = "t_order_" + shardingValue.getValue() % 2;
for (String each : availableTargetNames) {
if (each.equals(resultTableName)) {
return each;
}
}
return null;
}

@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Integer> shardingValue) {
throw new RuntimeException("This algorithm class does not support range queries.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,38 @@ void assertShardingInLocalTransactions() throws SQLException {
Statement statement = connection.createStatement()) {
statement.execute("CREATE DATABASE sharding_db");
statement.execute("USE sharding_db");
statement.execute("REGISTER STORAGE UNIT ds_0 (\n"
+ " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_0\",\n"
+ " USER=\"root\",\n"
+ " PASSWORD=\"yourStrongPassword123!\"\n"
statement.execute("REGISTER STORAGE UNIT IF NOT EXISTS ds_0 (\n"
+ " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_0',\n"
+ " USER='root',\n"
+ " PASSWORD='yourStrongPassword123!'\n"
+ "),ds_1 (\n"
+ " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_1\",\n"
+ " USER=\"root\",\n"
+ " PASSWORD=\"yourStrongPassword123!\"\n"
+ " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_1',\n"
+ " USER='root',\n"
+ " PASSWORD='yourStrongPassword123!'\n"
+ "),ds_2 (\n"
+ " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_2\",\n"
+ " USER=\"root\",\n"
+ " PASSWORD=\"yourStrongPassword123!\"\n"
+ " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_2',\n"
+ " USER='root',\n"
+ " PASSWORD='yourStrongPassword123!'\n"
+ ")");
statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n"
+ " TYPE=\"standard\", \n"
statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY IF NOT EXISTS (\n"
+ " TYPE='standard', \n"
+ " SHARDING_COLUMN=user_id, \n"
+ " SHARDING_ALGORITHM(\n"
+ " TYPE(\n"
+ " NAME=CLASS_BASED, \n"
+ " PROPERTIES(\n"
+ " \"strategy\"=\"STANDARD\",\n"
+ " \"algorithmClassName\"=\"org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture\"\n"
+ " 'strategy'='STANDARD',\n"
+ " 'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'\n"
+ " )\n"
+ " )\n"
+ " )\n"
+ ")");
statement.execute("CREATE SHARDING TABLE RULE t_order (\n"
+ " DATANODES(\"<LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order\"),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=\"SNOWFLAKE\"))\n"
statement.execute("CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (\n"
+ " DATANODES('<LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order'),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='SNOWFLAKE'))\n"
+ "), t_order_item (\n"
+ " DATANODES(\"<LITERAL>ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item\"),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=\"SNOWFLAKE\"))\n"
+ " DATANODES('<LITERAL>ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME='SNOWFLAKE'))\n"
+ ")");
statement.execute("CREATE BROADCAST TABLE RULE t_address");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,38 @@ void assertShardingInLocalTransactions() throws SQLException {
try (
Connection connection = openConnection("root", "root", "jdbc:postgresql://127.0.0.1:" + proxyTestingServer.getProxyPort() + "/sharding_db");
Statement statement = connection.createStatement()) {
statement.execute("REGISTER STORAGE UNIT ds_0 (\n"
+ " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0\",\n"
+ " USER=\"test\",\n"
+ " PASSWORD=\"test\"\n"
statement.execute("REGISTER STORAGE UNIT IF NOT EXISTS ds_0 (\n"
+ " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0',\n"
+ " USER='test',\n"
+ " PASSWORD='test'\n"
+ "),ds_1 (\n"
+ " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1\",\n"
+ " USER=\"test\",\n"
+ " PASSWORD=\"test\"\n"
+ " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1',\n"
+ " USER='test',\n"
+ " PASSWORD='test'\n"
+ "),ds_2 (\n"
+ " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2\",\n"
+ " USER=\"test\",\n"
+ " PASSWORD=\"test\"\n"
+ " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2',\n"
+ " USER='test',\n"
+ " PASSWORD='test'\n"
+ ")");
statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n"
+ " TYPE=\"standard\", \n"
statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY IF NOT EXISTS (\n"
+ " TYPE='standard', \n"
+ " SHARDING_COLUMN=user_id, \n"
+ " SHARDING_ALGORITHM(\n"
+ " TYPE(\n"
+ " NAME=CLASS_BASED, \n"
+ " PROPERTIES(\n"
+ " \"strategy\"=\"STANDARD\",\n"
+ " \"algorithmClassName\"=\"org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture\"\n"
+ " 'strategy'='STANDARD',\n"
+ " 'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'\n"
+ " )\n"
+ " )\n"
+ " )\n"
+ ")");
statement.execute("CREATE SHARDING TABLE RULE t_order (\n"
+ " DATANODES(\"<LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order\"),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=\"SNOWFLAKE\"))\n"
statement.execute("CREATE SHARDING TABLE RULE IF NOT EXISTS t_order (\n"
+ " DATANODES('<LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order'),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='SNOWFLAKE'))\n"
+ "), t_order_item (\n"
+ " DATANODES(\"<LITERAL>ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item\"),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=\"SNOWFLAKE\"))\n"
+ " DATANODES('<LITERAL>ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),\n"
+ " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME='SNOWFLAKE'))\n"
+ ")");
statement.execute("CREATE BROADCAST TABLE RULE t_address");
}
Expand Down
Loading

0 comments on commit 23d7773

Please sign in to comment.