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

zhonghongsheng 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 67e9afb  Show error message when altering sharding configuration if 
scaling is not enabled (#15407)
67e9afb is described below

commit 67e9afb23a313504da0834268651b9dcd31141fc
Author: ReyYang <[email protected]>
AuthorDate: Tue Feb 15 16:41:00 2022 +0800

    Show error message when altering sharding configuration if scaling is not 
enabled (#15407)
---
 .../distsql/rdl/rule/RuleDefinitionBackendHandler.java   | 16 +++++++++++++++-
 .../resources/cases/rdl/rdl-integration-test-cases.xml   |  9 ++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
index f4e4b9c..365f051 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.rule;
 
+import com.google.common.collect.Sets;
 import lombok.extern.slf4j.Slf4j;
 import 
org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJobWorker;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.RuleDefinitionStatement;
@@ -33,6 +34,11 @@ 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.session.ConnectionSession;
 import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterDefaultShardingStrategyStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingAlgorithmStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBindingTableRulesStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
 
@@ -40,6 +46,7 @@ import java.util.Collection;
 import java.util.LinkedList;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.Set;
 
 /**
  * Rule definition backend handler.
@@ -54,6 +61,9 @@ public final class RuleDefinitionBackendHandler<T extends 
RuleDefinitionStatemen
         
ShardingSphereServiceLoader.register(RuleDefinitionAlterPreprocessor.class);
     }
     
+    private static final Set<String> RULE_ALTERED_ACTION_LIST = 
Sets.newHashSet(AlterShardingTableRuleStatement.class.getName(), 
AlterShardingAlgorithmStatement.class.getName(),
+            AlterDefaultShardingStrategyStatement.class.getName(), 
AlterShardingBindingTableRulesStatement.class.getName(), 
AlterShardingBroadcastTableRulesStatement.class.getName());
+    
     public RuleDefinitionBackendHandler(final T sqlStatement, final 
ConnectionSession connectionSession) {
         super(sqlStatement, connectionSession);
     }
@@ -68,7 +78,11 @@ public final class RuleDefinitionBackendHandler<T extends 
RuleDefinitionStatemen
         ruleDefinitionUpdater.checkSQLStatement(shardingSphereMetaData, 
sqlStatement, currentRuleConfig);
         Optional<RuleDefinitionAlterPreprocessor> preprocessor = 
TypedSPIRegistry.findRegisteredService(RuleDefinitionAlterPreprocessor.class, 
sqlStatement.getClass().getCanonicalName(), 
                 new Properties());
-        if 
(RuleAlteredJobWorker.isOnRuleAlteredActionEnabled(currentRuleConfig) && 
preprocessor.isPresent()) {
+        if 
(!RuleAlteredJobWorker.isOnRuleAlteredActionEnabled(currentRuleConfig)) {
+            if 
(RULE_ALTERED_ACTION_LIST.contains(sqlStatement.getClass().getCanonicalName())) 
{
+                throw new RuntimeException("scaling is not enabled");
+            }
+        } else if (preprocessor.isPresent()) {
             processCache(shardingSphereMetaData, sqlStatement, 
(RuleDefinitionAlterUpdater) ruleDefinitionUpdater, currentRuleConfig, 
preprocessor.get());
             return new UpdateResponseHeader(sqlStatement);
         }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/rdl-integration-test-cases.xml
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/rdl-integration-test-cases.xml
index e1db09b..adbd71d 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/rdl-integration-test-cases.xml
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/rdl/rdl-integration-test-cases.xml
@@ -90,8 +90,9 @@
             <initial-sql sql="CREATE SHARDING TABLE RULE t_user (
                 RESOURCES(&quot;encrypt_write_ds_${0..9}&quot;),
                 SHARDING_COLUMN=user_id, TYPE(NAME=MOD, 
PROPERTIES(&quot;sharding-count&quot;=40)))));
+                CREATE SHARDING SCALING RULE default_scaling;
                 ALTER SHARDING BINDING TABLE RULES (t_user,t_user_item);"/>
-            <destroy-sql sql="DROP SHARDING BINDING TABLE RULES;DROP SHARDING 
TABLE RULE t_user" />
+            <destroy-sql sql="DROP SHARDING BINDING TABLE RULES;DROP SHARDING 
TABLE RULE t_user;DROP SHARDING SCALING RULE default_scaling" />
         </assertion>
     </test-case>
     
@@ -132,9 +133,10 @@
         <assertion expected-data-file="alter_encrypt_rule.xml">
             <initial-sql sql="CREATE ENCRYPT RULE t_user (COLUMNS ((
                 NAME=pwd, PLAIN=pwd_plain, CIPHER=pwd_cipher, TYPE(NAME=AES, 
PROPERTIES(&quot;aes-key-value&quot;='123456abc')))));
+                CREATE SHARDING SCALING RULE default_scaling;
                 ALTER ENCRYPT RULE t_user (COLUMNS ((NAME=pwd, 
PLAIN=pwd_plain, CIPHER=pwd_cipher, TYPE(NAME=AES,
                 PROPERTIES(&quot;aes-key-value&quot;='123abc')))))"/>
-            <destroy-sql sql="DROP ENCRYPT RULE t_user" />
+            <destroy-sql sql="DROP ENCRYPT RULE t_user;DROP SHARDING SCALING 
RULE default_scaling" />
         </assertion>
     </test-case>
     
@@ -159,9 +161,10 @@
         <assertion expected-data-file="alter_readwrite_splitting_rules.xml">
             <initial-sql sql="CREATE READWRITE_SPLITTING RULE readwrite_ds_1 
(WRITE_RESOURCE=encrypt_write_ds_1,
             READ_RESOURCES(encrypt_read_ds_1), TYPE(NAME=ROUND_ROBIN));
+            CREATE SHARDING SCALING RULE default_scaling;
             ALTER READWRITE_SPLITTING RULE readwrite_ds_1 
(WRITE_RESOURCE=encrypt_write_ds_1,
             READ_RESOURCES(encrypt_read_ds_1, encrypt_read_ds_2), 
TYPE(NAME=RANDOM,PROPERTIES(read_weight='2:1')))"/>
-            <destroy-sql sql="DROP READWRITE_SPLITTING RULE readwrite_ds_1" />
+            <destroy-sql sql="DROP READWRITE_SPLITTING RULE 
readwrite_ds_1;DROP SHARDING SCALING RULE default_scaling" />
         </assertion>
     </test-case>
     

Reply via email to