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 b23c8b7  Add TODO for DropShardingTableRuleBackendHandler (#10418)
b23c8b7 is described below

commit b23c8b79b2c33fc0c5ee18a76930ff32b4e7d623
Author: Haoran Meng <[email protected]>
AuthorDate: Fri May 21 16:58:39 2021 +0800

    Add TODO for DropShardingTableRuleBackendHandler (#10418)
    
    * Add TODO for DropShardingTableRuleBackendHandler
    
    * Add TODO for DropShardingTableRuleBackendHandler
    
    * Add TODO for DropShardingTableRuleBackendHandler
    
    Co-authored-by: menghaoranss <[email protected]>
---
 .../shardingsphere/db/protocol/error/CommonErrorCode.java |  2 +-
 .../db/protocol/error/CommonErrorCodeTest.java            |  6 +++---
 ...eption.java => ShardingTableRulesInUsedException.java} |  4 ++--
 .../rdl/impl/DropShardingTableRuleBackendHandler.java     | 14 +++++++++-----
 .../rdl/impl/DropShardingTableRuleBackendHandlerTest.java | 15 ---------------
 .../proxy/frontend/mysql/err/MySQLErrPacketFactory.java   |  6 +++---
 .../frontend/mysql/err/MySQLErrPacketFactoryTest.java     |  6 +++---
 7 files changed, 21 insertions(+), 32 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 c43e5cd..5188034 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
@@ -31,7 +31,7 @@ public enum CommonErrorCode implements SQLErrorCode {
     
     SHARDING_TABLE_RULES_NOT_EXISTED(1101, "C1101", "Sharding table rule %s is 
not exist."),
     
-    TABLES_IN_USED(1102, "C1102", "Tables %s in the rule are still in used."),
+    SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE(1102, "C1102", "Sharding 
table rules %s are still used by binding table rule."),
 
     RESOURCE_IN_USED(1103, "C1103", "Resources %s in the rule are still in 
used."),
     
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
index e34bab2..9f1a19d 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
@@ -40,9 +40,9 @@ public final class CommonErrorCodeTest {
     
     @Test
     public void assertTableInUsed() {
-        assertThat(CommonErrorCode.TABLES_IN_USED.getErrorCode(), is(1102));
-        assertThat(CommonErrorCode.TABLES_IN_USED.getSqlState(), is("C1102"));
-        assertThat(CommonErrorCode.TABLES_IN_USED.getErrorMessage(), 
is("Tables %s in the rule are still in used."));
+        
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE.getErrorCode(),
 is(1102));
+        
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE.getSqlState(),
 is("C1102"));
+        
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE.getErrorMessage(),
 is("Sharding table rules %s are still used by binding table rule."));
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/TablesInUsedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRulesInUsedException.java
similarity index 90%
rename from 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/TablesInUsedException.java
rename to 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRulesInUsedException.java
index c572181..1f6f861 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/TablesInUsedException.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRulesInUsedException.java
@@ -23,11 +23,11 @@ import lombok.RequiredArgsConstructor;
 import java.util.Collection;
 
 /**
- * Tables in used exception.
+ * Sharding table rules in used exception.
  */
 @RequiredArgsConstructor
 @Getter
-public final class TablesInUsedException extends BackendException {
+public final class ShardingTableRulesInUsedException extends BackendException {
     
     private static final long serialVersionUID = -6958306664517015097L;
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
index 9763d7f..7309821 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
 
+import com.google.common.base.Splitter;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropShardingTableRuleStatement;
 import 
org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
@@ -24,7 +25,6 @@ import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.TablesInUsedException;
 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;
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleC
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 
 import java.util.Collection;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -65,10 +66,7 @@ public final class DropShardingTableRuleBackendHandler 
extends SchemaRequiredBac
         if (!notExistedTableNames.isEmpty()) {
             throw new 
ShardingTableRuleNotExistedException(notExistedTableNames);
         }
-        Collection<String> inUsedTableNames = tableNames.stream().filter(each 
-> 
ProxyContext.getInstance().getMetaData(schemaName).getSchema().containsTable(each)).collect(Collectors.toList());
-        if (!inUsedTableNames.isEmpty()) {
-            throw new TablesInUsedException(inUsedTableNames);
-        }
+        // TODO issue#10417
         return shardingRuleConfiguration.get();
     }
 
@@ -96,6 +94,12 @@ public final class DropShardingTableRuleBackendHandler 
extends SchemaRequiredBac
                 .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
     }
 
+    private Collection<String> getBindingTables(final 
ShardingRuleConfiguration shardingRuleConfiguration) {
+        Collection<String> bindTables = new LinkedHashSet<>();
+        shardingRuleConfiguration.getBindingTableGroups().forEach(each -> 
bindTables.addAll(Splitter.on(",").splitToList(each)));
+        return bindTables;
+    }
+
     private void post(final String schemaName) {
         // TODO should use RuleConfigurationsChangeEvent
         ShardingSphereEventBus.getInstance().post(new 
RuleConfigurationsAlteredEvent(schemaName, 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations()));
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
index 04216a3..5132026 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
@@ -22,12 +22,10 @@ import 
org.apache.shardingsphere.infra.config.RuleConfiguration;
 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.infra.metadata.schema.ShardingSphereSchema;
 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.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
-import org.apache.shardingsphere.proxy.backend.exception.TablesInUsedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -74,9 +72,6 @@ public final class DropShardingTableRuleBackendHandlerTest {
     
     @Mock
     private ShardingSphereRuleMetaData ruleMetaData;
-
-    @Mock
-    private ShardingSphereSchema shardingSphereSchema;
     
     private DropShardingTableRuleBackendHandler handler = new 
DropShardingTableRuleBackendHandler(sqlStatement, backendConnection);
     
@@ -86,7 +81,6 @@ public final class DropShardingTableRuleBackendHandlerTest {
         
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
         
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
-        
when(shardingSphereMetaData.getSchema()).thenReturn(shardingSphereSchema);
     }
     
     @Test(expected = ShardingRuleNotExistedException.class)
@@ -102,15 +96,6 @@ public final class DropShardingTableRuleBackendHandlerTest {
         handler.execute("test", sqlStatement);
     }
 
-    @Test(expected = TablesInUsedException.class)
-    public void assertExecuteWithTableRuleInUsed() {
-        TableNameSegment tableRuleSegment = new TableNameSegment(0, 3, new 
IdentifierValue("t_order"));
-        
when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
-        
when(sqlStatement.getTableNames()).thenReturn(Arrays.asList(tableRuleSegment));
-        
when(shardingSphereSchema.containsTable(eq("t_order"))).thenReturn(true);
-        handler.execute("test", sqlStatement);
-    }
-
     @Test
     public void assertExecute() {
         TableNameSegment tableRuleSegment = new TableNameSegment(0, 3, new 
IdentifierValue("t_order"));
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 35ebfbf..f7883a2 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
@@ -51,10 +51,10 @@ import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableR
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRulesInUsedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableLockWaitTimeoutException;
 import org.apache.shardingsphere.proxy.backend.exception.TableLockedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
-import org.apache.shardingsphere.proxy.backend.exception.TablesInUsedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException;
 import org.apache.shardingsphere.proxy.backend.text.sctl.ShardingCTLErrorCode;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.exception.ShardingCTLException;
@@ -116,8 +116,8 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof ShardingTableRuleNotExistedException) {
             return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED, 
((ShardingTableRuleNotExistedException) cause).getTableNames());
         }
-        if (cause instanceof TablesInUsedException) {
-            return new MySQLErrPacket(1, CommonErrorCode.TABLES_IN_USED, 
((TablesInUsedException) cause).getTableNames());
+        if (cause instanceof ShardingTableRulesInUsedException) {
+            return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE, 
((ShardingTableRulesInUsedException) cause).getTableNames());
         }
         if (cause instanceof UnsupportedCommandException) {
             return new MySQLErrPacket(1, CommonErrorCode.UNSUPPORTED_COMMAND, 
((UnsupportedCommandException) cause).getCommandType());
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 70a8079..08bcee1 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -25,8 +25,8 @@ import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException
 import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRulesInUsedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
-import org.apache.shardingsphere.proxy.backend.exception.TablesInUsedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.exception.InvalidShardingCTLFormatException;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.exception.UnsupportedShardingCTLTypeException;
@@ -204,11 +204,11 @@ public final class MySQLErrPacketFactoryTest {
     
     @Test
     public void assertNewInstanceWithTablesInUsedException() {
-        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
TablesInUsedException(Collections.singleton("tbl")));
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
ShardingTableRulesInUsedException(Collections.singleton("tbl")));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1102));
         assertThat(actual.getSqlState(), is("C1102"));
-        assertThat(actual.getErrorMessage(), is("Tables [tbl] in the rule are 
still in used."));
+        assertThat(actual.getErrorMessage(), is("Sharding table rules [tbl] 
are still used by binding table rule."));
     }
 
     @Test

Reply via email to