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

panjuan 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 5279ba1  Add alter & drop database discovery rule backend handler 
(#10386)
5279ba1 is described below

commit 5279ba1fa5316307f3a4e8e5ef4fb8c39b8ee1d6
Author: Haoran Meng <[email protected]>
AuthorDate: Wed May 19 17:00:53 2021 +0800

    Add alter & drop database discovery rule backend handler (#10386)
    
    * Add alter & drop database discovery rule backend handler
    
    * Add alter & drop database discovery rule backend handler
    
    Co-authored-by: menghaoranss <[email protected]>
---
 .../db/protocol/error/CommonErrorCode.java         |   4 +
 ...iscoveryRuleDataSourcesNotExistedException.java |  35 +++++
 .../DatabaseDiscoveryRuleNotExistedException.java  |  33 +++++
 .../text/distsql/rdl/RDLBackendHandlerFactory.java |  12 +-
 .../AlterDatabaseDiscoveryRuleBackendHandler.java  | 127 ++++++++++++++++
 .../DropDatabaseDiscoveryRuleBackendHandler.java   |  86 +++++++++++
 ...terDatabaseDiscoveryRuleBackendHandlerTest.java | 164 +++++++++++++++++++++
 ...ropDatabaseDiscoveryRuleBackendHandlerTest.java | 114 ++++++++++++++
 .../frontend/mysql/err/MySQLErrPacketFactory.java  |   8 +
 9 files changed, 582 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
index 26a0d8a..d7ab5fa 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
@@ -67,6 +67,10 @@ public enum CommonErrorCode implements SQLErrorCode {
 
     INVALID_DATABASE_DISCOVERY_TYPES(1119, "C1119", "Invalid database 
discovery types %s."),
 
+    DATABASE_DISCOVERY_RULE_NOT_EXIST(1120, "C1120", "Database discovery rule 
not exist in schema %s."),
+
+    DATABASE_DISCOVERY_RULE_DATASOURCE_NOT_EXIST(1121, "C1121", "Database 
discovery rules %s do not exist."),
+
     SCALING_JOB_NOT_EXIST(1201, "C1201", "Scaling job %s does not exist."),
     
     SCALING_OPERATE_FAILED(1209, "C1209", "Scaling Operate Failed: [%s]"),
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleDataSourcesNotExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleDataSourcesNotExistedException.java
new file mode 100644
index 0000000..4585552
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleDataSourcesNotExistedException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.proxy.backend.exception;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+import java.util.Collection;
+
+/**
+ * Database discovery rule data sources not existed exception.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DatabaseDiscoveryRuleDataSourcesNotExistedException extends 
BackendException {
+
+    private static final long serialVersionUID = -5200865025455932005L;
+
+    private final Collection<String> ruleNames;
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleNotExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleNotExistedException.java
new file mode 100644
index 0000000..c726a4d
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseDiscoveryRuleNotExistedException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.proxy.backend.exception;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Database discovery rule not existed exception.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DatabaseDiscoveryRuleNotExistedException extends 
BackendException {
+
+    private static final long serialVersionUID = 1293361372683913161L;
+
+    private final String schemaName;
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
index 497b644..ae8b14d 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterDatabaseDiscoveryRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterReadwriteSplittingRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterShardingBindingTableRulesStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterShardingBroadcastTableRulesStatement;
@@ -29,6 +30,7 @@ import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.Create
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingBindingTableRulesStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingBroadcastTableRulesStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingTableRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropDatabaseDiscoveryRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropReadwriteSplittingRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropResourceStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropShardingBindingTableRulesStatement;
@@ -40,6 +42,7 @@ import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AddResourceBackendHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AlterDatabaseDiscoveryRuleBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AlterReadwriteSplittingRuleBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AlterShardingBindingTableRulesBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.AlterShardingBroadcastTableRulesBackendHandler;
@@ -51,6 +54,7 @@ import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.CreateShard
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.CreateShardingBroadcastTableRulesBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.CreateShardingTableRuleBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropDatabaseBackendHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropDatabaseDiscoveryRuleBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropReadwriteSplittingRuleBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropResourceBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.DropShardingBindingTableRulesBackendHandler;
@@ -91,7 +95,7 @@ public final class RDLBackendHandlerFactory {
             throw new SQLException(String.format("No Registry center to 
execute `%s` SQL", sqlStatement.getClass().getSimpleName()));
         }
     }
-    
+
     private static Optional<TextProtocolBackendHandler> 
createRDLBackendHandler(final DatabaseType databaseType, final SQLStatement 
sqlStatement, final BackendConnection backendConnection) {
         if (sqlStatement instanceof AddResourceStatement) {
             return Optional.of(new AddResourceBackendHandler(databaseType, 
(AddResourceStatement) sqlStatement, backendConnection));
@@ -147,6 +151,12 @@ public final class RDLBackendHandlerFactory {
         if (sqlStatement instanceof CreateDatabaseDiscoveryRuleStatement) {
             return Optional.of(new 
CreateDatabaseDiscoveryRuleBackendHandler((CreateDatabaseDiscoveryRuleStatement)
 sqlStatement, backendConnection));
         }
+        if (sqlStatement instanceof AlterDatabaseDiscoveryRuleStatement) {
+            return Optional.of(new 
AlterDatabaseDiscoveryRuleBackendHandler((AlterDatabaseDiscoveryRuleStatement) 
sqlStatement, backendConnection));
+        }
+        if (sqlStatement instanceof DropDatabaseDiscoveryRuleStatement) {
+            return Optional.of(new 
DropDatabaseDiscoveryRuleBackendHandler((DropDatabaseDiscoveryRuleStatement) 
sqlStatement, backendConnection));
+        }
         return Optional.empty();
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
new file mode 100644
index 0000000..40fde43
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandler.java
@@ -0,0 +1,127 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl;
+
+import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.common.yaml.converter.DatabaseDiscoveryRuleStatementConverter;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
+import 
org.apache.shardingsphere.distsql.parser.segment.rdl.DatabaseDiscoveryRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
+import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleDataSourcesNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Alter database discovery rule backend handler.
+ */
+public final class AlterDatabaseDiscoveryRuleBackendHandler extends 
SchemaRequiredBackendHandler<AlterDatabaseDiscoveryRuleStatement> {
+
+    public AlterDatabaseDiscoveryRuleBackendHandler(final 
AlterDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection 
backendConnection) {
+        super(sqlStatement, backendConnection);
+    }
+    
+    @Override
+    public ResponseHeader execute(final String schemaName, final 
AlterDatabaseDiscoveryRuleStatement statement) {
+        Optional<DatabaseDiscoveryRuleConfiguration> ruleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
+                .filter(each -> each instanceof 
DatabaseDiscoveryRuleConfiguration).map(each -> 
(DatabaseDiscoveryRuleConfiguration) each).findFirst();
+        if (!ruleConfig.isPresent()) {
+            throw new DatabaseDiscoveryRuleNotExistedException(schemaName);
+        }
+        check(schemaName, statement, ruleConfig.get());
+        YamlDatabaseDiscoveryRuleConfiguration config = 
alter(ruleConfig.get(), statement);
+        Collection<RuleConfiguration> rules = new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(config));
+        post(schemaName, rules);
+        return new UpdateResponseHeader(statement);
+    }
+    
+    private void check(final String schemaName, final 
AlterDatabaseDiscoveryRuleStatement sqlStatement, final 
DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration) {
+        checkAlteredDataSources(databaseDiscoveryRuleConfiguration, 
sqlStatement);
+        checkResources(schemaName, sqlStatement);
+        checkDiscoveryType(sqlStatement);
+    }
+
+    private void checkAlteredDataSources(final 
DatabaseDiscoveryRuleConfiguration ruleConfig, final 
AlterDatabaseDiscoveryRuleStatement statement) {
+        Set<String> existDataSourceNames = 
ruleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
+        Collection<String> notExistDataSourceNames = 
statement.getDatabaseDiscoveryRules().stream().map(DatabaseDiscoveryRuleSegment::getName)
+                .filter(each -> 
!existDataSourceNames.contains(each)).collect(Collectors.toList());
+        if (!notExistDataSourceNames.isEmpty()) {
+            throw new 
DatabaseDiscoveryRuleDataSourcesNotExistedException(notExistDataSourceNames);
+        }
+    }
+
+    private void checkResources(final String schemaName, final 
AlterDatabaseDiscoveryRuleStatement statement) {
+        Collection<String> resources = new LinkedHashSet<>();
+        statement.getDatabaseDiscoveryRules().forEach(each -> 
resources.addAll(each.getDataSources()));
+        Collection<String> notExistResources = resources.stream().filter(each 
-> !this.isValidResource(schemaName, each)).collect(Collectors.toList());
+        if (!notExistResources.isEmpty()) {
+            throw new ResourceNotExistedException(notExistResources);
+        }
+    }
+
+    private void checkDiscoveryType(final AlterDatabaseDiscoveryRuleStatement 
statement) {
+        Collection<String> invalidDiscoveryTypes = 
statement.getDatabaseDiscoveryRules().stream().map(each -> 
each.getDiscoveryTypeName()).distinct()
+                .filter(each -> 
!TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, each, new 
Properties()).isPresent())
+                .collect(Collectors.toList());
+        if (!invalidDiscoveryTypes.isEmpty()) {
+            throw new 
InvalidDatabaseDiscoveryTypesException(invalidDiscoveryTypes);
+        }
+    }
+
+    private boolean isValidResource(final String schemaName, final String 
resourceName) {
+        return 
Objects.nonNull(ProxyContext.getInstance().getMetaData(schemaName).getResource())
+                && 
ProxyContext.getInstance().getMetaData(schemaName).getResource().getDataSources().containsKey(resourceName);
+    }
+
+    private YamlDatabaseDiscoveryRuleConfiguration alter(final 
DatabaseDiscoveryRuleConfiguration ruleConfig, final 
AlterDatabaseDiscoveryRuleStatement statement) {
+        YamlDatabaseDiscoveryRuleConfiguration 
alterYamlDatabaseDiscoveryRuleConfiguration = 
DatabaseDiscoveryRuleStatementConverter.convert(statement.getDatabaseDiscoveryRules());
+        YamlDatabaseDiscoveryRuleConfiguration result = new 
YamlRuleConfigurationSwapperEngine()
+                
.swapToYamlRuleConfigurations(Collections.singletonList(ruleConfig)).stream()
+                .map(each -> (YamlDatabaseDiscoveryRuleConfiguration) 
each).findFirst().get();
+        alterYamlDatabaseDiscoveryRuleConfiguration.getDataSources().keySet()
+                .forEach(each -> 
result.getDiscoveryTypes().remove(result.getDataSources().get(each).getDiscoveryTypeName()));
+        
result.getDataSources().putAll(alterYamlDatabaseDiscoveryRuleConfiguration.getDataSources());
+        
result.getDiscoveryTypes().putAll(alterYamlDatabaseDiscoveryRuleConfiguration.getDiscoveryTypes());
+        return result;
+    }
+
+    private void post(final String schemaName, final 
Collection<RuleConfiguration> rules) {
+        ShardingSphereEventBus.getInstance().post(new 
RuleConfigurationsAlteredEvent(schemaName, rules));
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
new file mode 100644
index 0000000..6ae6972
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandler.java
@@ -0,0 +1,86 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl;
+
+import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.common.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleDataSourcesNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Drop database discovery rule backend handler.
+ */
+public final class DropDatabaseDiscoveryRuleBackendHandler extends 
SchemaRequiredBackendHandler<DropDatabaseDiscoveryRuleStatement> {
+
+    public DropDatabaseDiscoveryRuleBackendHandler(final 
DropDatabaseDiscoveryRuleStatement sqlStatement, final BackendConnection 
backendConnection) {
+        super(sqlStatement, backendConnection);
+    }
+    
+    @Override
+    public ResponseHeader execute(final String schemaName, final 
DropDatabaseDiscoveryRuleStatement sqlStatement) {
+        Optional<DatabaseDiscoveryRuleConfiguration> ruleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
+                .filter(each -> each instanceof 
DatabaseDiscoveryRuleConfiguration).map(each -> 
(DatabaseDiscoveryRuleConfiguration) each).findFirst();
+        if (!ruleConfig.isPresent()) {
+            throw new DatabaseDiscoveryRuleNotExistedException(schemaName);
+        }
+        check(ruleConfig.get(), sqlStatement);
+        YamlDatabaseDiscoveryRuleConfiguration yamlConfig = new 
YamlRuleConfigurationSwapperEngine()
+                
.swapToYamlRuleConfigurations(Collections.singletonList(ruleConfig.get())).stream()
+                .map(each -> (YamlDatabaseDiscoveryRuleConfiguration) 
each).findFirst().get();
+        drop(yamlConfig, sqlStatement);
+        post(schemaName, new YamlRuleConfigurationSwapperEngine()
+                
.swapToRuleConfigurations(yamlConfig.getDataSources().isEmpty() ? 
Collections.emptyList() : Collections.singletonList(yamlConfig)));
+        return new UpdateResponseHeader(sqlStatement);
+    }
+    
+    private void check(final DatabaseDiscoveryRuleConfiguration ruleConfig, 
final DropDatabaseDiscoveryRuleStatement sqlStatement) {
+        Collection<String> databaseDiscoveryDataSourceNames = 
ruleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+        Collection<String> notExistedRuleNames = 
sqlStatement.getRuleNames().stream().filter(each -> 
!databaseDiscoveryDataSourceNames.contains(each)).collect(Collectors.toList());
+        if (!notExistedRuleNames.isEmpty()) {
+            throw new 
DatabaseDiscoveryRuleDataSourcesNotExistedException(notExistedRuleNames);
+        }
+    }
+
+    private void drop(final YamlDatabaseDiscoveryRuleConfiguration 
yamlDatabaseDiscoveryRuleConfiguration, final 
DropDatabaseDiscoveryRuleStatement sqlStatement) {
+        for (String each : sqlStatement.getRuleNames()) {
+            yamlDatabaseDiscoveryRuleConfiguration.getDiscoveryTypes()
+                    
.remove(yamlDatabaseDiscoveryRuleConfiguration.getDataSources().get(each).getDiscoveryTypeName());
+            
yamlDatabaseDiscoveryRuleConfiguration.getDataSources().remove(each);
+        }
+    }
+    
+    private void post(final String schemaName, final 
Collection<RuleConfiguration> rules) {
+        ShardingSphereEventBus.getInstance().post(new 
RuleConfigurationsAlteredEvent(schemaName, rules));
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
new file mode 100644
index 0000000..fa6abb3
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl;
+
+import com.google.common.collect.Maps;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
+import 
org.apache.shardingsphere.distsql.parser.segment.rdl.DatabaseDiscoveryRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterDatabaseDiscoveryRuleStatement;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleDataSourcesNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.sql.DataSource;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
+    
+    @Mock
+    private BackendConnection backendConnection;
+    
+    @Mock
+    private AlterDatabaseDiscoveryRuleStatement sqlStatement;
+    
+    @Mock
+    private MetaDataContexts metaDataContexts;
+    
+    @Mock
+    private TransactionContexts transactionContexts;
+    
+    @Mock
+    private ShardingSphereMetaData shardingSphereMetaData;
+    
+    @Mock
+    private ShardingSphereRuleMetaData ruleMetaData;
+
+    @Mock
+    private ShardingSphereResource shardingSphereResource;
+
+    @Mock
+    private DatabaseDiscoveryDataSourceRuleConfiguration 
databaseDiscoveryDataSourceRuleConfiguration;
+    
+    private AlterDatabaseDiscoveryRuleBackendHandler handler = new 
AlterDatabaseDiscoveryRuleBackendHandler(sqlStatement, backendConnection);
+    
+    @Before
+    public void setUp() {
+        ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
+        ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
+        
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
+        
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
+        
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
+    }
+    
+    @Test
+    public void assertExecute() {
+        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment();
+        databaseDiscoveryRuleSegment.setName("ha_group");
+        databaseDiscoveryRuleSegment.setDataSources(Arrays.asList("ds_0", 
"ds_1"));
+        databaseDiscoveryRuleSegment.setDiscoveryTypeName("TEST");
+        
when(sqlStatement.getDatabaseDiscoveryRules()).thenReturn(Collections.singletonList(databaseDiscoveryRuleSegment));
+        when(ruleMetaData.getConfigurations()).thenReturn(Collections
+                .singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections
+                        
.singleton(databaseDiscoveryDataSourceRuleConfiguration), Maps.newHashMap())));
+        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
+        
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
+        Map<String, DataSource> dataSourceMap = mock(Map.class);
+        
when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
+        when(dataSourceMap.containsKey(anyString())).thenReturn(true);
+        ResponseHeader responseHeader = handler.execute("test", sqlStatement);
+        assertNotNull(responseHeader);
+        assertTrue(responseHeader instanceof UpdateResponseHeader);
+    }
+    
+    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
+    public void assertExecuteWithNotExistDatabaseDiscoveryRule() {
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
+        handler.execute("test", sqlStatement);
+    }
+
+    @Test(expected = DatabaseDiscoveryRuleDataSourcesNotExistedException.class)
+    public void assertExecuteWithNoAlteredDatabaseDiscoveryRuleDataSources() {
+        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment();
+        databaseDiscoveryRuleSegment.setName("ha_group");
+        databaseDiscoveryRuleSegment.setDataSources(Arrays.asList("ds_0", 
"ds_1"));
+        databaseDiscoveryRuleSegment.setDiscoveryTypeName("TEST");
+        
when(sqlStatement.getDatabaseDiscoveryRules()).thenReturn(Collections.singletonList(databaseDiscoveryRuleSegment));
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Maps.newHashMap())));
+        handler.execute("test", sqlStatement);
+    }
+    
+    @Test(expected = ResourceNotExistedException.class)
+    public void assertExecuteWithNotExistResources() {
+        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment();
+        databaseDiscoveryRuleSegment.setName("ha_group");
+        databaseDiscoveryRuleSegment.setDataSources(Arrays.asList("ds_0", 
"ds_1"));
+        databaseDiscoveryRuleSegment.setDiscoveryTypeName("TEST");
+        
when(sqlStatement.getDatabaseDiscoveryRules()).thenReturn(Collections.singletonList(databaseDiscoveryRuleSegment));
+        when(ruleMetaData.getConfigurations()).thenReturn(Collections
+                .singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections
+                        
.singleton(databaseDiscoveryDataSourceRuleConfiguration), Maps.newHashMap())));
+        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
+        handler.execute("test", sqlStatement);
+    }
+
+    @Test(expected = InvalidDatabaseDiscoveryTypesException.class)
+    public void assertExecuteWithInvalidDiscoveryTypes() {
+        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment();
+        databaseDiscoveryRuleSegment.setName("ha_group");
+        databaseDiscoveryRuleSegment.setDataSources(Arrays.asList("ds_0", 
"ds_1"));
+        databaseDiscoveryRuleSegment.setDiscoveryTypeName("notExistType");
+        
when(sqlStatement.getDatabaseDiscoveryRules()).thenReturn(Collections.singletonList(databaseDiscoveryRuleSegment));
+        when(ruleMetaData.getConfigurations()).thenReturn(Collections
+                .singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections
+                        
.singleton(databaseDiscoveryDataSourceRuleConfiguration), Maps.newHashMap())));
+        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
+        
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
+        Map<String, DataSource> dataSourceMap = mock(Map.class);
+        
when(shardingSphereResource.getDataSources()).thenReturn(dataSourceMap);
+        when(dataSourceMap.containsKey(anyString())).thenReturn(true);
+        handler.execute("test", sqlStatement);
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandlerTest.java
new file mode 100644
index 0000000..db3e195
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropDatabaseDiscoveryRuleBackendHandlerTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl;
+
+import com.google.common.collect.Maps;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleDataSourcesNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class DropDatabaseDiscoveryRuleBackendHandlerTest {
+    
+    @Mock
+    private BackendConnection backendConnection;
+    
+    @Mock
+    private DropDatabaseDiscoveryRuleStatement sqlStatement;
+    
+    @Mock
+    private MetaDataContexts metaDataContexts;
+    
+    @Mock
+    private TransactionContexts transactionContexts;
+    
+    @Mock
+    private ShardingSphereMetaData shardingSphereMetaData;
+    
+    @Mock
+    private ShardingSphereRuleMetaData ruleMetaData;
+
+    @Mock
+    private DatabaseDiscoveryDataSourceRuleConfiguration 
databaseDiscoveryDataSourceRuleConfiguration;
+
+    @Mock
+    private ShardingSphereAlgorithmConfiguration 
shardingSphereAlgorithmConfiguration;
+    
+    private DropDatabaseDiscoveryRuleBackendHandler handler = new 
DropDatabaseDiscoveryRuleBackendHandler(sqlStatement, backendConnection);
+    
+    @Before
+    public void setUp() {
+        ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
+        
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
+        
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
+        
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
+    }
+    
+    @Test
+    public void assertExecute() {
+        
when(sqlStatement.getRuleNames()).thenReturn(Collections.singletonList("ha_group"));
+        Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = new 
HashMap<>(1, 1);
+        discoveryTypes.put("pr_ds_MGR", shardingSphereAlgorithmConfiguration);
+        when(ruleMetaData.getConfigurations()).thenReturn(Collections
+                .singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections
+                        
.singleton(databaseDiscoveryDataSourceRuleConfiguration), discoveryTypes)));
+        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
+        
when(databaseDiscoveryDataSourceRuleConfiguration.getDiscoveryTypeName()).thenReturn("pr_ds_MGR");
+        ResponseHeader responseHeader = handler.execute("test", sqlStatement);
+        assertNotNull(responseHeader);
+        assertTrue(responseHeader instanceof UpdateResponseHeader);
+    }
+    
+    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
+    public void assertExecuteWithNotExistDatabaseDiscoveryRule() {
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
+        handler.execute("test", sqlStatement);
+    }
+
+    @Test(expected = DatabaseDiscoveryRuleDataSourcesNotExistedException.class)
+    public void assertExecuteWithNoDroppedDatabaseDiscoveryRuleDataSources() {
+        
when(sqlStatement.getRuleNames()).thenReturn(Collections.singletonList("ha_group"));
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Maps.newHashMap())));
+        handler.execute("test", sqlStatement);
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index e5db727..05e96b0 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -27,7 +27,9 @@ import 
org.apache.shardingsphere.proxy.backend.exception.AddReadwriteSplittingRu
 import org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
 import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleDataSourcesNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleExistsException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DuplicateResourceException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
 import 
org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
@@ -190,6 +192,12 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof InvalidDatabaseDiscoveryTypesException) {
             return new MySQLErrPacket(1, 
CommonErrorCode.INVALID_DATABASE_DISCOVERY_TYPES, 
((InvalidDatabaseDiscoveryTypesException) cause).getDatabaseDiscoveryTypes());
         }
+        if (cause instanceof DatabaseDiscoveryRuleNotExistedException) {
+            return new MySQLErrPacket(1, 
CommonErrorCode.DATABASE_DISCOVERY_RULE_NOT_EXIST, 
((DatabaseDiscoveryRuleNotExistedException) cause).getSchemaName());
+        }
+        if (cause instanceof 
DatabaseDiscoveryRuleDataSourcesNotExistedException) {
+            return new MySQLErrPacket(1, 
CommonErrorCode.DATABASE_DISCOVERY_RULE_DATASOURCE_NOT_EXIST, 
((DatabaseDiscoveryRuleDataSourcesNotExistedException) cause).getRuleNames());
+        }
         return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION, 
cause.getMessage());
     }
 }

Reply via email to