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

totalo 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 193c3ccc2af Add DistSQLExecutorCurrentRuleRequired (#29902)
193c3ccc2af is described below

commit 193c3ccc2af56bb14027bfe1885d2271c9faa670
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 29 15:26:18 2024 +0800

    Add DistSQLExecutorCurrentRuleRequired (#29902)
    
    * Add DistSQLExecutorCurrentRuleRequired
    
    * Add DistSQLExecutorCurrentRuleRequired
    
    * Add DistSQLExecutorCurrentRuleRequired
    
    * Add DistSQLExecutorCurrentRuleRequired
    
    * Add DistSQLExecutorCurrentRuleRequired
---
 .../handler/update/AlterEncryptRuleExecutor.java   |  7 ++--
 .../update/AlterEncryptRuleExecutorTest.java       |  5 ---
 .../handler/update/AlterMaskRuleExecutor.java      |  7 ++--
 .../handler/update/AlterMaskRuleExecutorTest.java  | 11 ++-----
 .../ReadwriteSplittingRuleStatementChecker.java    |  1 -
 .../AlterReadwriteSplittingRuleExecutor.java       |  2 ++
 .../AlterReadwriteSplittingRuleExecutorTest.java   |  5 ---
 .../AlterDefaultShadowAlgorithmExecutor.java       |  3 +-
 .../handler/update/AlterShadowRuleExecutor.java    |  3 +-
 .../AlterDefaultShadowAlgorithmExecutorTest.java   |  8 -----
 .../update/AlterShadowRuleExecutorTest.java        |  6 ----
 .../AlterDefaultShardingStrategyExecutor.java      |  7 ++--
 .../AlterShardingTableReferenceRuleExecutor.java   |  7 ++--
 .../update/AlterShardingTableRuleExecutor.java     |  5 ++-
 .../AlterDefaultShardingStrategyExecutorTest.java  |  7 ----
 ...lterShardingTableReferenceRuleExecutorTest.java |  7 +---
 .../DistSQLExecutorCurrentRuleRequired.java        | 38 ++++++++++++++++++++++
 .../DatabaseRuleDefinitionExecuteEngine.java       | 14 +++++++-
 .../handler/update/UnloadSingleTableExecutor.java  |  7 ++--
 .../distsql/DistSQLBackendHandlerFactoryTest.java  |  1 +
 20 files changed, 74 insertions(+), 77 deletions(-)

diff --git 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
index 94258e7f0d6..1fa59165d6b 100644
--- 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
+++ 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
@@ -43,6 +44,7 @@ import java.util.stream.Collectors;
 /**
  * Alter encrypt rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Encrypt")
 @Setter
 public final class AlterEncryptRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterEncryptRuleStatement, EncryptRuleConfiguration> {
     
@@ -50,16 +52,11 @@ public final class AlterEncryptRuleExecutor implements 
DatabaseRuleAlterExecutor
     
     @Override
     public void checkBeforeUpdate(final AlterEncryptRuleStatement 
sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
-        checkCurrentRuleConfiguration(currentRuleConfig);
         checkToBeAlteredRules(sqlStatement, currentRuleConfig);
         checkColumnNames(sqlStatement);
         checkToBeAlteredEncryptors(sqlStatement);
     }
     
-    private void checkCurrentRuleConfiguration(final EncryptRuleConfiguration 
currentRuleConfig) {
-        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Encrypt", database.getName()));
-    }
-    
     private void checkToBeAlteredRules(final AlterEncryptRuleStatement 
sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
         Collection<String> currentEncryptTableNames = 
currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
         Collection<String> notExistEncryptTableNames = 
getToBeAlteredEncryptTableNames(sqlStatement).stream().filter(each -> 
!currentEncryptTableNames.contains(each)).collect(Collectors.toList());
diff --git 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
index 25a9a100b32..f6724ff06fa 100644
--- 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
+++ 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
@@ -55,11 +55,6 @@ class AlterEncryptRuleExecutorTest {
         executor.setDatabase(mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS));
     }
     
-    @Test
-    void assertCheckSQLStatementWithoutCurrentRule() {
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("MD5"), null));
-    }
-    
     @Test
     void assertCheckSQLStatementWithoutToBeAlteredRules() {
         assertThrows(MissingRequiredRuleException.class,
diff --git 
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
 
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
index b2c7bab4096..81b55d704b0 100644
--- 
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
+++ 
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.mask.distsql.handler.update;
 
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -39,6 +40,7 @@ import java.util.stream.Collectors;
 /**
  * Alter mask rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Mask")
 @Setter
 public final class AlterMaskRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterMaskRuleStatement, MaskRuleConfiguration> {
     
@@ -46,14 +48,9 @@ public final class AlterMaskRuleExecutor implements 
DatabaseRuleAlterExecutor<Al
     
     @Override
     public void checkBeforeUpdate(final AlterMaskRuleStatement sqlStatement, 
final MaskRuleConfiguration currentRuleConfig) {
-        checkCurrentRuleConfiguration(currentRuleConfig);
         checkToBeAlteredRules(sqlStatement, currentRuleConfig);
     }
     
-    private void checkCurrentRuleConfiguration(final MaskRuleConfiguration 
currentRuleConfig) {
-        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Mask", database.getName()));
-    }
-    
     private void checkToBeAlteredRules(final AlterMaskRuleStatement 
sqlStatement, final MaskRuleConfiguration currentRuleConfig) {
         Collection<String> currentMaskTableNames = 
currentRuleConfig.getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toList());
         Collection<String> notExistedMaskTableNames = 
getToBeAlteredMaskTableNames(sqlStatement).stream().filter(each -> 
!currentMaskTableNames.contains(each)).collect(Collectors.toList());
diff --git 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java
 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java
index b9df3971f1d..d1745749a6f 100644
--- 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java
+++ 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java
@@ -51,23 +51,18 @@ class AlterMaskRuleExecutorTest {
     }
     
     @Test
-    void assertCheckSQLStatementWithoutCurrentRule() {
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("MD5"), null));
-    }
-    
-    @Test
-    void assertCheckSQLStatementWithoutToBeAlteredRules() {
+    void assertCheckBeforeUpdateWithoutToBeAlteredRules() {
         assertThrows(MissingRequiredRuleException.class,
                 () -> executor.checkBeforeUpdate(createSQLStatement("MD5"), 
new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
     }
     
     @Test
-    void assertCheckSQLStatementWithoutToBeAlteredAlgorithm() {
+    void assertCheckBeforeUpdateWithoutToBeAlteredAlgorithm() {
         assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("INVALID_TYPE"), 
createCurrentRuleConfig()));
     }
     
     @Test
-    void assertCheckSQLStatementWithIncompleteDataType() {
+    void assertCheckBeforeUpdateWithIncompleteDataType() {
         MaskColumnSegment columnSegment = new MaskColumnSegment("user_id", new 
AlgorithmSegment("test", new Properties()));
         MaskRuleSegment ruleSegment = new MaskRuleSegment("t_mask", 
Collections.singleton(columnSegment));
         AlterMaskRuleStatement statement = new 
AlterMaskRuleStatement(Collections.singleton(ruleSegment));
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index af729839d23..34ab5b3db7a 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -78,7 +78,6 @@ public final class ReadwriteSplittingRuleStatementChecker {
      */
     public static void checkAlteration(final ShardingSphereDatabase database, 
final Collection<ReadwriteSplittingRuleSegment> segments, final 
ReadwriteSplittingRuleConfiguration currentRuleConfig) {
         String databaseName = database.getName();
-        checkRuleConfigurationExist(database, currentRuleConfig);
         checkDuplicateRuleNamesWithSelf(databaseName, segments);
         checkRuleNamesExist(segments, currentRuleConfig, databaseName);
         checkDataSourcesExist(databaseName, segments, database);
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
index 5d33aafe5d6..71fd3838750 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
 
 import com.google.common.base.Preconditions;
 import lombok.Setter;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -39,6 +40,7 @@ import java.util.stream.Collectors;
 /**
  * Alter readwrite-splitting rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Readwrite-splitting")
 @Setter
 public final class AlterReadwriteSplittingRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterReadwriteSplittingRuleStatement, 
ReadwriteSplittingRuleConfiguration> {
     
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutorTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutorTest.java
index 0e9655a5d69..86d5f969ce7 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutorTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutorTest.java
@@ -64,11 +64,6 @@ class AlterReadwriteSplittingRuleExecutorTest {
         executor.setDatabase(database);
     }
     
-    @Test
-    void assertCheckSQLStatementWithoutCurrentRule() {
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("TEST"), null));
-    }
-    
     @Test
     void assertCheckSQLStatementWithoutToBeAlteredRules() {
         assertThrows(MissingRequiredRuleException.class,
diff --git 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
index c7ca8ac07f6..ed274a7f5ec 100644
--- 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
+++ 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
@@ -38,6 +39,7 @@ import java.util.Map;
 /**
  * Alter default shadow algorithm executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Shadow")
 @Setter
 public final class AlterDefaultShadowAlgorithmExecutor implements 
DatabaseRuleAlterExecutor<AlterDefaultShadowAlgorithmStatement, 
ShadowRuleConfiguration> {
     
@@ -47,7 +49,6 @@ public final class AlterDefaultShadowAlgorithmExecutor 
implements DatabaseRuleAl
     
     @Override
     public void checkBeforeUpdate(final AlterDefaultShadowAlgorithmStatement 
sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
-        
ShadowRuleStatementChecker.checkRuleConfigurationExists(database.getName(), 
currentRuleConfig);
         
checkAlgorithms(sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment(), 
currentRuleConfig);
     }
     
diff --git 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
index d160aeb9f9c..c38b7a29120 100644
--- 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
+++ 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
@@ -21,6 +21,7 @@ import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.AlgorithmInUsedException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -41,6 +42,7 @@ import java.util.Map;
 /**
  * Alter shadow rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Shadow")
 @Setter
 public final class AlterShadowRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterShadowRuleStatement, ShadowRuleConfiguration> {
     
@@ -48,7 +50,6 @@ public final class AlterShadowRuleExecutor implements 
DatabaseRuleAlterExecutor<
     
     @Override
     public void checkBeforeUpdate(final AlterShadowRuleStatement sqlStatement, 
final ShadowRuleConfiguration currentRuleConfig) {
-        
ShadowRuleStatementChecker.checkRuleConfigurationExists(database.getName(), 
currentRuleConfig);
         checkRuleNames(sqlStatement.getRules(), currentRuleConfig);
         
ShadowRuleStatementChecker.checkStorageUnitsExist(ShadowRuleStatementSupporter.getStorageUnitNames(sqlStatement.getRules()),
 database);
         checkAlgorithms(sqlStatement.getRules());
diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmExecutorTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmExecutorTest.java
index 966f2728a9a..1e168e2a1b9 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmExecutorTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmExecutorTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.shadow.distsql.update;
 
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
-import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
 import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -57,13 +56,6 @@ class AlterDefaultShadowAlgorithmExecutorTest {
         executor.setDatabase(mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS));
     }
     
-    @Test
-    void assertExecuteAlgorithmWithoutConfiguration() {
-        AlterDefaultShadowAlgorithmStatement sqlStatement = new 
AlterDefaultShadowAlgorithmStatement(
-                new ShadowAlgorithmSegment("sqlHintAlgorithm", new 
AlgorithmSegment("SQL_HINT", PropertiesBuilder.build(new Property("type", 
"value")))));
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(sqlStatement, null));
-    }
-    
     @Test
     void assertExecuteAlgorithmNotInMetaData() {
         Properties props = PropertiesBuilder.build(new Property("type", 
"value"));
diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleExecutorTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleExecutorTest.java
index 23a0e697ebf..656fb7d439e 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleExecutorTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleExecutorTest.java
@@ -76,12 +76,6 @@ class AlterShadowRuleExecutorTest {
         executor.setDatabase(database);
     }
     
-    @Test
-    void assertExecuteWithoutCurrentConfiguration() {
-        ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", 
null, null, null);
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(new 
AlterShadowRuleStatement(Arrays.asList(ruleSegment, ruleSegment)), null));
-    }
-    
     @Test
     void assertExecuteWithDuplicateRuleName() {
         ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", 
null, null, null);
diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
index 5ff67833819..3a37590fbf0 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
@@ -21,6 +21,7 @@ import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
@@ -39,6 +40,7 @@ import java.util.Optional;
 /**
  * Alter default sharding strategy executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Sharding")
 @Setter
 public final class AlterDefaultShardingStrategyExecutor implements 
DatabaseRuleAlterExecutor<AlterDefaultShardingStrategyStatement, 
ShardingRuleConfiguration> {
     
@@ -46,17 +48,12 @@ public final class AlterDefaultShardingStrategyExecutor 
implements DatabaseRuleA
     
     @Override
     public void checkBeforeUpdate(final AlterDefaultShardingStrategyStatement 
sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
-        checkCurrentRuleConfiguration(currentRuleConfig);
         if (!"none".equalsIgnoreCase(sqlStatement.getStrategyType())) {
             checkAlgorithm(sqlStatement);
         }
         checkExist(sqlStatement, currentRuleConfig);
     }
     
-    private void checkCurrentRuleConfiguration(final ShardingRuleConfiguration 
currentRuleConfig) {
-        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Sharding", database.getName()));
-    }
-    
     private void checkAlgorithm(final AlterDefaultShardingStrategyStatement 
sqlStatement) {
         
ShardingSpherePreconditions.checkState(ShardingStrategyType.contains(sqlStatement.getStrategyType()),
 () -> new 
InvalidAlgorithmConfigurationException(sqlStatement.getStrategyType()));
         
ShardingSpherePreconditions.checkState(ShardingStrategyType.getValueOf(sqlStatement.getStrategyType()).isValid(sqlStatement.getShardingColumn()),
diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
index 3cd8820a421..28a4edcfb72 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
@@ -21,6 +21,7 @@ import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -41,6 +42,7 @@ import java.util.stream.Collectors;
 /**
  * Alter sharding table reference rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Sharding")
 @Setter
 public final class AlterShardingTableReferenceRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterShardingTableReferenceRuleStatement, 
ShardingRuleConfiguration> {
     
@@ -48,17 +50,12 @@ public final class AlterShardingTableReferenceRuleExecutor 
implements DatabaseRu
     
     @Override
     public void checkBeforeUpdate(final 
AlterShardingTableReferenceRuleStatement sqlStatement, final 
ShardingRuleConfiguration currentRuleConfig) {
-        checkCurrentRuleConfiguration(currentRuleConfig);
         checkToBeAlteredRulesExisted(sqlStatement, currentRuleConfig);
         checkDuplicatedTablesInShardingTableReferenceRules(sqlStatement, 
currentRuleConfig);
         checkToBeReferencedShardingTablesExisted(sqlStatement, 
currentRuleConfig);
         checkShardingTableReferenceRulesValid(sqlStatement, currentRuleConfig);
     }
     
-    private void checkCurrentRuleConfiguration(final ShardingRuleConfiguration 
currentRuleConfig) {
-        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Sharding", database.getName()));
-    }
-    
     private void checkToBeAlteredRulesExisted(final 
AlterShardingTableReferenceRuleStatement sqlStatement, final 
ShardingRuleConfiguration currentRuleConfig) {
         Collection<String> currentRuleNames = 
currentRuleConfig.getBindingTableGroups().stream().map(ShardingTableReferenceRuleConfiguration::getName).collect(Collectors.toSet());
         Collection<String> notExistedRuleNames = 
sqlStatement.getRules().stream().map(TableReferenceRuleSegment::getName).filter(each
 -> !currentRuleNames.contains(each)).collect(Collectors.toSet());
diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
index 99f9bec1f04..69c2be3292c 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
@@ -18,9 +18,8 @@
 package org.apache.shardingsphere.sharding.distsql.handler.update;
 
 import lombok.Setter;
-import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
-import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -35,6 +34,7 @@ import java.util.stream.Collectors;
 /**
  * Alter sharding table rule executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Sharding")
 @Setter
 public final class AlterShardingTableRuleExecutor implements 
DatabaseRuleAlterExecutor<AlterShardingTableRuleStatement, 
ShardingRuleConfiguration> {
     
@@ -42,7 +42,6 @@ public final class AlterShardingTableRuleExecutor implements 
DatabaseRuleAlterEx
     
     @Override
     public void checkBeforeUpdate(final AlterShardingTableRuleStatement 
sqlStatement, final ShardingRuleConfiguration currentRuleConfig) {
-        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Sharding", database.getName()));
         ShardingTableRuleStatementChecker.checkAlteration(database, 
sqlStatement.getRules(), currentRuleConfig);
     }
     
diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyExecutorTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyExecutorTest.java
index 7087d61919d..33b10009102 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyExecutorTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyExecutorTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.distsql.update;
 
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
-import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
 import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -58,12 +57,6 @@ class AlterDefaultShardingStrategyExecutorTest {
                 () -> executor.checkBeforeUpdate(new 
AlterDefaultShardingStrategyStatement("TABLE", "invalidType", null, null), new 
ShardingRuleConfiguration()));
     }
     
-    @Test
-    void assertExecuteWithoutCurrentConfiguration() {
-        AlterDefaultShardingStrategyStatement statement = new 
AlterDefaultShardingStrategyStatement("TABLE", "standard", "order_id", null);
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(statement, null));
-    }
-    
     @Test
     void assertExecuteWithNotExist() {
         AlterDefaultShardingStrategyStatement statement = new 
AlterDefaultShardingStrategyStatement("TABLE", "standard", "order_id", null);
diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java
index 98c90395872..85092cf91db 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java
@@ -46,12 +46,7 @@ class AlterShardingTableReferenceRuleExecutorTest {
     }
     
     @Test
-    void assertCheckWithoutCurrentRuleConfig() {
-        assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("foo", "t_order,t_order_item"), 
null));
-    }
-    
-    @Test
-    void assertCheckWithNotExistedRule() {
+    void assertCheckBeforeUpdateWithNotExistedRule() {
         assertThrows(MissingRequiredRuleException.class, () -> 
executor.checkBeforeUpdate(createSQLStatement("notExisted", "t_1,t_2"), 
createCurrentRuleConfiguration()));
     }
     
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
new file mode 100644
index 00000000000..240601308a2
--- /dev/null
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.distsql.handler.required;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * DistSQL executor current rule required.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DistSQLExecutorCurrentRuleRequired {
+    
+    /**
+     * Get rule type.
+     * 
+     * @return rule type
+     */
+    String value();
+}
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
index 457afbab480..6899c31026c 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
@@ -18,10 +18,13 @@
 package 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.engine.database;
 
 import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleDefinitionExecutor;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleDropExecutor;
 import 
org.apache.shardingsphere.distsql.statement.rdl.rule.RuleDefinitionStatement;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 
@@ -50,13 +53,22 @@ public final class DatabaseRuleDefinitionExecuteEngine {
         Class<? extends RuleConfiguration> ruleConfigClass = 
executor.getRuleConfigurationClass();
         RuleConfiguration currentRuleConfig = 
findCurrentRuleConfiguration(database, ruleConfigClass).orElse(null);
         executor.setDatabase(database);
-        executor.checkBeforeUpdate(sqlStatement, currentRuleConfig);
+        checkBeforeUpdate(currentRuleConfig);
         if (getRefreshStatus(currentRuleConfig)) {
             
contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService()
                     
.switchActiveVersion(DatabaseRuleOperatorFactory.newInstance(contextManager, 
executor).operate(sqlStatement, database, currentRuleConfig));
         }
     }
     
+    @SuppressWarnings("unchecked")
+    private void checkBeforeUpdate(final RuleConfiguration currentRuleConfig) {
+        DistSQLExecutorCurrentRuleRequired currentRuleRequired = 
executor.getClass().getAnnotation(DistSQLExecutorCurrentRuleRequired.class);
+        if (null != currentRuleRequired) {
+            ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> 
new MissingRequiredRuleException(currentRuleRequired.value(), 
database.getName()));
+        }
+        executor.checkBeforeUpdate(sqlStatement, currentRuleConfig);
+    }
+    
     private Optional<RuleConfiguration> findCurrentRuleConfiguration(final 
ShardingSphereDatabase database, final Class<? extends RuleConfiguration> 
ruleConfigClass) {
         return 
database.getRuleMetaData().getConfigurations().stream().filter(each -> 
ruleConfigClass.isAssignableFrom(each.getClass())).findFirst();
     }
diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
index 0410f3c6027..170ab2143c4 100644
--- 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.single.distsql.handler.update;
 import com.google.common.base.Splitter;
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import 
org.apache.shardingsphere.distsql.handler.type.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -40,6 +41,7 @@ import java.util.stream.Collectors;
 /**
  * Unload single table statement executor.
  */
+@DistSQLExecutorCurrentRuleRequired("Single")
 @Setter
 public final class UnloadSingleTableExecutor implements 
DatabaseRuleAlterExecutor<UnloadSingleTableStatement, SingleRuleConfiguration> {
     
@@ -47,14 +49,9 @@ public final class UnloadSingleTableExecutor implements 
DatabaseRuleAlterExecuto
     
     @Override
     public void checkBeforeUpdate(final UnloadSingleTableStatement 
sqlStatement, final SingleRuleConfiguration currentRuleConfig) {
-        checkCurrentRuleConfig(currentRuleConfig);
         checkTables(sqlStatement, currentRuleConfig);
     }
     
-    private void checkCurrentRuleConfig(final SingleRuleConfiguration 
currentRuleConfig) {
-        ShardingSpherePreconditions.checkState(null != currentRuleConfig, () 
-> new MissingRequiredRuleException("Single", database.getName()));
-    }
-    
     private void checkTables(final UnloadSingleTableStatement sqlStatement, 
final SingleRuleConfiguration currentRuleConfig) {
         if (sqlStatement.isUnloadAllTables()) {
             return;
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java
index 12a7187dd72..a571871e3a7 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -103,6 +103,7 @@ class DistSQLBackendHandlerFactoryTest {
         MetaDataContexts metaDataContexts = mockMetaDataContexts(database);
         when(result.getMetaDataContexts()).thenReturn(metaDataContexts);
         
when(result.getInstanceContext().getModeContextManager()).thenReturn(mock(ModeContextManager.class));
+        
when(result.getInstanceContext().getModeConfiguration().getType()).thenReturn("Cluster");
         return result;
     }
     


Reply via email to