You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/10/25 10:38:29 UTC
[shardingsphere] branch master updated: Support resource group
route. (#13262)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f70d0bc Support resource group route. (#13262)
f70d0bc is described below
commit f70d0bc5123704327282122d122aecc9ebcf3975
Author: tuichenchuxin <86...@users.noreply.github.com>
AuthorDate: Mon Oct 25 18:37:52 2021 +0800
Support resource group route. (#13262)
---
.../route/engine/type/ShardingRouteEngineFactory.java | 10 ++++++++++
.../engine/type/ShardingRouteEngineFactoryTest.java | 18 ++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
index 661d11d..4d2cf5c 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
@@ -54,6 +54,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTablesp
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.TCLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCreateResourceGroupStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetResourceGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLLoadStatement;
@@ -125,6 +127,9 @@ public final class ShardingRouteEngineFactory {
|| sqlStatement instanceof MySQLShowDatabasesStatement || sqlStatement instanceof PostgreSQLLoadStatement) {
return new ShardingDatabaseBroadcastRoutingEngine();
}
+ if (isResourceGroupStatement(sqlStatement)) {
+ return new ShardingInstanceBroadcastRoutingEngine(metaData.getResource().getDataSourcesMetaData());
+ }
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
Collection<String> shardingRuleTableNames = shardingRule.getShardingRuleTableNames(tableNames);
if (!tableNames.isEmpty() && shardingRuleTableNames.isEmpty()) {
@@ -140,6 +145,11 @@ public final class ShardingRouteEngineFactory {
return new ShardingDataSourceGroupBroadcastRoutingEngine();
}
+ private static boolean isResourceGroupStatement(final SQLStatement sqlStatement) {
+ // TODO add dropResourceGroupStatement, alterResourceGroupStatement
+ return sqlStatement instanceof MySQLCreateResourceGroupStatement || sqlStatement instanceof MySQLSetResourceGroupStatement;
+ }
+
private static ShardingRouteEngine getDCLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext<?> sqlStatementContext) {
if (isDCLForSingleTable(sqlStatementContext)) {
Collection<String> shardingRuleTableNames = shardingRule.getShardingRuleTableNames(sqlStatementContext.getTablesContext().getTableNames());
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
index 20ccfbb..755dc67 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
@@ -45,6 +45,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatemen
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.TCLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLCreateResourceGroupStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetResourceGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowColumnsStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateTableStatement;
@@ -303,4 +305,20 @@ public final class ShardingRouteEngineFactoryTest {
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props);
assertThat(actual, instanceOf(ShardingFederatedRoutingEngine.class));
}
+
+ @Test
+ public void assertNewInstanceForCreateResourceGroup() {
+ MySQLCreateResourceGroupStatement resourceGroupStatement = mock(MySQLCreateResourceGroupStatement.class);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement);
+ ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props);
+ assertThat(actual, instanceOf(ShardingInstanceBroadcastRoutingEngine.class));
+ }
+
+ @Test
+ public void assertNewInstanceForSetResourceGroup() {
+ MySQLSetResourceGroupStatement resourceGroupStatement = mock(MySQLSetResourceGroupStatement.class);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement);
+ ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props);
+ assertThat(actual, instanceOf(ShardingInstanceBroadcastRoutingEngine.class));
+ }
}