Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor alterRuleConfiguration and removeRuleConfigurationItem interface in StandaloneModeContextManager #31347

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
import org.apache.shardingsphere.mode.event.NamedRuleItemChangedEventCreator;
import org.apache.shardingsphere.mode.event.UniqueRuleItemChangedEventCreator;
import org.apache.shardingsphere.mode.spi.RuleNodePathProvider;
Expand Down Expand Up @@ -54,7 +55,7 @@ public Optional<GovernanceEvent> build(final String databaseName, final DataChan
}

private Optional<GovernanceEvent> build(final RuleNodePath ruleNodePath, final String databaseName, final DataChangedEvent event) {
if (!ruleNodePath.getRoot().isValidatedPath(event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
if (!ruleNodePath.getRoot().isValidatedPath(event.getKey()) || Type.DELETED != event.getType() && Strings.isNullOrEmpty(event.getValue())) {
return Optional.empty();
}
for (Entry<String, NamedRuleItemNodePath> entry : ruleNodePath.getNamedItems().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,23 @@ private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaD
@Override
public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) {
if (null != toBeRemovedRuleConfig) {
sendDatabaseRuleChangedEvent(databaseName,
sendDatabaseRuleDeletedEvent(databaseName,
contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig)));
clearServiceCache();
}
}

private void sendDatabaseRuleDeletedEvent(final String databaseName, final Collection<MetaDataVersion> metaDataVersions) {
for (MetaDataVersion each : metaDataVersions) {
sendDatabaseRuleDeletedEvent(databaseName, each);
}
}

private void sendDatabaseRuleDeletedEvent(final String databaseName, final MetaDataVersion metaDataVersion) {
ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), "", Type.DELETED))
.ifPresent(optional -> contextManager.getComputeNodeInstanceContext().getEventBusContext().post(optional));
}

@Override
public void removeRuleConfiguration(final String databaseName, final String ruleName) {
contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().delete(databaseName, ruleName);
Expand Down
Loading