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 2023/06/27 08:44:31 UTC
[shardingsphere] branch master updated: Refactor features rule changed subscriber (#26621)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 f0fe3055fa5 Refactor features rule changed subscriber (#26621)
f0fe3055fa5 is described below
commit f0fe3055fa592b544f44e632de75bcf90c432511
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Tue Jun 27 16:44:24 2023 +0800
Refactor features rule changed subscriber (#26621)
---
.../shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java | 2 ++
.../subscriber/compatible/CompatibleEncryptTableSubscriber.java | 2 ++
.../apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java | 2 ++
.../subscriber/ReadwriteSplittingDataSourceSubscriber.java | 2 ++
.../shadow/subscriber/ShadowDataSourceSubscriber.java | 2 ++
.../sharding/subscriber/ShardingTableConfigurationSubscriber.java | 6 ++++++
6 files changed, 16 insertions(+)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
index 0818832680f..71cb03447ea 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/EncryptTableSubscriber.java
@@ -108,6 +108,8 @@ public final class EncryptTableSubscriber implements RuleChangedSubscriber {
Optional<EncryptRule> rule = database.getRuleMetaData().findSingleRule(EncryptRule.class);
EncryptRuleConfiguration config = rule.map(encryptRule -> getEncryptRuleConfiguration((EncryptRuleConfiguration) encryptRule.getConfiguration()))
.orElseGet(() -> new EncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>()));
+ // TODO refactor DistSQL to only persist config
+ config.getTables().removeIf(each -> each.getName().equals(needToAddedConfig.getName()));
config.getTables().add(needToAddedConfig);
return config;
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/compatible/CompatibleEncryptTableSubscriber.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/compatible/CompatibleEncryptTableSubscriber.java
index de003002139..cf37c63d189 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/compatible/CompatibleEncryptTableSubscriber.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/subscriber/compatible/CompatibleEncryptTableSubscriber.java
@@ -110,6 +110,8 @@ public final class CompatibleEncryptTableSubscriber implements RuleChangedSubscr
Optional<EncryptRule> rule = database.getRuleMetaData().findSingleRule(EncryptRule.class);
CompatibleEncryptRuleConfiguration config = rule.map(encryptRule -> getCompatibleEncryptRuleConfiguration((CompatibleEncryptRuleConfiguration) encryptRule.getConfiguration()))
.orElseGet(() -> new CompatibleEncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>()));
+ // TODO refactor DistSQL to only persist config
+ config.getTables().removeIf(each -> each.getName().equals(needToAddedConfig.getName()));
config.getTables().add(needToAddedConfig);
return config;
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
index f113852e505..cf114ba7655 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/subscriber/MaskTableSubscriber.java
@@ -105,6 +105,8 @@ public final class MaskTableSubscriber implements RuleChangedSubscriber {
Optional<MaskRule> rule = database.getRuleMetaData().findSingleRule(MaskRule.class);
MaskRuleConfiguration config = rule.map(encryptRule -> getMaskRuleConfiguration((MaskRuleConfiguration) encryptRule.getConfiguration()))
.orElseGet(() -> new MaskRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>()));
+ // TODO refactor DistSQL to only persist config
+ config.getTables().removeIf(each -> each.getName().equals(needToAddedConfig.getName()));
config.getTables().add(needToAddedConfig);
return config;
}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
index d990f53c575..35793c3bc68 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingDataSourceSubscriber.java
@@ -115,6 +115,8 @@ public final class ReadwriteSplittingDataSourceSubscriber implements RuleChanged
dataSources.add(dataSourceRuleConfig);
return new ReadwriteSplittingRuleConfiguration(dataSources, result.getLoadBalancers());
}
+ // TODO refactor DistSQL to only persist config
+ result.getDataSources().removeIf(each -> each.getName().equals(dataSourceRuleConfig.getName()));
result.getDataSources().add(dataSourceRuleConfig);
return result;
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
index dc591dfc937..5ad9ca24743 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/subscriber/ShadowDataSourceSubscriber.java
@@ -65,6 +65,8 @@ public final class ShadowDataSourceSubscriber implements RuleChangedSubscriber {
} else {
config = new ShadowRuleConfiguration();
}
+ // TODO refactor DistSQL to only persist config
+ config.getDataSources().removeIf(each -> each.getName().equals(needToAddedConfig.getName()));
config.getDataSources().add(needToAddedConfig);
instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingTableConfigurationSubscriber.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingTableConfigurationSubscriber.java
index 2c22caa31a1..44e587f1966 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingTableConfigurationSubscriber.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/subscriber/ShardingTableConfigurationSubscriber.java
@@ -72,6 +72,8 @@ public final class ShardingTableConfigurationSubscriber implements RuleChangedSu
ShardingTableRuleConfiguration needToAddedConfig = swapShardingTableRuleConfig(
instanceContext.getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion()));
ShardingRuleConfiguration config = getShardingRuleConfiguration(database);
+ // TODO refactor DistSQL to only persist config
+ config.getTables().removeIf(each -> each.getLogicTable().equals(needToAddedConfig.getLogicTable()));
config.getTables().add(needToAddedConfig);
instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
@@ -90,6 +92,8 @@ public final class ShardingTableConfigurationSubscriber implements RuleChangedSu
ShardingAutoTableRuleConfiguration needToAddedConfig = swapShardingAutoTableRuleConfig(
instanceContext.getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion()));
ShardingRuleConfiguration config = getShardingRuleConfiguration(database);
+ // TODO refactor DistSQL to only persist config
+ config.getAutoTables().removeIf(each -> each.getLogicTable().equals(needToAddedConfig.getLogicTable()));
config.getAutoTables().add(needToAddedConfig);
instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}
@@ -105,6 +109,8 @@ public final class ShardingTableConfigurationSubscriber implements RuleChangedSu
ShardingTableReferenceRuleConfiguration needToAddedConfig = swapShardingTableReferenceRuleConfig(
instanceContext.getModeContextManager().getVersionPathByActiveVersionKey(event.getActiveVersionKey(), event.getActiveVersion()));
ShardingRuleConfiguration config = getShardingRuleConfiguration(database);
+ // TODO refactor DistSQL to only persist config
+ config.getBindingTableGroups().removeIf(each -> each.getName().equals(needToAddedConfig.getName()));
config.getBindingTableGroups().add(needToAddedConfig);
instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
}