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

duanzhengqiang 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 ba3b3945e63 Add DBDiscoveryProviderException and 
DBDiscoverySQLException (#23403)
ba3b3945e63 is described below

commit ba3b3945e6339a4f7fe0123c6508f89a5eb9256f
Author: zhaojinchao <[email protected]>
AuthorDate: Sun Jan 8 15:52:54 2023 +0800

    Add DBDiscoveryProviderException and DBDiscoverySQLException (#23403)
---
 .../exception/DBDiscoveryProviderException.java}           |  8 ++++----
 .../checker/DatabaseDiscoveryRuleConfigurationChecker.java |  6 ++++--
 .../DBDiscoveryDataSourceRuleNotFoundException.java}       | 13 ++++++-------
 .../dbdiscovery}/exception/DBDiscoverySQLException.java    |  4 ++--
 .../MissingRequiredDBDiscoveryConfigurationException.java} | 13 ++++++-------
 ...singRequiredDataSourceNamesConfigurationException.java} | 13 ++++++-------
 .../MissingRequiredGroupNameConfigurationException.java}   | 13 ++++++-------
 .../dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java  |  7 ++++++-
 .../dbdiscovery/rule/DatabaseDiscoveryRule.java            |  6 ++++--
 .../DatabaseDiscoveryRuleConfigurationCheckerTest.java     |  3 ++-
 .../rule/DatabaseDiscoveryDataSourceRuleTest.java          |  5 +++--
 .../mgr/InvalidMGRGroupNameConfigurationException.java     |  4 ++--
 .../mysql/exception/mgr/InvalidMGRModeException.java       |  4 ++--
 .../mysql/exception/mgr/InvalidMGRPluginException.java     |  4 ++--
 .../mgr/InvalidMGRReplicationGroupMemberException.java     |  4 ++--
 .../DuplicatePrimaryDataSourceException.java}              | 14 +++++++-------
 ...ormalReplicationDatabaseDiscoveryProviderAlgorithm.java |  5 +++--
 17 files changed, 67 insertions(+), 59 deletions(-)

diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
 
b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java
similarity index 79%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
copy to 
features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java
index 89019d8e3e0..9a8bae8738b 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
+++ 
b/features/db-discovery/api/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryProviderException.java
@@ -15,21 +15,21 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.SQLState;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
 
 /**
- * Database discovery SQL exception.
+ * Database discovery provider exception.
  */
-public abstract class DBDiscoverySQLException extends FeatureSQLException {
+public abstract class DBDiscoveryProviderException extends FeatureSQLException 
{
     
     private static final long serialVersionUID = 2693931450412858590L;
     
     private static final int FEATURE_CODE = 3;
     
-    public DBDiscoverySQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Object... messageArgs) {
+    public DBDiscoveryProviderException(final SQLState sqlState, final int 
errorCode, final String reason, final Object... messageArgs) {
         super(sqlState, FEATURE_CODE, errorCode, reason, messageArgs);
     }
 }
diff --git 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
index 09824ffc9bc..5092c66e1df 100644
--- 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationChecker.java
@@ -17,11 +17,12 @@
 
 package org.apache.shardingsphere.dbdiscovery.checker;
 
-import com.google.common.base.Preconditions;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
 import org.apache.shardingsphere.dbdiscovery.constant.DatabaseDiscoveryOrder;
+import 
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDBDiscoveryConfigurationException;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -34,7 +35,8 @@ public final class DatabaseDiscoveryRuleConfigurationChecker 
implements RuleConf
     
     @Override
     public void check(final String databaseName, final 
DatabaseDiscoveryRuleConfiguration config, final Map<String, DataSource> 
dataSourceMap, final Collection<ShardingSphereRule> rules) {
-        config.getDataSources().forEach(each -> 
Preconditions.checkState(!each.getDiscoveryTypeName().isEmpty(), "No available 
database discovery rule configuration in database `%s.", databaseName));
+        config.getDataSources().forEach(each -> 
ShardingSpherePreconditions.checkState(!each.getDiscoveryTypeName().isEmpty(),
+                () -> new 
MissingRequiredDBDiscoveryConfigurationException(databaseName)));
     }
     
     @Override
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java
similarity index 64%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
copy to 
features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java
index 943ae8aedfa..abdfdb9e021 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoveryDataSourceRuleNotFoundException.java
@@ -15,19 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid MGR plugin exception.
+ * Database discovery data source rule not found exception.
  */
-public final class InvalidMGRPluginException extends DBDiscoverySQLException {
+public final class DBDiscoveryDataSourceRuleNotFoundException extends 
DBDiscoverySQLException {
     
-    private static final long serialVersionUID = 1703082683321097037L;
+    private static final long serialVersionUID = -851752979377324961L;
     
-    public InvalidMGRPluginException(final String databaseName) {
-        super(XOpenSQLState.GENERAL_ERROR, 80, "MGR plugin is not active in 
database `%s`.", databaseName);
+    public DBDiscoveryDataSourceRuleNotFoundException(final String 
databaseName) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "Can not found database 
discovery data source rule in database `%s`", databaseName);
     }
 }
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java
similarity index 91%
rename from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
rename to 
features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java
index 89019d8e3e0..4a748df5ddd 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/DBDiscoverySQLException.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/DBDiscoverySQLException.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.SQLState;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
@@ -25,7 +25,7 @@ import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.
  */
 public abstract class DBDiscoverySQLException extends FeatureSQLException {
     
-    private static final long serialVersionUID = 2693931450412858590L;
+    private static final long serialVersionUID = 5210719217645611897L;
     
     private static final int FEATURE_CODE = 3;
     
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java
similarity index 63%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
copy to 
features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java
index 943ae8aedfa..0867b41a2a0 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDBDiscoveryConfigurationException.java
@@ -15,19 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid MGR plugin exception.
+ * Missing required database discovery configuration exception.
  */
-public final class InvalidMGRPluginException extends DBDiscoverySQLException {
+public final class MissingRequiredDBDiscoveryConfigurationException extends 
DBDiscoverySQLException {
     
-    private static final long serialVersionUID = 1703082683321097037L;
+    private static final long serialVersionUID = -7743963772524386090L;
     
-    public InvalidMGRPluginException(final String databaseName) {
-        super(XOpenSQLState.GENERAL_ERROR, 80, "MGR plugin is not active in 
database `%s`.", databaseName);
+    public MissingRequiredDBDiscoveryConfigurationException(final String 
databaseName) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "No available database 
discovery rule configuration in database `%s.", databaseName);
     }
 }
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java
similarity index 64%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
copy to 
features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java
index 943ae8aedfa..bd99c39624b 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredDataSourceNamesConfigurationException.java
@@ -15,19 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid MGR plugin exception.
+ * Missing required data source names configuration exception.
  */
-public final class InvalidMGRPluginException extends DBDiscoverySQLException {
+public final class MissingRequiredDataSourceNamesConfigurationException 
extends DBDiscoverySQLException {
     
-    private static final long serialVersionUID = 1703082683321097037L;
+    private static final long serialVersionUID = -3591914080387845399L;
     
-    public InvalidMGRPluginException(final String databaseName) {
-        super(XOpenSQLState.GENERAL_ERROR, 80, "MGR plugin is not active in 
database `%s`.", databaseName);
+    public MissingRequiredDataSourceNamesConfigurationException() {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "Data source names are 
required.");
     }
 }
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java
similarity index 64%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
copy to 
features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java
index 943ae8aedfa..e2b8ea39433 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/exception/MissingRequiredGroupNameConfigurationException.java
@@ -15,19 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
+package org.apache.shardingsphere.dbdiscovery.exception;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid MGR plugin exception.
+ * Missing required group name configuration exception.
  */
-public final class InvalidMGRPluginException extends DBDiscoverySQLException {
+public final class MissingRequiredGroupNameConfigurationException extends 
DBDiscoverySQLException {
     
-    private static final long serialVersionUID = 1703082683321097037L;
+    private static final long serialVersionUID = -3591914080387845399L;
     
-    public InvalidMGRPluginException(final String databaseName) {
-        super(XOpenSQLState.GENERAL_ERROR, 80, "MGR plugin is not active in 
database `%s`.", databaseName);
+    public MissingRequiredGroupNameConfigurationException() {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "Group name is 
required");
     }
 }
diff --git 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
index 1f43c2d29ea..c02c6c52844 100644
--- 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
@@ -21,7 +21,10 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import lombok.Getter;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredGroupNameConfigurationException;
 import 
org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -63,7 +66,9 @@ public final class DatabaseDiscoveryDataSourceRule {
     
     private void checkConfiguration(final 
DatabaseDiscoveryDataSourceRuleConfiguration config) {
         
Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getGroupName()), 
"Group name is required.");
-        Preconditions.checkArgument(null != config.getDataSourceNames() && 
!config.getDataSourceNames().isEmpty(), "Data source names are required.");
+        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(config.getGroupName()),
 MissingRequiredGroupNameConfigurationException::new);
+        ShardingSpherePreconditions.checkState(null != 
config.getDataSourceNames()
+                && !config.getDataSourceNames().isEmpty(), 
MissingRequiredDataSourceNamesConfigurationException::new);
     }
     
     /**
diff --git 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 56418c75861..9b2fe053cdc 100644
--- 
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ 
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.dbdiscovery.algorithm.DatabaseDiscoveryEngine;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryDataSourceRuleNotFoundException;
 import org.apache.shardingsphere.dbdiscovery.heartbeat.HeartbeatJob;
 import 
org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
@@ -39,6 +40,7 @@ import 
org.apache.shardingsphere.infra.rule.identifier.type.exportable.Exportabl
 import 
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
 import org.apache.shardingsphere.infra.schedule.CronJob;
 import org.apache.shardingsphere.infra.schedule.ScheduleContext;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.mode.metadata.storage.StorageNodeStatus;
 import 
org.apache.shardingsphere.mode.metadata.storage.event.PrimaryDataSourceChangedEvent;
 import 
org.apache.shardingsphere.mode.metadata.storage.event.StorageNodeDataSourceChangedEvent;
@@ -150,7 +152,7 @@ public final class DatabaseDiscoveryRule implements 
DatabaseRule, DataSourceCont
         PrimaryDataSourceChangedEvent dataSourceEvent = 
(PrimaryDataSourceChangedEvent) event;
         QualifiedDatabase qualifiedDatabase = 
dataSourceEvent.getQualifiedDatabase();
         DatabaseDiscoveryDataSourceRule dataSourceRule = 
dataSourceRules.get(qualifiedDatabase.getGroupName());
-        Preconditions.checkNotNull(dataSourceRule, "Can not find database 
discovery data source rule in database `%s`", databaseName);
+        ShardingSpherePreconditions.checkNotNull(dataSourceRule, () -> new 
DBDiscoveryDataSourceRuleNotFoundException(databaseName));
         
dataSourceRule.changePrimaryDataSourceName(qualifiedDatabase.getDataSourceName());
         initHeartBeatJobs();
     }
@@ -158,7 +160,7 @@ public final class DatabaseDiscoveryRule implements 
DatabaseRule, DataSourceCont
     @Override
     public void closeSingleHeartBeatJob(final String groupName) {
         DatabaseDiscoveryDataSourceRule dataSourceRule = 
dataSourceRules.get(groupName);
-        Preconditions.checkNotNull(dataSourceRule, "Can not find database 
discovery data source rule in database `%s`", databaseName);
+        ShardingSpherePreconditions.checkNotNull(dataSourceRule, () -> new 
DBDiscoveryDataSourceRuleNotFoundException(databaseName));
         
scheduleContext.closeSchedule(dataSourceRule.getDatabaseDiscoveryProviderAlgorithm().getType()
 + "-" + databaseName + "-" + dataSourceRule.getGroupName());
     }
     
diff --git 
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
 
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
index 935a1d929d6..58ac98ca9d6 100644
--- 
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
+++ 
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/checker/DatabaseDiscoveryRuleConfigurationCheckerTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.dbdiscovery.checker;
 
 import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDBDiscoveryConfigurationException;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
 import 
org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPIRegistry;
 import org.junit.Test;
@@ -47,7 +48,7 @@ public final class 
DatabaseDiscoveryRuleConfigurationCheckerTest {
     }
     
     @SuppressWarnings({"rawtypes", "unchecked"})
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = MissingRequiredDBDiscoveryConfigurationException.class)
     public void assertInvalidCheck() {
         DatabaseDiscoveryRuleConfiguration config = getInvalidConfiguration();
         RuleConfigurationChecker checker = 
OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class, 
Collections.singleton(config.getClass())).get(config.getClass());
diff --git 
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
 
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
index 7469aaf8eb4..96f88a6a66e 100644
--- 
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
+++ 
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.dbdiscovery.rule;
 
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
 import 
org.apache.shardingsphere.dbdiscovery.mysql.type.MGRMySQLDatabaseDiscoveryProviderAlgorithm;
 import org.junit.Test;
 
@@ -41,13 +42,13 @@ public final class DatabaseDiscoveryDataSourceRuleTest {
                 new Properties(), new 
MGRMySQLDatabaseDiscoveryProviderAlgorithm());
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = 
MissingRequiredDataSourceNamesConfigurationException.class)
     public void assertNewHADataSourceRuleWithNullDataSourceName() {
         new DatabaseDiscoveryDataSourceRule(new 
DatabaseDiscoveryDataSourceRuleConfiguration("ds", null, "ha_heartbeat", 
"discoveryTypeName"),
                 new Properties(), new 
MGRMySQLDatabaseDiscoveryProviderAlgorithm());
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = 
MissingRequiredDataSourceNamesConfigurationException.class)
     public void assertNewHADataSourceRuleWithEmptyDataSourceName() {
         new DatabaseDiscoveryDataSourceRule(new 
DatabaseDiscoveryDataSourceRuleConfiguration("ds", Collections.emptyList(), 
"ha_heartbeat", "discoveryTypeName"),
                 new Properties(), new 
MGRMySQLDatabaseDiscoveryProviderAlgorithm());
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
index b5ea707c299..a0a3b2e16ec 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRGroupNameConfigurationException.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
  * Invalid MGR group name configuration exception.
  */
-public final class InvalidMGRGroupNameConfigurationException extends 
DBDiscoverySQLException {
+public final class InvalidMGRGroupNameConfigurationException extends 
DBDiscoveryProviderException {
     
     private static final long serialVersionUID = -2585442998454509788L;
     
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
index 99fe64a8c1a..eccae20791a 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
  * Invalid MGR mode exception.
  */
-public final class InvalidMGRModeException extends DBDiscoverySQLException {
+public final class InvalidMGRModeException extends 
DBDiscoveryProviderException {
     
     private static final long serialVersionUID = -2190741601319220590L;
     
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
index 943ae8aedfa..345c5cb2297 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRPluginException.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
  * Invalid MGR plugin exception.
  */
-public final class InvalidMGRPluginException extends DBDiscoverySQLException {
+public final class InvalidMGRPluginException extends 
DBDiscoveryProviderException {
     
     private static final long serialVersionUID = 1703082683321097037L;
     
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
index 48fa6e52efd..51fc450984a 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRReplicationGroupMemberException.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
  * Invalid MGR replication group member exception.
  */
-public final class InvalidMGRReplicationGroupMemberException extends 
DBDiscoverySQLException {
+public final class InvalidMGRReplicationGroupMemberException extends 
DBDiscoveryProviderException {
     
     private static final long serialVersionUID = 3766206496827463146L;
     
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java
similarity index 64%
copy from 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
copy to 
features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java
index 99fe64a8c1a..a34295c9ae9 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/mgr/InvalidMGRModeException.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/replica/DuplicatePrimaryDataSourceException.java
@@ -15,19 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.dbdiscovery.mysql.exception.mgr;
+package org.apache.shardingsphere.dbdiscovery.mysql.exception.replica;
 
-import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.DBDiscoverySQLException;
+import 
org.apache.shardingsphere.dbdiscovery.exception.DBDiscoveryProviderException;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid MGR mode exception.
+ * Duplicate primary data source exception.
  */
-public final class InvalidMGRModeException extends DBDiscoverySQLException {
+public final class DuplicatePrimaryDataSourceException extends 
DBDiscoveryProviderException {
     
-    private static final long serialVersionUID = -2190741601319220590L;
+    private static final long serialVersionUID = -7715117257616134436L;
     
-    public InvalidMGRModeException(final String databaseName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 81, "MGR is not in single 
primary mode in database `%s`.", databaseName);
+    public DuplicatePrimaryDataSourceException(final String databaseName) {
+        super(XOpenSQLState.DUPLICATE, 90, "Duplicate primary data source in 
database `%s`..", databaseName);
     }
 }
diff --git 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
index a084db9aaa9..d561182baf3 100644
--- 
a/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
+++ 
b/features/db-discovery/provider/mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
@@ -17,12 +17,13 @@
 
 package org.apache.shardingsphere.dbdiscovery.mysql.type;
 
-import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import lombok.Getter;
+import 
org.apache.shardingsphere.dbdiscovery.mysql.exception.replica.DuplicatePrimaryDataSourceException;
 import 
org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
 import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
 import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException;
 
 import javax.sql.DataSource;
@@ -71,7 +72,7 @@ public final class 
MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm impl
                 primaryCount++;
             }
         }
-        Preconditions.checkState(1 == primaryCount, "Check Environment are 
failed in database `%s`.", databaseName);
+        ShardingSpherePreconditions.checkState(1 == primaryCount, () -> new 
DuplicatePrimaryDataSourceException(databaseName));
     }
     
     private CompletableFuture<Boolean> supplyAsyncCheckEnvironment(final 
DataSource dataSource, final ExecutorService executorService) {


Reply via email to