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

sunnianjun 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 a87708ada59 Refactor UnregisterStorageUnitExecutor (#30712)
a87708ada59 is described below

commit a87708ada59ea2a6159b5faf8b3a9bb6218de317
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 15:25:55 2024 +0800

    Refactor UnregisterStorageUnitExecutor (#30712)
    
    * Refactor UnregisterStorageUnitExecutor
    
    * Refactor UnregisterStorageUnitExecutor
    
    * Refactor UnregisterStorageUnitExecutor
---
 .../resource/UnregisterStorageUnitExecutor.java    | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

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 b509d95db2c..d2a62d9bdb5 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,8 +26,8 @@ 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.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
+import 
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -37,7 +37,6 @@ 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;
 
@@ -76,21 +75,16 @@ public final class UnregisterStorageUnitExecutor implements 
DistSQLUpdateExecuto
         if (inUsedStorageUnitNames.isEmpty()) {
             return;
         }
-        Collection<Class<ShardingSphereRule>> ignoreShardingSphereRules = 
getIgnoreShardingSphereRules(sqlStatement);
+        Collection<Class<ShardingSphereRule>> ignoreUsageCheckRules = 
getIgnoreUsageCheckRules(sqlStatement);
         String firstResource = inUsedStorageUnitNames.iterator().next();
-        
ShardingSpherePreconditions.checkState(!ignoreShardingSphereRules.isEmpty(), () 
-> new InUsedStorageUnitException(firstResource, 
inUsedStorageUnits.get(firstResource)));
-        checkInUsedIgnoreTables(new HashSet<>(inUsedStorageUnitNames), 
inUsedStorageUnits, ignoreShardingSphereRules);
+        
ShardingSpherePreconditions.checkState(!ignoreUsageCheckRules.isEmpty(), () -> 
new InUsedStorageUnitException(firstResource, 
inUsedStorageUnits.get(firstResource)));
+        checkInUsedIgnoreTables(new HashSet<>(inUsedStorageUnitNames), 
inUsedStorageUnits, ignoreUsageCheckRules);
     }
     
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    private Collection<Class<ShardingSphereRule>> 
getIgnoreShardingSphereRules(final UnregisterStorageUnitStatement sqlStatement) 
{
-        Collection<Class<ShardingSphereRule>> result = new LinkedList<>();
-        for (StorageUnitDefinitionProcessor each : 
ShardingSphereServiceLoader.getServiceInstances(StorageUnitDefinitionProcessor.class))
 {
-            if (each.ignoreUsageCheckOnUnregister(sqlStatement)) {
-                result.add(each.getRuleClass());
-            }
-        }
-        return result;
+    @SuppressWarnings("unchecked")
+    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());
     }
     
     private void checkInUsedIgnoreTables(final Collection<String> 
inUsedResourceNames, final Map<String, Collection<Class<? extends 
ShardingSphereRule>>> inUsedStorageUnits,

Reply via email to