diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/builder/RuleConfigurationEventBuilder.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/builder/RuleConfigurationEventBuilder.java index 0b9f2e6ef13af..758c5b8460f7b 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/builder/RuleConfigurationEventBuilder.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/builder/RuleConfigurationEventBuilder.java @@ -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; @@ -54,7 +55,7 @@ public Optional build(final String databaseName, final DataChan } private Optional 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 entry : ruleNodePath.getNamedItems().entrySet()) { diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java index 2f08536cab280..716cd34548e18 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java @@ -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 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);