Skip to content

Commit

Permalink
Avoid refresh global rule when feature rule changed (#29658)
Browse files Browse the repository at this point in the history
* Avoid refresh global rule when feature rule changed

* Fix checkstyle
  • Loading branch information
zhaojinchao95 authored Jan 5, 2024
1 parent 99a5340 commit c2cb6db
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public synchronized void alterRuleConfiguration(final String databaseName, final
try {
Collection<ResourceHeldRule> 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)));
Expand Down Expand Up @@ -310,6 +310,23 @@ private Collection<ResourceHeldRule> 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<RuleConfiguration> 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.
*
Expand Down

0 comments on commit c2cb6db

Please sign in to comment.