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 f56d83cd696 Refactor InvalidStorageUnitStatusException (#30714)
f56d83cd696 is described below

commit f56d83cd696f730723214c1cb1440259e350ac72
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 16:54:50 2024 +0800

    Refactor InvalidStorageUnitStatusException (#30714)
    
    * Refactor InvalidStorageUnitStatusException
    
    * Refactor InvalidStorageUnitStatusException
---
 .../content/user-manual/error-code/sql-error-code.cn.md      |  4 ++--
 .../content/user-manual/error-code/sql-error-code.en.md      |  4 ++--
 .../exception/MissingRequiredReadStorageUnitException.java   |  2 +-
 .../AlterReadwriteSplittingStorageUnitStatusExecutor.java    |  6 +++---
 .../storageunit}/InvalidStorageUnitStatusException.java      | 10 +++++-----
 .../executor/rdl/resource/UnregisterStorageUnitExecutor.java | 12 +++++++++---
 6 files changed, 22 insertions(+), 16 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 7036a259da9..1aa48ab6366 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
@@ -31,10 +31,10 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42S02     | 10102       | There is no storage unit in database '%s'.         
                            |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.              
                            |
 | 44000     | 10104       | Duplicate storage unit names '%s'.                 
                            |
-| 44000     | 10105       | Invalid storage unit status, error message is: %s. 
                            |
-| 44000     | 10106       | Read storage unit '%s' does not exist in rule 
'%s'.                            |
 | 0A000     | 10108       | Can not alter connection info in storage units: 
'%s'.                          |
 | 0A000     | 10109       | Storage units can not connect, error messages are: 
%s.                         |
+| 44000     | 10120       | Invalid storage unit status, error message is: %s. 
                            |
+| 44000     | 10150       | Read storage unit '%s' does not exist in rule 
'%s'.                            |
 | 44000     | 10200       | Invalid '%s' rule '%s', error message is: %s       
                            |
 | 44000     | 10201       | %s rules '%s' do not exist in database '%s'.       
                            |
 | 44000     | 10202       | %s rules '%s' in database '%s' are still in used.  
                            |
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 3909ee9560c..adbe0d3458e 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
@@ -31,10 +31,10 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42S02     | 10102       | There is no storage unit in database '%s'.         
                            |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.              
                            |
 | 44000     | 10104       | Duplicate storage unit names '%s'.                 
                            |
-| 44000     | 10105       | Invalid storage unit status, error message is: %s. 
                            |
-| 44000     | 10106       | Read storage unit '%s' does not exist in rule 
'%s'.                            |
 | 0A000     | 10108       | Can not alter connection info in storage units: 
'%s'.                          |
 | 0A000     | 10109       | Storage units can not connect, error messages are: 
%s.                         |
+| 44000     | 10120       | Invalid storage unit status, error message is: %s. 
                            |
+| 44000     | 10150       | Read storage unit '%s' does not exist in rule 
'%s'.                            |
 | 44000     | 10200       | Invalid '%s' rule '%s', error message is: %s       
                            |
 | 44000     | 10201       | %s rules '%s' do not exist in database '%s'.       
                            |
 | 44000     | 10202       | %s rules '%s' in database '%s' are still in used.  
                            |
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
index 8c9a1e60a76..5e22e1c45c7 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/MissingRequiredReadStorageUnitException.java
@@ -28,6 +28,6 @@ public final class MissingRequiredReadStorageUnitException 
extends StorageUnitDe
     private static final long serialVersionUID = -4252553422332603648L;
     
     public MissingRequiredReadStorageUnitException(final String ruleName, 
final String storageUnitName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 6, "Read storage unit '%s' 
does not exist in rule '%s'.", storageUnitName, ruleName);
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 50, "Read storage unit 
'%s' does not exist in rule '%s'.", storageUnitName, ruleName);
     }
 }
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
index 980019a0c31..07eda407ef3 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
@@ -28,7 +28,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.mode.storage.service.StorageNodeStatusService;
-import 
org.apache.shardingsphere.readwritesplitting.distsql.handler.exception.InvalidStorageUnitStatusException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitStatusException;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.handler.exception.MissingRequiredReadStorageUnitException;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.statement.AlterReadwriteSplittingStorageUnitStatusStatement;
 import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
@@ -64,10 +64,10 @@ public final class 
AlterReadwriteSplittingStorageUnitStatusExecutor
                 () -> new 
MissingRequiredReadStorageUnitException(dataSourceRule.get().getName(), 
sqlStatement.getStorageUnitName()));
         if (sqlStatement.isEnable()) {
             
ShardingSpherePreconditions.checkState(dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
-                    () -> new InvalidStorageUnitStatusException("the storage 
unit is not disabled"));
+                    () -> new InvalidStorageUnitStatusException("storage unit 
is not disabled"));
         } else {
             
ShardingSpherePreconditions.checkState(!dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
-                    () -> new InvalidStorageUnitStatusException("the storage 
unit is already disabled"));
+                    () -> new InvalidStorageUnitStatusException("storage unit 
is already disabled"));
         }
     }
     
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitStatusException.java
similarity index 72%
rename from 
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
rename to 
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitStatusException.java
index 27294d537c6..db18b32775d 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/exception/InvalidStorageUnitStatusException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitStatusException.java
@@ -15,19 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.readwritesplitting.distsql.handler.exception;
+package org.apache.shardingsphere.infra.exception.storageunit;
 
-import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitDefinitionViolationException;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ResourceDefinitionException;
 
 /**
  * Invalid storage unit status exception.
  */
-public final class InvalidStorageUnitStatusException extends 
StorageUnitDefinitionViolationException {
+public final class InvalidStorageUnitStatusException extends 
ResourceDefinitionException {
     
     private static final long serialVersionUID = 4029749233439176539L;
     
-    public InvalidStorageUnitStatusException(final String errorMessages) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, "Invalid storage unit 
status, error message is: %s.", errorMessages);
+    public InvalidStorageUnitStatusException(final String errorMessage) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20, "Invalid storage unit 
status, error message is: %s.", errorMessage);
     }
 }
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 d2a62d9bdb5..ffbab47a0e7 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
@@ -37,6 +37,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.stream.Collectors;
 
@@ -81,10 +82,15 @@ public final class UnregisterStorageUnitExecutor implements 
DistSQLUpdateExecuto
         checkInUsedIgnoreTables(new HashSet<>(inUsedStorageUnitNames), 
inUsedStorageUnits, ignoreUsageCheckRules);
     }
     
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "rawtypes"})
     private Collection<Class<ShardingSphereRule>> 
getIgnoreUsageCheckRules(final UnregisterStorageUnitStatement sqlStatement) {
-        return 
ShardingSphereServiceLoader.getServiceInstances(StorageUnitDefinitionProcessor.class).stream()
-                .filter(each -> 
each.ignoreUsageCheckOnUnregister(sqlStatement)).map(StorageUnitDefinitionProcessor::getRuleClass).collect(Collectors.toList());
+        Collection<Class<ShardingSphereRule>> result = new LinkedList<>();
+        for (StorageUnitDefinitionProcessor each : 
ShardingSphereServiceLoader.getServiceInstances(StorageUnitDefinitionProcessor.class))
 {
+            if (each.ignoreUsageCheckOnUnregister(sqlStatement)) {
+                result.add(each.getRuleClass());
+            }
+        }
+        return result;
     }
     
     private void checkInUsedIgnoreTables(final Collection<String> 
inUsedResourceNames, final Map<String, Collection<Class<? extends 
ShardingSphereRule>>> inUsedStorageUnits,

Reply via email to