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

(shardingsphere) branch master updated: Refactor RuleDefinitionException (#30718)

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

zhonghongsheng 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 152da00c6c1 Refactor RuleDefinitionException (#30718)
152da00c6c1 is described below

commit 152da00c6c175b5954b78028135af588880ea6b3
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Mar 31 22:30:57 2024 +0800

    Refactor RuleDefinitionException (#30718)
    
    * Refactor DuplicateRuleException
    
    * Refactor MissingRequiredRuleException
    
    * Refactor InUsedRuleException
    
    * Refactor EmptyRuleException
    
    * Refactor MissingRequiredSingleTableException
    
    * Refactor DuplicateStorageUnitException
    
    * Refactor DuplicateStorageUnitException
---
 .../content/user-manual/error-code/sql-error-code.cn.md     | 13 +++++++------
 .../content/user-manual/error-code/sql-error-code.en.md     | 13 ++++++++-----
 .../handler/update/DropReadwriteSplittingRuleExecutor.java  |  4 ++--
 .../update/DropReadwriteSplittingRuleExecutorTest.java      |  4 ++--
 .../handler/update/DropShardingTableRuleExecutor.java       |  4 ++--
 .../distsql/update/DropShardingTableRuleExecutorTest.java   |  4 ++--
 .../infra/exception/rule/DuplicateRuleException.java        |  6 +++---
 ...RuleNotExistedException.java => EmptyRuleException.java} |  8 ++++----
 .../{RuleInUsedException.java => InUsedRuleException.java}  | 12 ++++++------
 .../infra/exception/rule/MissingRequiredRuleException.java  | 10 +++++-----
 .../AlterStorageUnitConnectionInfoException.java            |  2 +-
 ...onDefinition.java => DuplicateStorageUnitException.java} |  4 ++--
 .../exception/storageunit/StorageUnitsConnectException.java |  2 +-
 .../executor/rdl/resource/AlterStorageUnitExecutor.java     |  4 ++--
 .../executor/rdl/resource/RegisterStorageUnitExecutor.java  |  6 +++---
 .../executor/rdl/resource/AlterStorageUnitExecutorTest.java |  4 ++--
 .../rdl/resource/RegisterStorageUnitExecutorTest.java       |  8 ++++----
 .../exception/MissingRequiredSingleTableException.java      |  6 +++---
 .../proxy/backend/connector/DatabaseConnector.java          |  4 ++--
 .../proxy/backend/handler/distsql/rul/PreviewExecutor.java  |  4 ++--
 20 files changed, 63 insertions(+), 59 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 0177ef65c86..7feac46bb70 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
@@ -20,6 +20,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 10005       | Column '%s' in %s is ambiguous.                                                |
 | 42S02     | 10006       | Unknown column '%s' in '%s'.                                                   |
 | 42S02     | 10007       | Table or view \`%s\` does not exist.                                           |
+| 42S02     | 10008       | Missing required table '%s' in storage unit '%s'.                              |
 | 42000     | 10010       | Rule does not exist.                                                           |
 | 42S02     | 10020       | Schema \`%s\` does not exist.                                                  |
 | 42S02     | 10021       | Single table \`%s\` does not exist.                                            |
@@ -31,14 +32,14 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 44000     | 10102       | Storage units '%s' do not exist in database '%s'.                              |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.                                          |
 | 42S01     | 10104       | Duplicate storage unit names '%s'.                                             |
-| 08000     | 10105       | Storage units can not connect, error messages are: %s.                         |
-| 0A000     | 10106       | Can not alter connection info in storage units: '%s'.                          |
+| 08000     | 10110       | Storage units can not connect, error messages are: %s.                         |
+| 0A000     | 10111       | Can not alter connection info in storage units: '%s'.                          |
 | 44000     | 10120       | Invalid storage unit status, error message is: %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.                              |
-| 44000     | 10205       | Duplicate %s rule names '%s' in database '%s'.                                 |
-| 44000     | 10210       | There is no rule in database '%s'.                                             |
+| 42S02     | 10201       | There is no rule in database '%s'.                                             |
+| 42S02     | 10202       | %s rules '%s' do not exist in database '%s'.                                   |
+| 44000     | 10203       | %s rules '%s' in database '%s' are still in used.                              |
+| 42S01     | 10204       | Duplicate %s rule names '%s' in database '%s'.                                 |
 | 44000     | 10300       | Algorithm '%s.'%s' initialization failed, reason is: %s.                       |
 | 44000     | 10301       | '%s' algorithm on %s is required.                                              |
 | 42S02     | 10302       | '%s' algorithm '%s' on %s is unregistered.                                     |
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 1e59d9be03f..ca22a4e991c 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
@@ -20,6 +20,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | HY000     | 10005       | Column '%s' in %s is ambiguous.                                                |
 | 42S02     | 10006       | Unknown column '%s' in '%s'.                                                   |
 | 42S02     | 10007       | Table or view \`%s\` does not exist.                                           |
+| 42S02     | 10008       | Missing required table '%s' in storage unit '%s'.                              |
 | 42000     | 10010       | Rule does not exist.                                                           |
 | 42S02     | 10020       | Schema \`%s\` does not exist.                                                  |
 | 42S02     | 10021       | Single table \`%s\` does not exist.                                            |
@@ -31,13 +32,15 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 44000     | 10102       | Storage units '%s' do not exist in database '%s'.                              |
 | 44000     | 10103       | Storage unit '%s' still used by '%s'.                                          |
 | 42S01     | 10104       | Duplicate storage unit names '%s'.                                             |
-| 08000     | 10105       | Storage units can not connect, error messages are: %s.                         |
-| 0A000     | 10106       | Can not alter connection info in storage units: '%s'.                          |
+| 08000     | 10110       | Storage units can not connect, error messages are: %s.                         |
+| 0A000     | 10111       | Can not alter connection info in storage units: '%s'.                          |
 | 44000     | 10120       | Invalid storage unit status, error message is: %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.                              |
-| 44000     | 10205       | Duplicate %s rule names '%s' in database '%s'.                                 |
+| 44000     | 10200       | Invalid '%s' rule '%s', error message is: %s                                   |
+| 42S02     | 10201       | There is no rule in database '%s'.                                             |
+| 42S02     | 10202       | %s rules '%s' do not exist in database '%s'.                                   |
+| 44000     | 10203       | %s rules '%s' in database '%s' are still in used.                              |
+| 42S01     | 10204       | Duplicate %s rule names '%s' in database '%s'.                                 |
 | 44000     | 10210       | There is no rule in database '%s'.                                             |
 | 44000     | 10300       | Algorithm '%s.'%s' initialization failed, reason is: %s.                       |
 | 44000     | 10301       | '%s' algorithm on %s is required.                                              |
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
index 53b59165dfc..fc5c2887a40 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
 import lombok.Setter;
 import org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDropExecutor;
 import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException;
+import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException;
 import org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -72,7 +72,7 @@ public final class DropReadwriteSplittingRuleExecutor implements DatabaseRuleDro
     private void checkToBeDroppedInUsed(final DropReadwriteSplittingRuleStatement sqlStatement) {
         Collection<String> resourceBeUsed = getInUsedResources();
         Collection<String> ruleInUsed = sqlStatement.getNames().stream().filter(resourceBeUsed::contains).collect(Collectors.toSet());
-        ShardingSpherePreconditions.checkState(ruleInUsed.isEmpty(), () -> new RuleInUsedException("Readwrite-splitting", database.getName(), ruleInUsed));
+        ShardingSpherePreconditions.checkState(ruleInUsed.isEmpty(), () -> new InUsedRuleException("Readwrite-splitting", database.getName(), ruleInUsed));
     }
     
     private Collection<String> getInUsedResources() {
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java
index 05d8b93e1a9..996288d6643 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfigurat
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException;
 import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException;
+import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
 import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
@@ -88,7 +88,7 @@ class DropReadwriteSplittingRuleExecutorTest {
         executor.setDatabase(database);
         when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration());
         executor.setRule(rule);
-        assertThrows(RuleInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatement()));
+        assertThrows(InUsedRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement()));
     }
     
     @Test
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
index d880c6012fb..28126d82a58 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
@@ -22,7 +22,7 @@ import com.google.common.base.Splitter;
 import lombok.Setter;
 import org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDropExecutor;
 import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException;
+import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException;
 import org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
 import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -79,7 +79,7 @@ public final class DropShardingTableRuleExecutor implements DatabaseRuleDropExec
         Collection<String> bindingTables = getBindingTables();
         Collection<String> usedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(bindingTables::contains).collect(Collectors.toList());
         if (!usedTableNames.isEmpty()) {
-            throw new RuleInUsedException("Sharding", database.getName(), usedTableNames, "sharding table reference");
+            throw new InUsedRuleException("Sharding", database.getName(), usedTableNames, "sharding table reference");
         }
     }
     
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java
index 15d757af95c..41a0a7edba6 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.sharding.distsql.update;
 import com.google.common.base.Splitter;
 import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException;
 import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException;
-import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException;
+import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException;
 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;
@@ -83,7 +83,7 @@ class DropShardingTableRuleExecutorTest {
         ShardingRule rule = mock(ShardingRule.class);
         when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration());
         executor.setRule(rule);
-        assertThrows(RuleInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order_item")));
+        assertThrows(InUsedRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order_item")));
     }
     
     @Test
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java
index dc89551c2a8..eb2211441e0 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java
@@ -30,14 +30,14 @@ public final class DuplicateRuleException extends RuleDefinitionException {
     private static final long serialVersionUID = -1738699538105858939L;
     
     public DuplicateRuleException(final String ruleType, final String databaseName, final Collection<String> ruleNames) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate %s rule names '%s' in database '%s'.", ruleType, ruleNames, databaseName));
+        super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate %s rule names '%s' in database '%s'.", ruleType, ruleNames, databaseName));
     }
     
     public DuplicateRuleException(final String ruleType, final Collection<String> ruleNames) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate %s rule names '%s'.", ruleType, ruleNames));
+        super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate %s rule names '%s'.", ruleType, ruleNames));
     }
     
     public DuplicateRuleException(final String type, final String databaseName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate '%s' in database '%s'.", type, databaseName));
+        super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate '%s' in database '%s'.", type, databaseName));
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java
similarity index 80%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java
index 8d5d6a5543c..1b4a9b54c7d 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java
@@ -21,13 +21,13 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
 import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException;
 
 /**
- * Rule does not exist exception.
+ * Empty rule unit exception.
  */
-public final class RuleNotExistedException extends RuleDefinitionException {
+public final class EmptyRuleException extends RuleDefinitionException {
     
     private static final long serialVersionUID = -4150905802300104824L;
     
-    public RuleNotExistedException(final String databaseName) {
-        super(XOpenSQLState.SYNTAX_ERROR, 10, "There is no rule in database '%s'.", databaseName);
+    public EmptyRuleException(final String databaseName) {
+        super(XOpenSQLState.NOT_FOUND, 1, "There is no rule in database '%s'.", databaseName);
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java
similarity index 81%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java
index 804942f60ed..8862e2a10ca 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java
@@ -23,17 +23,17 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.c
 import java.util.Collection;
 
 /**
- * Rule in used exception.
+ * In used rule exception.
  */
-public final class RuleInUsedException extends RuleDefinitionException {
+public final class InUsedRuleException extends RuleDefinitionException {
     
     private static final long serialVersionUID = 3308787279125477660L;
     
-    public RuleInUsedException(final String ruleType, final String databaseName, final Collection<String> ruleNames) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "%s rules '%s' in database '%s' are still in used.", ruleType, ruleNames, databaseName);
+    public InUsedRuleException(final String ruleType, final String databaseName, final Collection<String> ruleNames) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "%s rules '%s' in database '%s' are still in used.", ruleType, ruleNames, databaseName);
     }
     
-    public RuleInUsedException(final String ruleType, final String databaseName, final Collection<String> ruleNames, final String usingType) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "%s rules '%s' in database '%s' are still in used by %s.", ruleType, ruleNames, databaseName, usingType);
+    public InUsedRuleException(final String ruleType, final String databaseName, final Collection<String> ruleNames, final String usingType) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "%s rules '%s' in database '%s' are still in used by %s.", ruleType, ruleNames, databaseName, usingType);
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java
index b1ac637ffa7..bda267b5094 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java
@@ -30,22 +30,22 @@ public final class MissingRequiredRuleException extends RuleDefinitionException
     private static final long serialVersionUID = -8464574460917965546L;
     
     public MissingRequiredRuleException(final String ruleType) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule does not exist.", ruleType);
+        super(XOpenSQLState.NOT_FOUND, 2, "%s rule does not exist.", ruleType);
     }
     
     public MissingRequiredRuleException(final String ruleType, final String databaseName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule does not exist in database '%s'.", ruleType, databaseName);
+        super(XOpenSQLState.NOT_FOUND, 2, "%s rule does not exist in database '%s'.", ruleType, databaseName);
     }
     
     public MissingRequiredRuleException(final String ruleType, final Collection<String> ruleNames) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rules '%s' do not exist.", ruleType, ruleNames);
+        super(XOpenSQLState.NOT_FOUND, 2, "%s rules '%s' do not exist.", ruleType, ruleNames);
     }
     
     public MissingRequiredRuleException(final String ruleType, final String databaseName, final String ruleName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule '%s' do not exist in database '%s'.", ruleType, ruleName, databaseName);
+        super(XOpenSQLState.NOT_FOUND, 2, "%s rule '%s' do not exist in database '%s'.", ruleType, ruleName, databaseName);
     }
     
     public MissingRequiredRuleException(final String ruleType, final String databaseName, final Collection<String> ruleNames) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rules '%s' do not exist in database '%s'.", ruleType, ruleNames, databaseName);
+        super(XOpenSQLState.NOT_FOUND, 1, "%s rules '%s' do not exist in database '%s'.", ruleType, ruleNames, databaseName);
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java
index a436a472512..4414abe8269 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java
@@ -30,6 +30,6 @@ public final class AlterStorageUnitConnectionInfoException extends ResourceDefin
     private static final long serialVersionUID = 525999625052706626L;
     
     public AlterStorageUnitConnectionInfoException(final Collection<String> storageUnitNames) {
-        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 6, "Can not alter connection info in storage units: '%s'.", String.join(", ", storageUnitNames));
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 11, "Can not alter connection info in storage units: '%s'.", String.join(", ", storageUnitNames));
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java
similarity index 87%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java
index 39ba29e8342..66e10013bf7 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java
@@ -25,11 +25,11 @@ import java.util.Collection;
 /**
  * Duplicate storage unit exception.
  */
-public final class DuplicateStorageUnitExceptionDefinition extends ResourceDefinitionException {
+public final class DuplicateStorageUnitException extends ResourceDefinitionException {
     
     private static final long serialVersionUID = 2103793827572264148L;
     
-    public DuplicateStorageUnitExceptionDefinition(final Collection<String> storageUnitNames) {
+    public DuplicateStorageUnitException(final Collection<String> storageUnitNames) {
         super(XOpenSQLState.DUPLICATE, 4, "Duplicate storage unit names '%s'.", String.join(", ", storageUnitNames));
     }
 }
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
index b7507c1473b..72e851f551f 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
@@ -31,7 +31,7 @@ public final class StorageUnitsConnectException extends ResourceDefinitionExcept
     private static final long serialVersionUID = 1824912697040264268L;
     
     public StorageUnitsConnectException(final Map<String, Exception> causes) {
-        super(XOpenSQLState.CONNECTION_EXCEPTION, 5, "Storage units can not connect, error messages are: %s.", causes.entrySet().stream().map(entry -> String.format(
+        super(XOpenSQLState.CONNECTION_EXCEPTION, 10, "Storage units can not connect, error messages are: %s.", causes.entrySet().stream().map(entry -> String.format(
                 "Storage unit name: '%s', error message is: %s", entry.getKey(), entry.getValue().getMessage())).collect(Collectors.joining(System.lineSeparator())));
     }
 }
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 8f881c0b91b..ec7d7650b25 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
@@ -34,7 +34,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.AlterStorageUnitConnectionInfoException;
-import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
+import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException;
 import org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException;
 import org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -80,7 +80,7 @@ public final class AlterStorageUnitExecutor implements DistSQLUpdateExecutor<Alt
     
     private void checkDuplicatedStorageUnitNames(final Collection<String> storageUnitNames) {
         Collection<String> duplicatedStorageUnitNames = storageUnitNames.stream().filter(each -> storageUnitNames.stream().filter(each::equals).count() > 1).collect(Collectors.toList());
-        ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedStorageUnitNames));
+        ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedStorageUnitNames));
     }
     
     private void checkStorageUnitNameExisted(final Collection<String> storageUnitNames) {
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 cf8e568fdcc..09b8d65bece 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
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.Regist
 import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
 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.DuplicateStorageUnitException;
 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;
@@ -89,7 +89,7 @@ public final class RegisterStorageUnitExecutor implements DistSQLUpdateExecutor<
             }
             dataSourceNames.add(each.getName());
         }
-        ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedDataSourceNames));
+        ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames));
     }
     
     private void checkDuplicatedLogicalDataSourceNames(final Collection<String> requiredDataSourceNames) {
@@ -98,7 +98,7 @@ public final class RegisterStorageUnitExecutor implements DistSQLUpdateExecutor<
             return;
         }
         Collection<String> duplicatedDataSourceNames = requiredDataSourceNames.stream().filter(logicalDataSourceNames::contains).collect(Collectors.toSet());
-        ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedDataSourceNames));
+        ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames));
     }
     
     private Collection<String> getCurrentStorageUnitNames(final ContextManager contextManager) {
diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
index 9064965753d..7bc32bc10c7 100644
--- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
+++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.segment.URLBasedDataSourceSegment;
 import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.AlterStorageUnitStatement;
 import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
 import org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException;
-import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
+import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException;
 import org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
@@ -75,7 +75,7 @@ class AlterStorageUnitExecutorTest {
     
     @Test
     void assertExecuteUpdateWithDuplicateStorageUnitNames() {
-        assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createAlterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class)));
+        assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createAlterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class)));
     }
     
     @Test
diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
index 666f8e2f92a..e0900a347b4 100644
--- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
+++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolP
 import org.apache.shardingsphere.distsql.segment.HostnameAndPortBasedDataSourceSegment;
 import org.apache.shardingsphere.distsql.segment.URLBasedDataSourceSegment;
 import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.RegisterStorageUnitStatement;
-import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
+import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
@@ -70,14 +70,14 @@ class RegisterStorageUnitExecutorTest {
     
     @Test
     void assertExecuteUpdateWithDuplicateStorageUnitNamesInStatement() {
-        assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class)));
+        assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class)));
     }
     
     @Test
     void assertExecuteUpdateWithDuplicateStorageUnitNamesWithResourceMetaData() {
         ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         when(contextManager.getStorageUnits("foo_db").keySet()).thenReturn(Collections.singleton("ds_0"));
-        assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
+        assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
     }
     
     @Test
@@ -87,7 +87,7 @@ class RegisterStorageUnitExecutorTest {
         DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class);
         when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0", Collections.emptyList()));
         when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
-        assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
+        assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
     }
     
     private RegisterStorageUnitStatement createRegisterStorageUnitStatement() {
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
index 97d167e40ce..425e8bd6686 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java
@@ -18,16 +18,16 @@
 package org.apache.shardingsphere.single.distsql.handler.exception;
 
 import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException;
+import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
 
 /**
  * Missing required single table exception.
  */
-public final class MissingRequiredSingleTableException extends RuleDefinitionException {
+public final class MissingRequiredSingleTableException extends MetaDataSQLException {
     
     private static final long serialVersionUID = 3155006580453893122L;
     
     public MissingRequiredSingleTableException(final String storageUnitName, final String tableName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 6, "Missing required table '%s' in storage unit '%s'.", tableName, storageUnitName);
+        super(XOpenSQLState.NOT_FOUND, 8, "Missing required table '%s' in storage unit '%s'.", tableName, storageUnitName);
     }
 }
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
index d1b6c6405ff..59f752acb42 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
@@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.connection.refresher.MetaDataRefreshEngin
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine;
-import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.EmptyRuleException;
 import org.apache.shardingsphere.infra.exception.storageunit.EmptyStorageUnitException;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
 import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
@@ -132,7 +132,7 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
         boolean isSystemSchema = SystemSchemaUtils.containsSystemSchema(sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), database);
         ShardingSpherePreconditions.checkState(isSystemSchema || database.containsDataSource(), () -> new EmptyStorageUnitException(connectionSession.getDatabaseName()));
         if (!isSystemSchema && !database.isComplete()) {
-            throw new RuleNotExistedException(connectionSession.getDatabaseName());
+            throw new EmptyRuleException(connectionSession.getDatabaseName());
         }
     }
     
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
index 2acbcff77b1..c723b682e2c 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnection
 import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
 import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
-import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException;
+import org.apache.shardingsphere.infra.exception.rule.EmptyRuleException;
 import org.apache.shardingsphere.distsql.statement.rul.sql.PreviewStatement;
 import org.apache.shardingsphere.infra.binder.context.aware.CursorDefinitionAware;
 import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
@@ -97,7 +97,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem
         if (toBePreviewedStatementContext instanceof CursorAvailable && toBePreviewedStatementContext instanceof CursorDefinitionAware) {
             setUpCursorDefinition(toBePreviewedStatementContext);
         }
-        ShardingSpherePreconditions.checkState(database.isComplete(), () -> new RuleNotExistedException(database.getName()));
+        ShardingSpherePreconditions.checkState(database.isComplete(), () -> new EmptyRuleException(database.getName()));
         String schemaName = queryContext.getSqlStatementContext().getTablesContext().getSchemaName()
                 .orElseGet(() -> new DatabaseTypeRegistry(database.getProtocolType()).getDefaultSchemaName(database.getName()));
         Collection<ExecutionUnit> executionUnits = getExecutionUnits(contextManager, schemaName, metaData, queryContext);