You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/08/20 10:21:44 UTC

[shardingsphere] branch master updated: Add various check conditions for RDL executor (#6953)

This is an automated email from the ASF dual-hosted git repository.

zhangliang 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 abd8f37  Add various check conditions for RDL executor (#6953)
abd8f37 is described below

commit abd8f379e6273b9df2575fa3b79061ea86e341cd
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Thu Aug 20 18:21:21 2020 +0800

    Add various check conditions for RDL executor (#6953)
---
 .../orchestration/core/config/ConfigCenter.java              | 12 ++++++++++--
 .../org/apache/shardingsphere/sharding/rule/TableRule.java   |  2 +-
 .../convert/CreateDataSourcesStatementContextConverter.java  |  7 +++++++
 .../parser/binder/util/ShardingAlgorithmPropertiesUtil.java  |  9 +++++----
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
index 0031287..56babde 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenter.java
@@ -130,12 +130,12 @@ public final class ConfigCenter {
         for (RuleConfiguration each : ruleConfigurations) {
             if (each instanceof ShardingRuleConfiguration) {
                 ShardingRuleConfiguration config = (ShardingRuleConfiguration) each;
-                Preconditions.checkState(!config.getTables().isEmpty() || null != config.getDefaultTableShardingStrategy(),
+                Preconditions.checkState(hasAvailableTableConfigurations(config),
                         "No available rule configurations in `%s` for orchestration.", schemaName);
                 configurations.add(each);
             } else if (each instanceof AlgorithmProvidedShardingRuleConfiguration) {
                 AlgorithmProvidedShardingRuleConfiguration config = (AlgorithmProvidedShardingRuleConfiguration) each;
-                Preconditions.checkState(!config.getTables().isEmpty() || null != config.getDefaultTableShardingStrategy(),
+                Preconditions.checkState(hasAvailableTableConfigurations(config),
                         "No available rule configurations in `%s` for orchestration.", schemaName);
                 configurations.add(each);
             } else if (each instanceof AlgorithmProvidedMasterSlaveRuleConfiguration) {
@@ -167,6 +167,14 @@ public final class ConfigCenter {
         repository.persist(node.getRulePath(schemaName), YamlEngine.marshal(yamlRuleConfigurations));
     }
     
+    private boolean hasAvailableTableConfigurations(final ShardingRuleConfiguration configuration) {
+        return !configuration.getTables().isEmpty() || null != configuration.getDefaultTableShardingStrategy() || !configuration.getAutoTables().isEmpty();
+    }
+    
+    private boolean hasAvailableTableConfigurations(final AlgorithmProvidedShardingRuleConfiguration configuration) {
+        return !configuration.getTables().isEmpty() || null != configuration.getDefaultTableShardingStrategy() || !configuration.getAutoTables().isEmpty();
+    }
+    
     /**
      * Persist metrics configuration.
      *
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
index 4e10f4b..e6cf474 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
@@ -131,7 +131,7 @@ public final class TableRule {
             return new LinkedList<>();
         }
         List<String> result = new LinkedList<>();
-        List<String> dataSources = null == tableRuleConfig.getActualDataSources() ? new LinkedList<>(dataSourceNames)
+        List<String> dataSources = Strings.isNullOrEmpty(tableRuleConfig.getActualDataSources()) ? new LinkedList<>(dataSourceNames)
                 : new InlineExpressionParser(tableRuleConfig.getActualDataSources()).splitAndEvaluate();
         ShardingAutoTableAlgorithm tableAlgorithm = (ShardingAutoTableAlgorithm) tableShardingStrategy.getShardingAlgorithm();
         Iterator iterator = dataSources.iterator();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java
index 4bfd991..23202eb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/convert/CreateDataSourcesStatementContextConverter.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.proxy.convert;
 
+import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 import org.apache.shardingsphere.rdl.parser.binder.context.CreateDataSourcesStatementContext;
 import org.apache.shardingsphere.rdl.parser.binder.generator.SQLStatementContextConverter;
@@ -34,10 +35,16 @@ public final class CreateDataSourcesStatementContextConverter implements SQLStat
     public Map<String, YamlDataSourceParameter> convert(final CreateDataSourcesStatementContext context) {
         Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(context.getSqlStatement().getConnectionInfos().size(), 1);
         for (DataSourceConnectionSegment each : context.getSqlStatement().getConnectionInfos()) {
+            DataSourceParameter parameter = new DataSourceParameter();
             YamlDataSourceParameter dataSource = new YamlDataSourceParameter();
             dataSource.setUrl(context.getUrl(each));
             dataSource.setUsername(each.getUser());
             dataSource.setPassword(each.getPassword());
+            dataSource.setMinPoolSize(parameter.getMinPoolSize());
+            dataSource.setMaxPoolSize(parameter.getMaxPoolSize());
+            dataSource.setConnectionTimeoutMilliseconds(parameter.getConnectionTimeoutMilliseconds());
+            dataSource.setIdleTimeoutMilliseconds(parameter.getIdleTimeoutMilliseconds());
+            dataSource.setMaintenanceIntervalMilliseconds(parameter.getMaintenanceIntervalMilliseconds());
             result.put(each.getName(), dataSource);
         }
         return result;
diff --git a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/util/ShardingAlgorithmPropertiesUtil.java b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/util/ShardingAlgorithmPropertiesUtil.java
index 44ff5fc..18bb868 100644
--- a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/util/ShardingAlgorithmPropertiesUtil.java
+++ b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/util/ShardingAlgorithmPropertiesUtil.java
@@ -53,11 +53,12 @@ public final class ShardingAlgorithmPropertiesUtil {
      * @return properties
      */
     public static Properties getProperties(final String shardingAlgorithmType, final Collection<String> properties) {
-        Preconditions.checkArgument(TYPE_AND_PROPERTIES.containsKey(shardingAlgorithmType), "Bad sharding algorithm type: %s.", shardingAlgorithmType);
-        Preconditions.checkArgument(TYPE_AND_PROPERTIES.get(shardingAlgorithmType).size() == properties.size(),
-                "%s needs %d properties, but %s properties are given.", shardingAlgorithmType, TYPE_AND_PROPERTIES.get(shardingAlgorithmType).size(), properties.size());
+        String algorithmType = shardingAlgorithmType.toUpperCase();
+        Preconditions.checkArgument(TYPE_AND_PROPERTIES.containsKey(algorithmType), "Bad sharding algorithm type: %s.", algorithmType);
+        Preconditions.checkArgument(TYPE_AND_PROPERTIES.get(algorithmType).size() == properties.size(),
+                "%s needs %d properties, but %s properties are given.", algorithmType, TYPE_AND_PROPERTIES.get(algorithmType).size(), properties.size());
         Properties result = new Properties();
-        Iterator<String> keys = TYPE_AND_PROPERTIES.get(shardingAlgorithmType).iterator();
+        Iterator<String> keys = TYPE_AND_PROPERTIES.get(algorithmType).iterator();
         Iterator<String> values = properties.iterator();
         while (keys.hasNext()) {
             result.setProperty(keys.next(), values.next());