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

chengzhang 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 aa194284b58 Refactor StorageUnitsOperateException (#30711)
aa194284b58 is described below

commit aa194284b5847251f2e342ef7c049f41f899ae97
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 14:58:32 2024 +0800

    Refactor StorageUnitsOperateException (#30711)
    
    * Refactor StorageUnitsOperateException
    
    * Refactor StorageUnitsOperateException
---
 .../content/user-manual/error-code/sql-error-code.cn.md        |  2 +-
 .../content/user-manual/error-code/sql-error-code.en.md        |  2 +-
 ...geUnitsException.java => StorageUnitsOperateException.java} | 10 ++++++----
 .../executor/rdl/resource/AlterStorageUnitExecutor.java        |  5 ++---
 .../executor/rdl/resource/RegisterStorageUnitExecutor.java     |  5 ++---
 .../executor/rdl/resource/UnregisterStorageUnitExecutor.java   |  5 ++---
 .../sql/type/kernel/category/MetaDataSQLException.java         |  4 ++++
 .../sql/type/kernel/category/ResourceDefinitionException.java  |  4 ++++
 .../backend/util/YamlDatabaseConfigurationImportExecutor.java  |  4 ++--
 9 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md 
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index c037cca8a0d..9af97e61db2 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -26,7 +26,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 10022       | Can not load table with database name \`%s\` and 
data source name \`%s\`.      |
 | 0A000     | 10030       | Can not drop schema \`%s\` because of contains 
tables.                         |
 | 0A000     | 10040       | Unsupported storage type of \`%s.%s\`.             
                            |
-| 44000     | 10100       | Can not process invalid storage units, error 
messages is: %s                   |
+| 44000     | 10100       | Can not %s storage units '%s'.                     
                            |
 | 44000     | 10101       | Storage units '%s' do not exist in database '%s'.  
                            |
 | 44000     | 10102       | There is no storage unit in the database '%s'.     
                            |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.              
                            |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md 
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 8352ea8869b..14adc58967e 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -26,7 +26,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 10022       | Can not load table with database name \`%s\` and 
data source name \`%s\`.      |
 | 0A000     | 10030       | Can not drop schema \`%s\` because of contains 
tables.                         |
 | 0A000     | 10040       | Unsupported storage type of \`%s.%s\`.             
                            |
-| 44000     | 10100       | Can not process invalid storage units, error 
messages is: %s                   |
+| 44000     | 10100       | Can not %s storage units '%s'.                     
                            |
 | 44000     | 10101       | Storage units '%s' do not exist in database '%s'.  
                            |
 | 44000     | 10102       | There is no storage unit in the database '%s'.     
                            |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.              
                            |
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsOperateException.java
similarity index 73%
rename from 
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
rename to 
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsOperateException.java
index 5429da2a8fd..7c5a726b658 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsOperateException.java
@@ -20,14 +20,16 @@ package 
org.apache.shardingsphere.infra.exception.storageunit;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ResourceDefinitionException;
 
+import java.util.Collection;
+
 /**
- * Invalid storage units exception.
+ * Storage units operate exception.
  */
-public final class InvalidStorageUnitsException extends 
ResourceDefinitionException {
+public final class StorageUnitsOperateException extends 
ResourceDefinitionException {
     
     private static final long serialVersionUID = 7029641448948791509L;
     
-    public InvalidStorageUnitsException(final Exception cause) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process 
invalid storage units, error messages is: %s", cause.getMessage());
+    public StorageUnitsOperateException(final String operationType, final 
Collection<String> storageUnitNames, final Exception cause) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, String.format("Can not 
%s storage units '%s'.", operationType, String.join(", ", storageUnitNames)), 
cause);
     }
 }
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
index 4d588e062d5..8f881c0b91b 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
@@ -35,7 +35,7 @@ import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePrecondition
 import 
org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
-import 
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -67,8 +67,7 @@ public final class AlterStorageUnitExecutor implements 
DistSQLUpdateExecutor<Alt
         try {
             
contextManager.getInstanceContext().getModeContextManager().alterStorageUnits(database.getName(),
 propsMap);
         } catch (final SQLException | ShardingSphereExternalException ex) {
-            log.error("Alter storage unit failed", ex);
-            throw new InvalidStorageUnitsException(ex);
+            throw new StorageUnitsOperateException("alter", propsMap.keySet(), 
ex);
         }
     }
     
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
index 371a2a5228c..cf8e568fdcc 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
@@ -29,7 +29,7 @@ import 
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePo
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
-import 
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -69,8 +69,7 @@ public final class RegisterStorageUnitExecutor implements 
DistSQLUpdateExecutor<
         try {
             
contextManager.getInstanceContext().getModeContextManager().registerStorageUnits(database.getName(),
 propsMap);
         } catch (final SQLException | ShardingSphereExternalException ex) {
-            log.error("Register storage unit failed", ex);
-            throw new InvalidStorageUnitsException(ex);
+            throw new StorageUnitsOperateException("register", 
propsMap.keySet(), ex);
         }
     }
     
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
index d3d7d5263bf..b509d95db2c 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
@@ -26,7 +26,7 @@ import 
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.Unregi
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.exception.core.external.server.ShardingSphereServerException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.InUsedStorageUnitException;
-import 
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -59,8 +59,7 @@ public final class UnregisterStorageUnitExecutor implements 
DistSQLUpdateExecuto
         try {
             
contextManager.getInstanceContext().getModeContextManager().unregisterStorageUnits(database.getName(),
 sqlStatement.getStorageUnitNames());
         } catch (final SQLException | ShardingSphereServerException ex) {
-            log.error("Unregister storage unit failed", ex);
-            throw new InvalidStorageUnitsException(ex);
+            throw new StorageUnitsOperateException("unregister", 
sqlStatement.getStorageUnitNames(), ex);
         }
     }
     
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
index 5beb5bffd60..5e19f43fb28 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
@@ -32,4 +32,8 @@ public abstract class MetaDataSQLException extends 
KernelSQLException {
     protected MetaDataSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Object... messageArgs) {
         super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
     }
+    
+    protected MetaDataSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
+        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+    }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ResourceDefinitionException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ResourceDefinitionException.java
index 8832b7bcb3d..66b6fc6d89d 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ResourceDefinitionException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ResourceDefinitionException.java
@@ -33,6 +33,10 @@ public abstract class ResourceDefinitionException extends 
MetaDataSQLException {
         super(sqlState, getErrorCode(errorCode), reason, messageArgs);
     }
     
+    protected ResourceDefinitionException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
+        super(sqlState, getErrorCode(errorCode), reason, cause);
+    }
+    
     private static int getErrorCode(final int errorCode) {
         Preconditions.checkArgument(errorCode >= 0 && errorCode < 100, "The 
value range of error code should be [0, 1000).");
         return RESOURCE_CODE * 100 + errorCode;
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index f28e6847de9..cea0087d579 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.util;
 
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckEngine;
 import 
org.apache.shardingsphere.distsql.handler.exception.datasource.MissingRequiredDataSourcesException;
-import 
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
 import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
@@ -118,7 +118,7 @@ public final class YamlDatabaseConfigurationImportExecutor {
         try {
             
ProxyContext.getInstance().getContextManager().getInstanceContext().getModeContextManager().registerStorageUnits(databaseName,
 propsMap);
         } catch (final SQLException ex) {
-            throw new InvalidStorageUnitsException(ex);
+            throw new StorageUnitsOperateException("import", 
propsMap.keySet(), ex);
         }
         Map<String, StorageUnit> storageUnits = 
ProxyContext.getInstance().getContextManager()
                 
.getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnits();

Reply via email to