From a6a09ba68baf3bad8dc088f2af8ebecf9ad58fa5 Mon Sep 17 00:00:00 2001 From: Haoran Meng Date: Thu, 2 Jan 2025 14:44:54 +0800 Subject: [PATCH] Remove use original database to build new MetaDataContexts (#34222) --- .../manager/DatabaseRuleConfigurationManager.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java index 9cf95b320a923..50361e42ecd85 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java @@ -36,6 +36,7 @@ import java.util.LinkedList; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * Database rule configuration manager. @@ -74,7 +75,7 @@ public synchronized void alterRuleConfiguration(final String databaseName, final rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); rules.addAll(DatabaseRulesBuilder.build( databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); - refreshMetadata(databaseName, database, rules); + refreshMetadata(databaseName, getRuleConfigurations(rules)); } /** @@ -98,14 +99,16 @@ public synchronized void dropRuleConfiguration(final String databaseName, final rules.addAll(DatabaseRulesBuilder.build( databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); } - refreshMetadata(databaseName, database, rules); + refreshMetadata(databaseName, getRuleConfigurations(rules)); } - private void refreshMetadata(final String databaseName, final ShardingSphereDatabase database, final Collection rules) throws SQLException { - database.getRuleMetaData().getRules().clear(); - database.getRuleMetaData().getRules().addAll(rules); + private void refreshMetadata(final String databaseName, final Collection ruleConfigurations) throws SQLException { MetaDataContexts reloadMetaDataContexts = MetaDataContextsFactory.createByAlterRule(databaseName, false, - database.getRuleMetaData().getConfigurations(), metaDataContexts.get(), metaDataPersistService, computeNodeInstanceContext); + ruleConfigurations, metaDataContexts.get(), metaDataPersistService, computeNodeInstanceContext); metaDataContexts.set(reloadMetaDataContexts); } + + private Collection getRuleConfigurations(final Collection rules) { + return rules.stream().map(ShardingSphereRule::getConfiguration).collect(Collectors.toList()); + } }