You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/12/07 10:38:20 UTC
[shardingsphere] branch master updated: Fix exception info missing when data source is unavailable (#22718)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 a8a9fca66bb Fix exception info missing when data source is unavailable (#22718)
a8a9fca66bb is described below
commit a8a9fca66bb18e10a942cb9a57781d748f2af636
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Wed Dec 7 18:38:09 2022 +0800
Fix exception info missing when data source is unavailable (#22718)
---
.../infra/datasource/state/DataSourceStateManager.java | 2 +-
.../datasource/state/exception/UnavailableDataSourceException.java | 6 ++++--
.../shardingsphere/mode/metadata/MetadataContextsFactory.java | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/DataSourceStateManager.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/DataSourceStateManager.java
index 223903358a1..b4dd26d1975 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/DataSourceStateManager.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/DataSourceStateManager.java
@@ -84,7 +84,7 @@ public final class DataSourceStateManager {
try (Connection ignored = dataSource.getConnection()) {
dataSourceStates.put(getCacheKey(databaseName, actualDataSourceName), DataSourceState.ENABLED);
} catch (final SQLException ex) {
- ShardingSpherePreconditions.checkState(forceStart, UnavailableDataSourceException::new);
+ ShardingSpherePreconditions.checkState(forceStart, () -> new UnavailableDataSourceException(ex));
log.error("Data source unavailable, ignored with the -f parameter.", ex);
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/exception/UnavailableDataSourceException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/exception/UnavailableDataSourceException.java
index c6dba88bb57..e54840070da 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/exception/UnavailableDataSourceException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/state/exception/UnavailableDataSourceException.java
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.infra.datasource.state.exception;
import org.apache.shardingsphere.infra.util.exception.external.server.ShardingSphereServerException;
+import java.sql.SQLException;
+
/**
* Data source state exception.
*/
@@ -30,7 +32,7 @@ public final class UnavailableDataSourceException extends ShardingSphereServerEx
private static final int ERROR_CODE = 1;
- public UnavailableDataSourceException() {
- super(ERROR_CATEGORY, ERROR_CODE, "Data source unavailable.");
+ public UnavailableDataSourceException(final SQLException cause) {
+ super(ERROR_CATEGORY, ERROR_CODE, "Data source unavailable.", cause);
}
}
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetadataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetadataContextsFactory.java
index 9be63e4c1e9..f079f634191 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetadataContextsFactory.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetadataContextsFactory.java
@@ -109,7 +109,7 @@ public final class MetadataContextsFactory {
private static void checkDataSourceStates(final Map<String, DatabaseConfiguration> databaseConfigs, final Map<String, StorageNodeDataSource> storageNodes, final boolean force) {
Map<String, DataSourceState> storageDataSourceStates = getStorageDataSourceStates(storageNodes);
databaseConfigs.forEach((key, value) -> {
- if (null != value.getDataSources() && !value.getDataSources().isEmpty()) {
+ if (!value.getDataSources().isEmpty()) {
DataSourceStateManager.getInstance().initStates(key, value.getDataSources(), storageDataSourceStates, force);
}
});