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 5f3a5fc Refactor exception for alter & drop readwrite splitting rule
(#10426)
5f3a5fc is described below
commit 5f3a5fcc1ac984488696a48627ed4980b4e976aa
Author: Haoran Meng <[email protected]>
AuthorDate: Fri May 21 20:53:03 2021 +0800
Refactor exception for alter & drop readwrite splitting rule (#10426)
* Refactor exception for alter & drop readwrite splitting rule
* Refactor exception for alter & drop readwrite splitting rule
Co-authored-by: menghaoranss <[email protected]>
---
.../db/protocol/error/CommonErrorCode.java | 4 +-
.../ReadwriteSplittingRuleNotExistedException.java | 31 ---------------
...eadwriteSplittingRulesNotExistedException.java} | 10 +++--
.../AlterReadwriteSplittingRuleBackendHandler.java | 29 ++++++++------
.../DropReadwriteSplittingRuleBackendHandler.java | 44 ++++++++++++----------
.../text/distsql/RDLBackendHandlerFactoryTest.java | 6 +--
...erReadwriteSplittingRuleBackendHandlerTest.java | 9 ++---
...opReadwriteSplittingRuleBackendHandlerTest.java | 9 ++---
.../frontend/mysql/err/MySQLErrPacketFactory.java | 11 ++----
9 files changed, 64 insertions(+), 89 deletions(-)
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 5188034..134768e 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
@@ -37,9 +37,7 @@ public enum CommonErrorCode implements SQLErrorCode {
RESOURCE_NOT_EXIST(1104, "C1104", "Resources %s do not exist."),
- REPLICA_QUERY_RULE_NOT_EXIST(1105, "C1105", "Replica query rule does not
exist."),
-
- REPLICA_QUERY_RULE_DATA_SOURCE_NOT_EXIST(1106, "C1106", "Data sources %s
in replica query rule do not exist."),
+ READWRITE_SPLITTING_RULES_NOT_EXIST(1105, "C1105", "Readwrite splitting
rules %s do not exist in schema %s."),
ADD_REPLICA_QUERY_RULE_DATA_SOURCE_EXIST(1107, "C1107", "Data sources %s
in replica query rule already exists."),
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleNotExistedException.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleNotExistedException.java
deleted file mode 100644
index d2a47e9..0000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleNotExistedException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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;
-
-/**
- * Readwrite-splitting rule not existed exception.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ReadwriteSplittingRuleNotExistedException extends
BackendException {
-
- private static final long serialVersionUID = -5119217255419990719L;
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleDataSourcesNotExistedException.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRulesNotExistedException.java
similarity index 80%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleDataSourcesNotExistedException.java
rename to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRulesNotExistedException.java
index daff110..d95c293 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRuleDataSourcesNotExistedException.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ReadwriteSplittingRulesNotExistedException.java
@@ -23,13 +23,15 @@ import lombok.RequiredArgsConstructor;
import java.util.Collection;
/**
- * Readwrite-splitting rule data source not existed exception.
+ * Readwrite splitting rules not existed exception.
*/
@RequiredArgsConstructor
@Getter
-public final class ReadwriteSplittingRuleDataSourcesNotExistedException
extends BackendException {
-
- private static final long serialVersionUID = -2151854349124198061L;
+public final class ReadwriteSplittingRulesNotExistedException extends
BackendException {
+ private static final long serialVersionUID = -5119217255419990719L;
+
+ private final String schemaName;
+
private final Collection<String> ruleNames;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
index 15c791a..9345dbc 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandler.java
@@ -28,8 +28,7 @@ import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
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.InvalidLoadBalancersException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleDataSourcesNotExistedException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
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;
@@ -60,30 +59,36 @@ public final class
AlterReadwriteSplittingRuleBackendHandler extends SchemaRequi
@Override
public ResponseHeader execute(final String schemaName, final
AlterReadwriteSplittingRuleStatement sqlStatement) {
+ Collection<String> alteredRuleNames =
getAlteredRuleNames(sqlStatement);
Optional<ReadwriteSplittingRuleConfiguration> ruleConfig =
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
.filter(each -> each instanceof
ReadwriteSplittingRuleConfiguration).map(each ->
(ReadwriteSplittingRuleConfiguration) each).findFirst();
if (!ruleConfig.isPresent()) {
- throw new ReadwriteSplittingRuleNotExistedException();
+ throw new ReadwriteSplittingRulesNotExistedException(schemaName,
alteredRuleNames);
}
- check(schemaName, sqlStatement, ruleConfig.get());
+ check(schemaName, sqlStatement, ruleConfig.get(), alteredRuleNames);
YamlReadwriteSplittingRuleConfiguration alterConfig =
alter(ruleConfig.get(), sqlStatement);
Collection<RuleConfiguration> rules = new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(alterConfig));
post(schemaName, rules);
return new UpdateResponseHeader(sqlStatement);
}
+
+ private Collection<String> getAlteredRuleNames(final
AlterReadwriteSplittingRuleStatement sqlStatement) {
+ return
sqlStatement.getReadwriteSplittingRules().stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toSet());
+ }
- private void check(final String schemaName, final
AlterReadwriteSplittingRuleStatement sqlStatement, final
ReadwriteSplittingRuleConfiguration ruleConfig) {
- checkAlteredDataSources(ruleConfig, sqlStatement);
+ private void check(final String schemaName, final
AlterReadwriteSplittingRuleStatement sqlStatement,
+ final ReadwriteSplittingRuleConfiguration ruleConfig,
final Collection<String> alteredRuleNames) {
+ checkAlteredRules(schemaName, ruleConfig, alteredRuleNames);
checkResources(sqlStatement, schemaName);
checkLoadBalancer(sqlStatement);
}
- private void checkAlteredDataSources(final
ReadwriteSplittingRuleConfiguration ruleConfig, final
AlterReadwriteSplittingRuleStatement statement) {
- Set<String> existDataSourceNames =
ruleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
- Collection<String> notExistDataSourceNames =
statement.getReadwriteSplittingRules().stream().map(ReadwriteSplittingRuleSegment::getName)
- .filter(each ->
!existDataSourceNames.contains(each)).collect(Collectors.toList());
- if (!notExistDataSourceNames.isEmpty()) {
- throw new
ReadwriteSplittingRuleDataSourcesNotExistedException(notExistDataSourceNames);
+ private void checkAlteredRules(final String schemaName, final
ReadwriteSplittingRuleConfiguration ruleConfig, final Collection<String>
alteredRuleNames) {
+ Set<String> existRuleNames =
ruleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
+ Collection<String> notExistRuleNames = alteredRuleNames.stream()
+ .filter(each ->
!existRuleNames.contains(each)).collect(Collectors.toList());
+ if (!notExistRuleNames.isEmpty()) {
+ throw new ReadwriteSplittingRulesNotExistedException(schemaName,
notExistRuleNames);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
index 2d4ff8a..3d5fe25 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandler.java
@@ -24,8 +24,7 @@ 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.ReadwriteSplittingRuleDataSourcesNotExistedException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
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;
@@ -49,30 +48,37 @@ public final class DropReadwriteSplittingRuleBackendHandler
extends SchemaRequir
@Override
public ResponseHeader execute(final String schemaName, final
DropReadwriteSplittingRuleStatement sqlStatement) {
- Collection<String> ruleNames = sqlStatement.getRuleNames();
+ Collection<String> droppedRuleNames = sqlStatement.getRuleNames();
+ ReadwriteSplittingRuleConfiguration
readwriteSplittingRuleConfiguration =
getReadwriteSplittingRuleConfiguration(schemaName, droppedRuleNames);
+ check(schemaName, readwriteSplittingRuleConfiguration,
droppedRuleNames);
+ YamlReadwriteSplittingRuleConfiguration
yamlReadwriteSplittingRuleConfiguration =
getYamlReadwriteSplittingRuleConfiguration(readwriteSplittingRuleConfiguration);
+ drop(yamlReadwriteSplittingRuleConfiguration, droppedRuleNames);
+ post(schemaName, new YamlRuleConfigurationSwapperEngine()
+
.swapToRuleConfigurations(yamlReadwriteSplittingRuleConfiguration.getDataSources()
+ .isEmpty() ? Collections.emptyList() :
Collections.singletonList(yamlReadwriteSplittingRuleConfiguration)));
+ return new UpdateResponseHeader(sqlStatement);
+ }
+
+ private ReadwriteSplittingRuleConfiguration
getReadwriteSplittingRuleConfiguration(final String schemaName, final
Collection<String> droppedRuleNames) {
Optional<ReadwriteSplittingRuleConfiguration> ruleConfig =
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
.filter(each -> each instanceof
ReadwriteSplittingRuleConfiguration).map(each ->
(ReadwriteSplittingRuleConfiguration) each).findFirst();
if (!ruleConfig.isPresent()) {
- throw new ReadwriteSplittingRuleNotExistedException();
- }
- check(ruleConfig.get(), ruleNames);
- Optional<YamlReadwriteSplittingRuleConfiguration> yamlConfig = new
YamlRuleConfigurationSwapperEngine()
-
.swapToYamlRuleConfigurations(Collections.singletonList(ruleConfig.get())).stream()
- .map(each -> (YamlReadwriteSplittingRuleConfiguration)
each).findFirst();
- if (!yamlConfig.isPresent()) {
- throw new ReadwriteSplittingRuleNotExistedException();
+ throw new ReadwriteSplittingRulesNotExistedException(schemaName,
droppedRuleNames);
}
- drop(yamlConfig.get(), ruleNames);
- post(schemaName, new YamlRuleConfigurationSwapperEngine()
-
.swapToRuleConfigurations(yamlConfig.get().getDataSources().isEmpty() ?
Collections.emptyList() : Collections.singletonList(yamlConfig.get())));
- return new UpdateResponseHeader(sqlStatement);
+ return ruleConfig.get();
+ }
+
+ private YamlReadwriteSplittingRuleConfiguration
getYamlReadwriteSplittingRuleConfiguration(final
ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfiguration) {
+ return new YamlRuleConfigurationSwapperEngine()
+
.swapToYamlRuleConfigurations(Collections.singletonList(readwriteSplittingRuleConfiguration)).stream()
+ .map(each -> (YamlReadwriteSplittingRuleConfiguration)
each).findFirst().get();
}
- private void check(final ReadwriteSplittingRuleConfiguration ruleConfig,
final Collection<String> ruleNames) {
- Collection<String> readwriteSplittingDataSourceNames =
ruleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
- Collection<String> notExistedRuleNames =
ruleNames.stream().filter(each ->
!readwriteSplittingDataSourceNames.contains(each)).collect(Collectors.toList());
+ private void check(final String schemaName, final
ReadwriteSplittingRuleConfiguration ruleConfig, final Collection<String>
droppedRuleNames) {
+ Collection<String> existRuleNames =
ruleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+ Collection<String> notExistedRuleNames =
droppedRuleNames.stream().filter(each ->
!existRuleNames.contains(each)).collect(Collectors.toList());
if (!notExistedRuleNames.isEmpty()) {
- throw new
ReadwriteSplittingRuleDataSourcesNotExistedException(notExistedRuleNames);
+ throw new ReadwriteSplittingRulesNotExistedException(schemaName,
droppedRuleNames);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerFactoryTest.java
index 1fae5b2..6ed171c 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerFactoryTest.java
@@ -35,7 +35,7 @@ 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.DBCreateExistsException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -211,7 +211,7 @@ public final class RDLBackendHandlerFactoryTest {
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
- @Test(expected = ReadwriteSplittingRuleNotExistedException.class)
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
public void assertExecuteDropReadwriteSplittingRuleContext() throws
SQLException {
BackendConnection connection = mock(BackendConnection.class);
when(connection.getSchemaName()).thenReturn("schema");
@@ -243,7 +243,7 @@ public final class RDLBackendHandlerFactoryTest {
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
- @Test(expected = ReadwriteSplittingRuleNotExistedException.class)
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
public void assertExecuteAlterReadwriteSplittingRuleContext() throws
SQLException {
BackendConnection connection = mock(BackendConnection.class);
when(connection.getSchemaName()).thenReturn("schema");
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
index dffc760..3deeb78 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterReadwriteSplittingRuleBackendHandlerTest.java
@@ -28,8 +28,7 @@ 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.InvalidLoadBalancersException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleDataSourcesNotExistedException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
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;
@@ -114,14 +113,14 @@ public final class
AlterReadwriteSplittingRuleBackendHandlerTest {
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
- @Test(expected = ReadwriteSplittingRuleNotExistedException.class)
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
public void assertExecuteWithNotExistReadwriteSplittingRule() {
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
handler.execute("test", sqlStatement);
}
- @Test(expected =
ReadwriteSplittingRuleDataSourcesNotExistedException.class)
- public void assertExecuteWithNoAlteredReadwriteSplittingRuleDataSources() {
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
+ public void assertExecuteWithNoAlteredReadwriteSplittingRules() {
ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new
ReadwriteSplittingRuleSegment();
readwriteSplittingRuleSegment.setName("pr_ds");
readwriteSplittingRuleSegment.setWriteDataSource("ds_write");
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandlerTest.java
index 4d425dd..2fd4662 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropReadwriteSplittingRuleBackendHandlerTest.java
@@ -26,8 +26,7 @@ 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.ReadwriteSplittingRuleDataSourcesNotExistedException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
@@ -102,14 +101,14 @@ public final class
DropReadwriteSplittingRuleBackendHandlerTest {
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
- @Test(expected = ReadwriteSplittingRuleNotExistedException.class)
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
public void assertExecuteWithNotExistReadwriteSplittingRule() {
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
handler.execute("test", sqlStatement);
}
- @Test(expected =
ReadwriteSplittingRuleDataSourcesNotExistedException.class)
- public void assertExecuteWithNoDroppedReadwriteSplittingRuleDataSources() {
+ @Test(expected = ReadwriteSplittingRulesNotExistedException.class)
+ public void assertExecuteWithNoDroppedReadwriteSplittingRules() {
when(sqlStatement.getRuleNames()).thenReturn(Collections.singletonList("pr_ds"));
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new
ReadwriteSplittingRuleConfiguration(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 f7883a2..594ac41 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
@@ -40,8 +40,7 @@ import
org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersExc
import
org.apache.shardingsphere.proxy.backend.exception.InvalidResourceException;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleCreateExistsException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleDataSourcesNotExistedException;
-import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRuleNotExistedException;
+import
org.apache.shardingsphere.proxy.backend.exception.ReadwriteSplittingRulesNotExistedException;
import
org.apache.shardingsphere.proxy.backend.exception.ResourceInUsedException;
import
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
import
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
@@ -171,11 +170,9 @@ public final class MySQLErrPacketFactory {
if (cause instanceof ShardingBroadcastTableRulesNotExistsException) {
return new MySQLErrPacket(1,
CommonErrorCode.SHARDING_BROADCAST_TABLE_RULES_NOT_EXIST,
((ShardingBroadcastTableRulesNotExistsException) cause).getSchemaName());
}
- if (cause instanceof ReadwriteSplittingRuleNotExistedException) {
- return new MySQLErrPacket(1,
CommonErrorCode.REPLICA_QUERY_RULE_NOT_EXIST);
- }
- if (cause instanceof
ReadwriteSplittingRuleDataSourcesNotExistedException) {
- return new MySQLErrPacket(1,
CommonErrorCode.REPLICA_QUERY_RULE_DATA_SOURCE_NOT_EXIST,
((ReadwriteSplittingRuleDataSourcesNotExistedException) cause).getRuleNames());
+ if (cause instanceof ReadwriteSplittingRulesNotExistedException) {
+ return new MySQLErrPacket(1,
CommonErrorCode.READWRITE_SPLITTING_RULES_NOT_EXIST,
+ ((ReadwriteSplittingRulesNotExistedException)
cause).getRuleNames(), ((ReadwriteSplittingRulesNotExistedException)
cause).getSchemaName());
}
if (cause instanceof
AddReadwriteSplittingRuleDataSourcesExistedException) {
return new MySQLErrPacket(1,
CommonErrorCode.ADD_REPLICA_QUERY_RULE_DATA_SOURCE_EXIST,
((AddReadwriteSplittingRuleDataSourcesExistedException) cause).getRuleNames());