Skip to content

Commit

Permalink
Remove use original database to build new MetaDataContexts (apache#34222
Browse files Browse the repository at this point in the history
)
  • Loading branch information
menghaoranss authored Jan 2, 2025
1 parent 680c0db commit a6a09ba
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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<ShardingSphereRule> rules) throws SQLException {
database.getRuleMetaData().getRules().clear();
database.getRuleMetaData().getRules().addAll(rules);
private void refreshMetadata(final String databaseName, final Collection<RuleConfiguration> 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<RuleConfiguration> getRuleConfigurations(final Collection<ShardingSphereRule> rules) {
return rules.stream().map(ShardingSphereRule::getConfiguration).collect(Collectors.toList());
}
}

0 comments on commit a6a09ba

Please sign in to comment.