From c2cb6db1ef402ee18ee017c82f5ce585390fac79 Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Fri, 5 Jan 2024 17:10:22 +0800 Subject: [PATCH] Avoid refresh global rule when feature rule changed (#29658) * Avoid refresh global rule when feature rule changed * Fix checkstyle --- .../context/ConfigurationContextManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index 80eb87750bf6d..be507c10ec7e4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -152,7 +152,7 @@ public synchronized void alterRuleConfiguration(final String databaseName, final try { Collection staleResourceHeldRules = getStaleResourceHeldRules(databaseName); staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource); - MetaDataContexts reloadMetaDataContexts = createMetaDataContexts(databaseName, false, null, ruleConfigs); + MetaDataContexts reloadMetaDataContexts = createMetaDataContextsWhenRuleChanged(databaseName, false, null, ruleConfigs); alterSchemaMetaData(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.get().getMetaData().getDatabase(databaseName)); metaDataContexts.set(reloadMetaDataContexts); metaDataContexts.get().getMetaData().getDatabase(databaseName).getSchemas().putAll(newShardingSphereSchemas(metaDataContexts.get().getMetaData().getDatabase(databaseName))); @@ -310,6 +310,23 @@ private Collection getStaleResourceHeldRules(final String data return result; } + /** + * Create meta data contexts when rule configuration changed. + * + * @param databaseName database name + * @param internalLoadMetaData internal load meta data + * @param switchingResource switching resource + * @param ruleConfigs rule configs + * @return MetaDataContexts meta data contexts + * @throws SQLException SQL exception + */ + public MetaDataContexts createMetaDataContextsWhenRuleChanged(final String databaseName, final boolean internalLoadMetaData, final SwitchingResource switchingResource, + final Collection ruleConfigs) throws SQLException { + return newMetaDataContexts(new ShardingSphereMetaData(createChangedDatabases(databaseName, internalLoadMetaData, switchingResource, ruleConfigs), + metaDataContexts.get().getMetaData().getGlobalResourceMetaData(), metaDataContexts.get().getMetaData().getGlobalRuleMetaData(), + metaDataContexts.get().getMetaData().getProps())); + } + /** * Create meta data contexts. *