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 e82146a Refactor cache rule configuration (#13411)
e82146a is described below
commit e82146a78e75af256b6c3870481f2a1e04e73e8f
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Nov 2 18:48:59 2021 +0800
Refactor cache rule configuration (#13411)
---
...lterShardingTableRuleStatementPreprocessor.java | 25 ----------------------
.../rdl/rule/RuleDefinitionBackendHandler.java | 1 +
2 files changed, 1 insertion(+), 25 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/preprocess/AlterShardingTableRuleStatementPreprocessor.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/preprocess/AlterShardingTableRuleStatementPrepro
[...]
index f2c8e0c..cd8a8a8 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/preprocess/AlterShardingTableRuleStatementPreprocessor.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/preprocess/AlterShardingTableRuleStatementPreprocessor.java
@@ -17,14 +17,10 @@
package org.apache.shardingsphere.sharding.distsql.handler.preprocess;
-import com.google.common.base.Preconditions;
import
org.apache.shardingsphere.infra.distsql.preprocess.RuleDefinitionAlterPreprocessor;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
-import java.util.Optional;
-
/**
* Alter sharding table rule statement preprocessor.
*/
@@ -48,27 +44,6 @@ public final class
AlterShardingTableRuleStatementPreprocessor implements RuleDe
result.setBroadcastTables(currentRuleConfig.getBroadcastTables());
result.setDefaultKeyGenerateStrategy(currentRuleConfig.getDefaultKeyGenerateStrategy());
result.setKeyGenerators(currentRuleConfig.getKeyGenerators());
- dropRuleConfiguration(result, toBeAlteredRuleConfig);
- addRuleConfiguration(result, toBeAlteredRuleConfig);
return result;
}
-
- private void dropRuleConfiguration(final ShardingRuleConfiguration
preAlteredRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
- for (ShardingAutoTableRuleConfiguration each :
toBeAlteredRuleConfig.getAutoTables()) {
- Optional<ShardingAutoTableRuleConfiguration>
shardingAutoTableRuleConfig
- =
preAlteredRuleConfig.getAutoTables().stream().filter(tableRule ->
each.getLogicTable().equals(tableRule.getLogicTable())).findAny();
- Preconditions.checkState(shardingAutoTableRuleConfig.isPresent());
-
preAlteredRuleConfig.getAutoTables().remove(shardingAutoTableRuleConfig.get());
-
preAlteredRuleConfig.getShardingAlgorithms().remove(shardingAutoTableRuleConfig.get().getShardingStrategy().getShardingAlgorithmName());
- if (null !=
shardingAutoTableRuleConfig.get().getKeyGenerateStrategy()) {
-
preAlteredRuleConfig.getKeyGenerators().remove(shardingAutoTableRuleConfig.get().getKeyGenerateStrategy().getKeyGeneratorName());
- }
- }
- }
-
- private void addRuleConfiguration(final ShardingRuleConfiguration
currentRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
-
currentRuleConfig.getAutoTables().addAll(toBeAlteredRuleConfig.getAutoTables());
-
currentRuleConfig.getShardingAlgorithms().putAll(toBeAlteredRuleConfig.getShardingAlgorithms());
-
currentRuleConfig.getKeyGenerators().putAll(toBeAlteredRuleConfig.getKeyGenerators());
- }
}
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 ea6fa23..f992406 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
@@ -123,6 +123,7 @@ public final class RuleDefinitionBackendHandler<T extends
RuleDefinitionStatemen
final RuleDefinitionAlterPreprocessor
preprocessor) {
RuleConfiguration toBeAlteredRuleConfig =
updater.buildToBeAlteredRuleConfiguration(sqlStatement);
RuleConfiguration alteredRuleConfig =
preprocessor.preprocess(currentRuleConfig, toBeAlteredRuleConfig);
+ updater.updateCurrentRuleConfiguration(alteredRuleConfig,
toBeAlteredRuleConfig);
Collection<RuleConfiguration> alteredConfigs = new
LinkedList<>(shardingSphereMetaData.getRuleMetaData().getConfigurations());
alteredConfigs.remove(currentRuleConfig);
alteredConfigs.add(alteredRuleConfig);