From 24592b6b7d0c513eac7fb3e038af2692b88b291e Mon Sep 17 00:00:00 2001 From: tristaZero Date: Fri, 13 Jul 2018 12:30:08 +0800 Subject: [PATCH] use InstanceDatabaseBroadcastRoutingEngine for dcl. --- .../router/sharding/ParsingSQLRouter.java | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java index 27f75876d9bad..db6aae76f4ef7 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java @@ -43,6 +43,7 @@ import io.shardingsphere.core.routing.type.RoutingResult; import io.shardingsphere.core.routing.type.TableUnit; import io.shardingsphere.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine; +import io.shardingsphere.core.routing.type.broadcast.InstanceDatabaseBroadcastRoutingEngine; import io.shardingsphere.core.routing.type.broadcast.TableBroadcastRoutingEngine; import io.shardingsphere.core.routing.type.complex.ComplexRoutingEngine; import io.shardingsphere.core.routing.type.ignore.IgnoreRoutingEngine; @@ -118,8 +119,10 @@ private RoutingResult route(final List parameters, final SQLStatement sq routingEngine = new IgnoreRoutingEngine(); } else if (sqlStatement instanceof DDLStatement || (sqlStatement instanceof DCLStatement && ((DCLStatement) sqlStatement).isGrantForSingleTable())) { routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement); - } else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof DCLStatement) { + } else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement) { routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule); + } else if (sqlStatement instanceof DCLStatement) { + routingEngine = new InstanceDatabaseBroadcastRoutingEngine(shardingRule, shardingDataSourceMetaData); } else if (shardingConditions.isAlwaysFalse()) { routingEngine = new UnicastRoutingEngine(shardingRule, tableNames); } else if (sqlStatement instanceof DALStatement) { @@ -134,25 +137,7 @@ private RoutingResult route(final List parameters, final SQLStatement sq // TODO config for cartesian set routingEngine = new ComplexRoutingEngine(shardingRule, parameters, tableNames, shardingConditions); } - return getRoutingResult(routingEngine, sqlStatement); - } - - private RoutingResult getRoutingResult(final RoutingEngine routingEngine, final SQLStatement sqlStatement) { - RoutingResult result = routingEngine.route(); - if (routingEngine instanceof DatabaseBroadcastRoutingEngine && sqlStatement instanceof DCLStatement) { - removeRedundantTableUnits(result); - } - return result; - } - - private void removeRedundantTableUnits(final RoutingResult routingResult) { - Collection toRemoved = new LinkedList<>(); - for (TableUnit each : routingResult.getTableUnits().getTableUnits()) { - if (!shardingDataSourceMetaData.getAllInstanceDataSourceNames().contains(each.getDataSourceName())) { - toRemoved.add(each); - } - } - routingResult.getTableUnits().getTableUnits().removeAll(toRemoved); + return routingEngine.route(); } private GeneratedKey getGenerateKey(final ShardingRule shardingRule, final InsertStatement insertStatement, final List parameters) {