From 7ea04f2da81344c1117f10f850a641cc8f2804cf Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Wed, 22 May 2024 21:30:50 +0800 Subject: [PATCH] Refactor alterRuleConfiguration and removeRuleConfigurationItem interface in StandaloneModeContextManager --- .../standalone/StandaloneModeContextManager.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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..0d145f8ae5e18 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 @@ -269,20 +269,20 @@ public Collection alterRuleConfiguration(final String databaseN Collection metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService() .persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig)); contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions); - sendDatabaseRuleChangedEvent(databaseName, metaDataVersions); + sendDatabaseRuleChangedEvent(databaseName, metaDataVersions, Type.UPDATED); clearServiceCache(); } return Collections.emptyList(); } - private void sendDatabaseRuleChangedEvent(final String databaseName, final Collection metaDataVersions) { + private void sendDatabaseRuleChangedEvent(final String databaseName, final Collection metaDataVersions, final Type type) { for (MetaDataVersion each : metaDataVersions) { - sendDatabaseRuleChangedEvent(databaseName, each); + sendDatabaseRuleChangedEvent(databaseName, each, type); } } - private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaDataVersion metaDataVersion) { - ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), Type.UPDATED)) + private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) { + ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)) .ifPresent(optional -> contextManager.getComputeNodeInstanceContext().getEventBusContext().post(optional)); } @@ -290,7 +290,8 @@ private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaD public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { if (null != toBeRemovedRuleConfig) { sendDatabaseRuleChangedEvent(databaseName, - contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig))); + contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, + Collections.singleton(toBeRemovedRuleConfig)), Type.DELETED); clearServiceCache(); } }