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 7ace261 add configuration switch for federation executor engine in
Apache/ShardingSphere (#13277)
7ace261 is described below
commit 7ace261b89c6b756a9c9f9d7b005af562e2911a5
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Oct 26 17:04:59 2021 +0800
add configuration switch for federation executor engine in
Apache/ShardingSphere (#13277)
* add configuration switch for federation execution engine
* modify doc and configuration file
* fix unit test
* fix rewrite test
* add configuration for integration test
* fix checkstyle
* fix checkstyle
* rename federation-executor-enabled to sql-federation-enabled
---
.../shardingsphere-jdbc/configuration/props.cn.md | 1 +
.../shardingsphere-jdbc/configuration/props.en.md | 3 +-
.../shardingsphere-proxy/configuration/props.cn.md | 1 +
.../shardingsphere-proxy/configuration/props.en.md | 1 +
.../engine/type/ShardingRouteEngineFactory.java | 8 +++--
.../type/ShardingRouteEngineFactoryTest.java | 9 +++++-
.../properties/ConfigurationPropertyKey.java | 7 ++++-
.../singletable/route/SingleTableRouteEngine.java | 15 +--------
.../singletable/route/SingleTableSQLRouter.java | 36 ++++++++++++----------
.../singletable/rule/SingleTableRule.java | 32 ++++++++++++++++---
.../src/main/resources/conf/server.yaml | 1 +
.../resources/docker/db/h2/proxy/conf/server.yaml | 1 +
.../docker/db/mysql/proxy/conf/server.yaml | 1 +
.../docker/db/postgresql/proxy/conf/server.yaml | 1 +
.../h2/proxy/conf/server.yaml | 1 +
.../mysql/proxy/conf/server.yaml | 1 +
.../postgresql/proxy/conf/server.yaml | 1 +
.../h2/proxy/conf/server.yaml | 1 +
.../mysql/proxy/conf/server.yaml | 1 +
.../postgresql/proxy/conf/server.yaml | 1 +
.../resources/docker/tbl/h2/proxy/conf/server.yaml | 1 +
.../docker/tbl/mysql/proxy/conf/server.yaml | 1 +
.../docker/tbl/postgresql/proxy/conf/server.yaml | 1 +
.../src/test/resources/env/db/rules.yaml | 3 ++
.../env/dbtbl_with_readwrite_splitting/rules.yaml | 3 ++
.../rules.yaml | 3 ++
.../src/test/resources/env/tbl/rules.yaml | 3 ++
.../scenario/sharding/config/sharding-rule.yaml | 3 ++
28 files changed, 100 insertions(+), 41 deletions(-)
diff --git
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.cn.md
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.cn.md
index 3bb6155..baacdef 100644
---
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.cn.md
+++
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.cn.md
@@ -19,3 +19,4 @@ Apache ShardingSphere 提供属性配置的方式配置系统级配置。
| check-table-metadata-enabled (?) | boolean | 在程序启动和更新时,是否检查分片元数据的结构一致性。
| false |
| check-duplicate-table-enabled (?) | boolean | 在程序启动和更新时,是否检查重复表。
| false |
| sql-comment-parse-enabled (?) | boolean | 是否解析 SQL 注释。
| false |
+| sql-federation-enabled (?) | boolean | 是否开启 federation 查询。
| false |
diff --git
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.en.md
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.en.md
index 8d5d68f..d5ba5e5 100644
---
a/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.en.md
+++
b/docs/document/content/user-manual/shardingsphere-jdbc/configuration/props.en.md
@@ -14,8 +14,9 @@ Apache ShardingSphere provides the way of property
configuration to configure sy
| ---------------------------------- | ----------- |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| --------------- |
| sql-show (?) | boolean | Whether show SQL or not
in log. <br /> Print SQL details can help developers debug easier. The log
details include: logic SQL, actual SQL and SQL parse result. <br /> Enable this
property will log into log topic `ShardingSphere-SQL`, log level is INFO. |
false |
| sql-simple (?) | boolean | Whether show SQL details
in simple style.
| false
|
-| kernel-executor-size (?) | int | The max thread
size of worker group to execute SQL. One ShardingSphereDataSource will use a
independent thread pool, it does not share thread pool even different data
source in same JVM.
| infinite |
+| kernel-executor-size (?) | int | The max thread size of
worker group to execute SQL. One ShardingSphereDataSource will use a
independent thread pool, it does not share thread pool even different data
source in same JVM.
| infinite |
| max-connections-size-per-query (?) | int | Max opened connection
size for each query.
| 1
|
| check-table-metadata-enabled (?) | boolean | Whether validate table
meta data consistency when application startup or updated.
| false
|
| check-duplicate-table-enabled (?) | boolean | Whether validate
duplicate table when application startup or updated.
|
false |
| sql-comment-parse-enabled (?) | boolean | Whether parse the comment
of SQL.
| false
|
+| sql-federation-enabled (?) | boolean | Whether enable sql
federation.
|
false |
diff --git
a/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.cn.md
b/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.cn.md
index e7b4a9f..d8117fe 100644
---
a/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.cn.md
+++
b/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.cn.md
@@ -25,3 +25,4 @@ Apache ShardingSphere 提供属性配置的方式配置系统级配置。
| sql-comment-parse-enabled (?) | boolean | 是否解析 SQL 注释。
| false |
| proxy-frontend-executor-size (?) | int | Proxy 前端 Netty
线程池线程数量,默认值 0 代表使用 Netty 默认值。
| 0 |
| proxy-backend-executor-suitable (?)| String | 可选选项:OLAP、OLTP。OLTP
选项可能会减少向客户端写入数据包的时间开销,但如果客户端连接数超过 `proxy-frontend-netty-executor-size`,尤其是执行慢
SQL 时,它可能会增加 SQL 执行的延迟。 | OLAP |
+| sql-federation-enabled (?) | boolean | 是否开启 federation 查询。
| false |
diff --git
a/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.en.md
b/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.en.md
index 67c0c32..58d42d4 100644
---
a/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.en.md
+++
b/docs/document/content/user-manual/shardingsphere-proxy/configuration/props.en.md
@@ -25,3 +25,4 @@ Apache ShardingSphere provides the way of property
configuration to configure sy
| sql-comment-parse-enabled (?) | boolean | Whether parse the comment
of SQL.
| false
|
| proxy-frontend-executor-size (?) | int | Proxy frontend Netty
executor size. The default value is 0, which means let Netty decide.
| 0
|
| proxy-backend-executor-suitable (?)| String | Available options of
proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may
reduce time cost of writing packets to client, but it may increase the latency
of SQL execution if client connections are more than
`proxy-frontend-netty-executor-size`, especially executing slow SQL.| OLAP |
+| sql-federation-enabled (?) | boolean | Whether enable sql
federation.
|
false |
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 64482b8..4bea173 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
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
import
org.apache.shardingsphere.sharding.route.engine.condition.value.ShardingConditionValue;
@@ -187,7 +188,7 @@ public final class ShardingRouteEngineFactory {
private static ShardingRouteEngine getDQLRouteEngineForShardingTable(final
ShardingRule shardingRule, final SQLStatementContext<?> sqlStatementContext,
final
ShardingConditions shardingConditions, final Collection<String> tableNames,
final ConfigurationProperties props) {
- if (isShardingFederatedQuery(sqlStatementContext, tableNames,
shardingRule, shardingConditions)) {
+ if (isShardingFederatedQuery(sqlStatementContext, tableNames,
shardingRule, shardingConditions, props)) {
return new ShardingFederatedRoutingEngine(tableNames);
}
if (isShardingStandardQuery(tableNames, shardingRule)) {
@@ -207,8 +208,9 @@ public final class ShardingRouteEngineFactory {
}
private static boolean isShardingFederatedQuery(final
SQLStatementContext<?> sqlStatementContext, final Collection<String>
tableNames,
- final ShardingRule
shardingRule, final ShardingConditions shardingConditions) {
- if (!(sqlStatementContext instanceof SelectStatementContext)) {
+ final ShardingRule
shardingRule, final ShardingConditions shardingConditions, final
ConfigurationProperties props) {
+ boolean sqlFederationEnabled =
props.getValue(ConfigurationPropertyKey.SQL_FEDERATION_ENABLED);
+ if (!sqlFederationEnabled || !(sqlStatementContext instanceof
SelectStatementContext)) {
return false;
}
SelectStatementContext select = (SelectStatementContext)
sqlStatementContext;
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 c9233df..6504ae9 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
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dcl.GrantStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
@@ -302,10 +303,16 @@ public final class ShardingRouteEngineFactoryTest {
when(shardingRule.getTableRule("t_order").getActualDatasourceNames()).thenReturn(Arrays.asList("ds_0",
"ds_1"));
when(shardingConditions.isNeedMerge()).thenReturn(true);
when(shardingConditions.isSameShardingCondition()).thenReturn(false);
- ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, metaData,
sqlStatementContext, shardingConditions, props);
+ ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, metaData,
sqlStatementContext, shardingConditions,
createFederationConfigurationProperties());
assertThat(actual, instanceOf(ShardingFederatedRoutingEngine.class));
}
+ private ConfigurationProperties createFederationConfigurationProperties() {
+ Properties props = new Properties();
+
props.setProperty(ConfigurationPropertyKey.SQL_FEDERATION_ENABLED.getKey(),
String.valueOf(Boolean.TRUE));
+ return new ConfigurationProperties(props);
+ }
+
@Test
public void assertNewInstanceForCreateResourceGroup() {
MySQLCreateResourceGroupStatement resourceGroupStatement =
mock(MySQLCreateResourceGroupStatement.class);
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
index e8c35e1..23dda3e 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
@@ -118,7 +118,12 @@ public enum ConfigurationPropertyKey implements
TypedPropertyKey {
/**
* Proxy connection num limit. less than 0 or equal 0 means no limit.
*/
- PROXY_FRONTEND_CONNECTION_LIMIT("proxy-frontend-connection-limit", "-1",
int.class);
+ PROXY_FRONTEND_CONNECTION_LIMIT("proxy-frontend-connection-limit", "-1",
int.class),
+
+ /**
+ * Whether enable sql federation.
+ */
+ SQL_FEDERATION_ENABLED("sql-federation-enabled",
String.valueOf(Boolean.FALSE), boolean.class);
private final String key;
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableRouteEngine.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableRouteEngine.java
index 4f005b8..eccbd73 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableRouteEngine.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableRouteEngine.java
@@ -78,7 +78,7 @@ public final class SingleTableRouteEngine {
}
private void route0(final RouteContext routeContext, final SingleTableRule
rule) {
- if (isDDLTableStatement() || isAllTablesInSameDataSource(routeContext,
rule)) {
+ if (isDDLTableStatement() ||
rule.isAllTablesInSameDataSource(routeContext, singleTableNames)) {
Collection<String> existSingleTables =
rule.getSingleTableNames(singleTableNames);
if (!existSingleTables.isEmpty()) {
fillRouteContext(rule, routeContext, existSingleTables);
@@ -107,19 +107,6 @@ public final class SingleTableRouteEngine {
return sqlStatement instanceof CreateTableStatement || sqlStatement
instanceof AlterTableStatement || sqlStatement instanceof DropTableStatement;
}
- private boolean isAllTablesInSameDataSource(final RouteContext
routeContext, final SingleTableRule rule) {
- if (!rule.isSingleTableInSameDataSource(singleTableNames)) {
- return false;
- }
- SingleTableDataNode dataNode =
rule.getSingleTableDataNodes().get(singleTableNames.iterator().next());
- for (RouteUnit each : routeContext.getRouteUnits()) {
- if
(!each.getDataSourceMapper().getLogicName().equals(dataNode.getDataSourceName()))
{
- return false;
- }
- }
- return true;
- }
-
private RouteUnit getRandomRouteUnit(final SingleTableRule
singleTableRule) {
Collection<String> dataSourceNames =
singleTableRule.getDataSourceNames();
String dataSource = new
ArrayList<>(dataSourceNames).get(ThreadLocalRandom.current().nextInt(dataSourceNames.size()));
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java
index d82a5b7..9b387d9 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java
@@ -17,16 +17,17 @@
package org.apache.shardingsphere.singletable.route;
+import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.singletable.constant.SingleTableOrder;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
+import org.apache.shardingsphere.singletable.constant.SingleTableOrder;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
@@ -41,36 +42,39 @@ public final class SingleTableSQLRouter implements
SQLRouter<SingleTableRule> {
@Override
public RouteContext createRouteContext(final LogicSQL logicSQL, final
ShardingSphereMetaData metaData, final SingleTableRule rule, final
ConfigurationProperties props) {
RouteContext result = new RouteContext();
- route(logicSQL, rule, result);
+ route(logicSQL.getSqlStatementContext(), rule, result, props);
return result;
}
- private void route(final LogicSQL logicSQL, final SingleTableRule rule,
final RouteContext result) {
- SQLStatementContext<?> sqlStatementContext =
logicSQL.getSqlStatementContext();
- Collection<String> singleTableNames =
getSingleTableNames(sqlStatementContext, rule, result);
- if (!singleTableNames.isEmpty()) {
- validateSameDataSource(rule, sqlStatementContext,
singleTableNames);
- new SingleTableRouteEngine(singleTableNames,
sqlStatementContext.getSqlStatement()).route(result, rule);
+ private void route(final SQLStatementContext<?> sqlStatementContext, final
SingleTableRule rule, final RouteContext routeContext, final
ConfigurationProperties props) {
+ Collection<String> singleTableNames =
getSingleTableNames(sqlStatementContext, rule, routeContext);
+ if (singleTableNames.isEmpty()) {
+ return;
}
+ validateSameDataSource(sqlStatementContext, rule, routeContext, props,
singleTableNames);
+ new SingleTableRouteEngine(singleTableNames,
sqlStatementContext.getSqlStatement()).route(routeContext, rule);
}
- private Collection<String> getSingleTableNames(final
SQLStatementContext<?> sqlStatementContext, final SingleTableRule rule, final
RouteContext result) {
+ private Collection<String> getSingleTableNames(final
SQLStatementContext<?> sqlStatementContext, final SingleTableRule rule, final
RouteContext routeContext) {
Collection<String> tableNames = sqlStatementContext instanceof
TableAvailable
? ((TableAvailable)
sqlStatementContext).getAllTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toSet())
: sqlStatementContext.getTablesContext().getTableNames();
- return result.getRouteUnits().isEmpty() &&
sqlStatementContext.getSqlStatement() instanceof CreateTableStatement ?
tableNames : rule.getSingleTableNames(tableNames);
+ return routeContext.getRouteUnits().isEmpty() &&
sqlStatementContext.getSqlStatement() instanceof CreateTableStatement ?
tableNames : rule.getSingleTableNames(tableNames);
}
- private void validateSameDataSource(final SingleTableRule rule, final
SQLStatementContext<?> sqlStatementContext, final Collection<String>
singleTableNames) {
- if (!(sqlStatementContext instanceof SelectStatementContext ||
rule.isSingleTableInSameDataSource(singleTableNames))) {
- throw new ShardingSphereException("Single tables must be in the
same datasource.");
- }
+ private void validateSameDataSource(final SQLStatementContext<?>
sqlStatementContext, final SingleTableRule rule,
+ final RouteContext routeContext, final
ConfigurationProperties props, final Collection<String> singleTableNames) {
+ boolean sqlFederationEnabled =
props.getValue(ConfigurationPropertyKey.SQL_FEDERATION_ENABLED);
+ boolean allTablesInSameDataSource = sqlFederationEnabled
+ ? sqlStatementContext instanceof SelectStatementContext ||
rule.isSingleTablesInSameDataSource(singleTableNames)
+ : rule.isAllTablesInSameDataSource(routeContext,
singleTableNames);
+ Preconditions.checkState(allTablesInSameDataSource, "All tables must
be in the same datasource.");
}
@Override
public void decorateRouteContext(final RouteContext routeContext, final
LogicSQL logicSQL, final ShardingSphereMetaData metaData,
final SingleTableRule rule, final
ConfigurationProperties props) {
- route(logicSQL, rule, routeContext);
+ route(logicSQL.getSqlStatementContext(), rule, routeContext, props);
}
@Override
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
index a66e7f7..c3d81fb 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
@@ -21,6 +21,8 @@ import lombok.Getter;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
@@ -80,17 +82,37 @@ public final class SingleTableRule implements SchemaRule,
DataNodeContainedRule,
}
/**
- * Judge whether single table is in same data source or not.
+ * Judge whether single tables are in same data source or not.
*
- * @param logicTableNames logic table names
- * @return whether single table is in same data source or not
+ * @param singleTableNames single table names
+ * @return whether single tables are in same data source or not
*/
- public boolean isSingleTableInSameDataSource(final Collection<String>
logicTableNames) {
- Set<String> dataSourceNames =
logicTableNames.stream().map(singleTableDataNodes::get).filter(Objects::nonNull).map(SingleTableDataNode::getDataSourceName).collect(Collectors.toSet());
+ public boolean isSingleTablesInSameDataSource(final Collection<String>
singleTableNames) {
+ Set<String> dataSourceNames =
singleTableNames.stream().map(singleTableDataNodes::get).filter(Objects::nonNull).map(SingleTableDataNode::getDataSourceName).collect(Collectors.toSet());
return dataSourceNames.size() <= 1;
}
/**
+ * Judge whether all tables are in same data source or not.
+ *
+ * @param routeContext route context
+ * @param singleTableNames single table names
+ * @return whether all tables are in same data source or not
+ */
+ public boolean isAllTablesInSameDataSource(final RouteContext
routeContext, final Collection<String> singleTableNames) {
+ if (!isSingleTablesInSameDataSource(singleTableNames)) {
+ return false;
+ }
+ SingleTableDataNode dataNode =
singleTableDataNodes.get(singleTableNames.iterator().next());
+ for (RouteUnit each : routeContext.getRouteUnits()) {
+ if
(!each.getDataSourceMapper().getLogicName().equals(dataNode.getDataSourceName()))
{
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Get sharding logic table names.
*
* @param logicTableNames logic table names
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index 0498cad..a16eb5f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -75,3 +75,4 @@
# # if client connections are more than proxy-frontend-netty-executor-size,
especially executing slow SQL.
# proxy-backend-executor-suitable: OLAP
# proxy-frontend-connection-limit: -1 # Proxy connection limit, less than 0
or equal 0 means no limit.
+# sql-federation-enabled: false
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/h2/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/h2/proxy/conf/server.yaml
index 69b1fd4..c372967 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/h2/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/h2/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/mysql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/mysql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/mysql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/mysql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/postgresql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/postgresql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/postgresql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/postgresql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/h2/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/h2/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/h2/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/h2/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/mysql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/mysql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/mysql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/mysql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/postgresql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/postgresql/proxy/conf/server.yaml
index 233f472..1a203b6 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/postgresql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting/postgresql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/h2/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/h2/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/h2/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/h2/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/mysql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/mysql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/mysql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/mysql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/postgresql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/postgresql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/postgresql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_readwrite_splitting_and_encrypt/postgresql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/h2/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/h2/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/h2/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/h2/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/mysql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/mysql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/mysql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/mysql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/postgresql/proxy/conf/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/postgresql/proxy/conf/server.yaml
index 72254e9..affe0eb 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/postgresql/proxy/conf/server.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/postgresql/proxy/conf/server.yaml
@@ -42,3 +42,4 @@ props:
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/rules.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/rules.yaml
index e8465d6..af9aa4a 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/rules.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/rules.yaml
@@ -73,3 +73,6 @@ rules:
keyGenerators:
constant:
type: Constant
+
+props:
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting/rules.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting/rules.yaml
index c9bf96e..78ba93e 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting/rules.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting/rules.yaml
@@ -140,3 +140,6 @@ rules:
loadBalancers:
roundRobin:
type: ROUND_ROBIN
+
+props:
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting_and_encrypt/rules.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting_and_encrypt/rules.yaml
index c9695bf..561d6a1 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting_and_encrypt/rules.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_readwrite_splitting_and_encrypt/rules.yaml
@@ -183,3 +183,6 @@ rules:
plainColumn: plain_pwd
cipherColumn: cipher_pwd
encryptorName: aes_encryptor
+
+props:
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/rules.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/rules.yaml
index 9166adf..d9ab8a5 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/rules.yaml
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/rules.yaml
@@ -73,3 +73,6 @@ rules:
keyGenerators:
constant:
type: Constant
+
+props:
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
index c7f9419..25bf543 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
@@ -87,3 +87,6 @@ rules:
keyGenerators:
test:
type: TEST
+
+props:
+ sql-federation-enabled: true