You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/12/15 03:22:23 UTC

[shardingsphere] branch master updated: Fix DROP DEFAULT SHADOW ALGORITHM. (#22860)

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

jianglongtao 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 32edbd4d14f Fix DROP DEFAULT SHADOW ALGORITHM. (#22860)
32edbd4d14f is described below

commit 32edbd4d14f5db5dc5521e3c0af99e2a0db36738
Author: yx9o <ya...@163.com>
AuthorDate: Thu Dec 15 11:22:11 2022 +0800

    Fix DROP DEFAULT SHADOW ALGORITHM. (#22860)
    
    * Fix DROP DEFAULT SHADOW ALGORITHM.
    
    * Update.
---
 .../rule-definition/shadow/create-default-shadow-algorithm.cn.md    | 2 +-
 .../rule-definition/shadow/create-default-shadow-algorithm.en.md    | 2 +-
 .../update/CreateDefaultShadowAlgorithmStatementUpdater.java        | 4 ++--
 .../handler/update/DropDefaultShadowAlgorithmStatementUpdater.java  | 6 +++---
 .../update/DropDefaultShadowAlgorithmStatementUpdaterTest.java      | 4 ++++
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
index 1e03a46b334..5bf8979e5fd 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.cn.md
@@ -29,7 +29,7 @@ shadowAlgorithmType ::=
 - 创建默认影子库压测算法
 
 ```sql
-CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar");
+CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
 ```
 
 ### 保留字
diff --git a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
index 35deb653617..c806806dbe2 100644
--- a/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
+++ b/docs/document/content/reference/distsql/syntax/rdl/rule-definition/shadow/create-default-shadow-algorithm.en.md
@@ -29,7 +29,7 @@ shadowAlgorithmType ::=
 - Create default shadow algorithm
 
 ```sql
-CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar");
+CREATE DEFAULT SHADOW ALGORITHM TYPE(NAME="SIMPLE_HINT", PROPERTIES("shadow"="true", "foo"="bar"));
 ```
 
 ### Reserved word
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
index 77fda3d49ae..c43e6853e9a 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java
@@ -66,12 +66,12 @@ public final class CreateDefaultShadowAlgorithmStatementUpdater implements RuleD
     
     @Override
     public void checkSQLStatement(final ShardingSphereDatabase database, final CreateDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
-        checkExist(database.getName(), sqlStatement, currentRuleConfig);
+        checkExist(database.getName(), currentRuleConfig);
         checkAlgorithmCompleteness(Collections.singleton(sqlStatement.getShadowAlgorithmSegment().getAlgorithmSegment()));
         checkAlgorithmType(sqlStatement);
     }
     
-    private void checkExist(final String databaseName, final CreateDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
+    private void checkExist(final String databaseName, final ShadowRuleConfiguration currentRuleConfig) {
         Collection<String> requireAlgorithmNames = Collections.singleton(DEFAULT_ALGORITHM_NAME);
         Collection<String> currentAlgorithmNames = null == currentRuleConfig ? Collections.emptyList() : currentRuleConfig.getShadowAlgorithms().keySet();
         ShadowRuleStatementChecker.checkAnyDuplicate(requireAlgorithmNames, currentAlgorithmNames, different -> new DuplicateAlgorithmException(SHADOW, databaseName, different));
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java
index f1e5985d2eb..86da9637277 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.shadow.distsql.handler.update;
 
-import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
 import org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
 import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
+import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
@@ -36,8 +36,7 @@ public final class DropDefaultShadowAlgorithmStatementUpdater implements RuleDef
     private static final String SHADOW = "shadow";
     
     @Override
-    public void checkSQLStatement(final ShardingSphereDatabase database, final DropDefaultShadowAlgorithmStatement sqlStatement,
-                                  final ShadowRuleConfiguration currentRuleConfig) {
+    public void checkSQLStatement(final ShardingSphereDatabase database, final DropDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
         if (sqlStatement.isIfExists() && !isExistRuleConfig(currentRuleConfig)) {
             return;
         }
@@ -63,6 +62,7 @@ public final class DropDefaultShadowAlgorithmStatementUpdater implements RuleDef
     
     @Override
     public boolean updateCurrentRuleConfiguration(final DropDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
+        currentRuleConfig.getShadowAlgorithms().remove(currentRuleConfig.getDefaultShadowAlgorithmName());
         currentRuleConfig.setDefaultShadowAlgorithmName(null);
         return false;
     }
diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java
index 6080a296802..ac75461cb2f 100644
--- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java
+++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.shadow.distsql.update;
 
 import org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
 import org.apache.shardingsphere.shadow.distsql.handler.update.DropDefaultShadowAlgorithmStatementUpdater;
@@ -30,6 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
 
 @RunWith(MockitoJUnitRunner.class)
 public final class DropDefaultShadowAlgorithmStatementUpdaterTest {
@@ -57,10 +59,12 @@ public final class DropDefaultShadowAlgorithmStatementUpdaterTest {
     public void assertUpdate() {
         ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration();
         ruleConfig.setDefaultShadowAlgorithmName("default");
+        ruleConfig.getShadowAlgorithms().put(ruleConfig.getDefaultShadowAlgorithmName(), mock(AlgorithmConfiguration.class));
         DropDefaultShadowAlgorithmStatement statement = new DropDefaultShadowAlgorithmStatement(false);
         updater.checkSQLStatement(database, new DropDefaultShadowAlgorithmStatement(true), ruleConfig);
         assertTrue(updater.hasAnyOneToBeDropped(statement, ruleConfig));
         updater.updateCurrentRuleConfiguration(statement, ruleConfig);
         assertNull(ruleConfig.getDefaultShadowAlgorithmName());
+        assertTrue(ruleConfig.getShadowAlgorithms().isEmpty());
     }
 }