This is an automated email from the ASF dual-hosted git repository.
azexin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 4ff6c5f87fd Add cause exception for
OverallConnectionNotEnoughException (#29410)
4ff6c5f87fd is described below
commit 4ff6c5f87fd41b0e0c53d2aba97a985b5c4b42e1
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Fri Dec 15 16:21:51 2023 +0800
Add cause exception for OverallConnectionNotEnoughException (#29410)
---
.../infra/exception/OverallConnectionNotEnoughException.java | 6 +++---
.../external/sql/type/kernel/category/ConnectionSQLException.java | 4 ++++
.../jdbc/core/connection/DriverDatabaseConnectionManager.java | 4 ++--
.../backend/connector/jdbc/datasource/JDBCBackendDataSource.java | 4 ++--
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/OverallConnectionNotEnoughException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/OverallConnectionNotEnoughException.java
index 7d9fc36e2ae..55dcc0a5ad9 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/OverallConnectionNotEnoughException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/OverallConnectionNotEnoughException.java
@@ -27,8 +27,8 @@ public final class OverallConnectionNotEnoughException
extends ConnectionSQLExce
private static final long serialVersionUID = -1297088138042287804L;
- public OverallConnectionNotEnoughException(final int desiredSize, final
int actualSize) {
- super(XOpenSQLState.CONNECTION_EXCEPTION, 20, "Can not get %d
connections one time, partition succeed connection(%d) have released. "
- + "Please consider increasing the `maxPoolSize` of the data
sources or decreasing the `max-connections-size-per-query` in properties.",
desiredSize, actualSize);
+ public OverallConnectionNotEnoughException(final int desiredSize, final
int actualSize, final Exception cause) {
+ super(XOpenSQLState.CONNECTION_EXCEPTION, 20, String.format("Can not
get %d connections one time, partition succeed connection(%d) have released. "
+ + "Please consider increasing the `maxPoolSize` of the data
sources or decreasing the `max-connections-size-per-query` in properties.",
desiredSize, actualSize), cause);
}
}
diff --git
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
index 562eda76807..946adb49ada 100644
---
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
+++
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
@@ -32,4 +32,8 @@ public abstract class ConnectionSQLException extends
KernelSQLException {
protected ConnectionSQLException(final SQLState sqlState, final int
errorCode, final String reason, final Object... messageArgs) {
super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
}
+
+ public ConnectionSQLException(final SQLState sqlState, final int
errorCode, final String reason, final Exception cause) {
+ super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+ }
}
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
index 4e7b958aae3..1fe9db95f8f 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
@@ -400,11 +400,11 @@ public final class DriverDatabaseConnectionManager
implements DatabaseConnection
Connection connection = createConnection(databaseName,
dataSourceName, dataSource, transactionConnectionContext);
methodInvocationRecorder.replay(connection);
result.add(connection);
- } catch (final SQLException ignored) {
+ } catch (final SQLException ex) {
for (Connection each : result) {
each.close();
}
- throw new OverallConnectionNotEnoughException(connectionSize,
result.size()).toSQLException();
+ throw new OverallConnectionNotEnoughException(connectionSize,
result.size(), ex).toSQLException();
}
}
return result;
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java
index dfb3e2ba82e..76f0cc66b86 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java
@@ -94,11 +94,11 @@ public final class JDBCBackendDataSource implements
BackendDataSource {
for (int i = 0; i < connectionSize; i++) {
try {
result.add(createConnection(databaseName, dataSourceName,
dataSource, transactionType));
- } catch (final SQLException ignored) {
+ } catch (final SQLException ex) {
for (Connection each : result) {
each.close();
}
- throw new OverallConnectionNotEnoughException(connectionSize,
result.size());
+ throw new OverallConnectionNotEnoughException(connectionSize,
result.size(), ex);
}
}
return result;