You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/02/24 03:24:05 UTC

[shardingsphere] branch master updated: Add information when throws UnavailableDataSourceException (#24223)

This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 5fec520bb98 Add information when throws UnavailableDataSourceException (#24223)
5fec520bb98 is described below

commit 5fec520bb9884e6c81da67f9943e3f7828a76a97
Author: skai <su...@gmail.com>
AuthorDate: Fri Feb 24 11:23:57 2023 +0800

    Add information when throws UnavailableDataSourceException (#24223)
    
    * Add information when throws UnavailableDataSourceException
    
    * Update UnavailableDataSourceException.java
---
 .../shardingsphere/infra/datasource/state/DataSourceStateManager.java | 2 +-
 .../datasource/state/exception/UnavailableDataSourceException.java    | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

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 b4dd26d1975..e2edf119c0f 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, () -> new UnavailableDataSourceException(ex));
+            ShardingSpherePreconditions.checkState(forceStart, () -> new UnavailableDataSourceException(ex, actualDataSourceName));
             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 e54840070da..42124925006 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
@@ -35,4 +35,8 @@ public final class UnavailableDataSourceException extends ShardingSphereServerEx
     public UnavailableDataSourceException(final SQLException cause) {
         super(ERROR_CATEGORY, ERROR_CODE, "Data source unavailable.", cause);
     }
+    
+    public UnavailableDataSourceException(final SQLException cause, final String databaseName) {
+        super(ERROR_CATEGORY, ERROR_CODE, String.format("Data source unavailable from `%s`.", databaseName), cause);
+    }
 }