This is an automated email from the ASF dual-hosted git repository.

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new c46a11c9767 Fix #30046 (#30048)
c46a11c9767 is described below

commit c46a11c976736084436931f68cbcabaa6703217b
Author: zhaojinchao <[email protected]>
AuthorDate: Wed Feb 7 16:58:15 2024 +0800

    Fix #30046 (#30048)
---
 .../mode/subsciber/RuleItemChangedSubscriber.java          | 14 ++++++++++++--
 .../standalone/NewStandaloneContextManagerBuilder.java     |  6 ++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
index 7d52720f764..b88030183f1 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/subsciber/RuleItemChangedSubscriber.java
@@ -55,7 +55,12 @@ public final class RuleItemChangedSubscriber {
         RuleConfiguration currentRuleConfig = 
processor.findRuleConfiguration(database);
         synchronized (this) {
             processor.changeRuleItemConfiguration(event, currentRuleConfig, 
processor.swapRuleItemConfiguration(event, yamlContent));
-            contextManager.getInstanceContext().getEventBusContext().post(new 
AlterDatabaseRuleConfigurationEvent(event.getDatabaseName(), 
currentRuleConfig));
+            // TODO Remove isCluster judgment
+            if (contextManager.getInstanceContext().isCluster()) {
+                
contextManager.getInstanceContext().getEventBusContext().post(new 
AlterDatabaseRuleConfigurationEvent(event.getDatabaseName(), 
currentRuleConfig));
+                return;
+            }
+            
contextManager.getConfigurationContextManager().alterRuleConfiguration(event.getDatabaseName(),
 currentRuleConfig);
         }
     }
     
@@ -75,7 +80,12 @@ public final class RuleItemChangedSubscriber {
         RuleConfiguration currentRuleConfig = 
processor.findRuleConfiguration(database);
         synchronized (this) {
             processor.dropRuleItemConfiguration(event, currentRuleConfig);
-            contextManager.getInstanceContext().getEventBusContext().post(new 
DropDatabaseRuleConfigurationEvent(event.getDatabaseName(), currentRuleConfig));
+            // TODO Remove isCluster judgment
+            if (contextManager.getInstanceContext().isCluster()) {
+                
contextManager.getInstanceContext().getEventBusContext().post(new 
DropDatabaseRuleConfigurationEvent(event.getDatabaseName(), currentRuleConfig));
+                return;
+            }
+            
contextManager.getConfigurationContextManager().dropRuleConfiguration(event.getDatabaseName(),
 currentRuleConfig);
         }
     }
 }
diff --git 
a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneContextManagerBuilder.java
 
b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneContextManagerBuilder.java
index eeb80576e06..5615fd18bc5 100644
--- 
a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneContextManagerBuilder.java
+++ 
b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneContextManagerBuilder.java
@@ -32,6 +32,7 @@ import 
org.apache.shardingsphere.mode.manager.standalone.workerid.generator.Stan
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.mode.metadata.NewMetaDataContextsFactory;
 import 
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
+import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscriber;
 
 import java.sql.SQLException;
 import java.util.Properties;
@@ -52,6 +53,7 @@ public final class NewStandaloneContextManagerBuilder 
implements ContextManagerB
         new StandaloneProcessSubscriber(instanceContext.getEventBusContext());
         MetaDataContexts metaDataContexts = 
NewMetaDataContextsFactory.create(persistService, param, instanceContext);
         ContextManager result = new ContextManager(metaDataContexts, 
instanceContext);
+        registerSubscriber(result);
         setContextManagerAware(result);
         return result;
     }
@@ -61,6 +63,10 @@ public final class NewStandaloneContextManagerBuilder 
implements ContextManagerB
                 new StandaloneWorkerIdGenerator(), 
param.getModeConfiguration(), new NewStandaloneModeContextManager(), new 
GlobalLockContext(null), new EventBusContext());
     }
     
+    private void registerSubscriber(final ContextManager contextManager) {
+        contextManager.getInstanceContext().getEventBusContext().register(new 
RuleItemChangedSubscriber(contextManager));
+    }
+    
     private void setContextManagerAware(final ContextManager contextManager) {
         ((NewStandaloneModeContextManager) 
contextManager.getInstanceContext().getModeContextManager()).setContextManagerAware(contextManager);
     }

Reply via email to