You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/06/28 10:21:06 UTC
(shardingsphere) branch master updated: Split ConfigurationChangedSubscriber to StorageUnitEventSubscriber GlobalRuleConfigurationEventSubscriber PropertiesEventSubscriber (#31914)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 c9bdb8cd923 Split ConfigurationChangedSubscriber to StorageUnitEventSubscriber GlobalRuleConfigurationEventSubscriber PropertiesEventSubscriber (#31914)
c9bdb8cd923 is described below
commit c9bdb8cd92358586edd88e2867ae3f8688444eab
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Jun 28 18:20:59 2024 +0800
Split ConfigurationChangedSubscriber to StorageUnitEventSubscriber GlobalRuleConfigurationEventSubscriber PropertiesEventSubscriber (#31914)
---
.../ClusterDispatchEventSubscriberRegistry.java | 6 ++-
.../GlobalRuleConfigurationEventSubscriber.java | 49 ++++++++++++++++++++++
.../subscriber/PropertiesEventSubscriber.java | 47 +++++++++++++++++++++
...criber.java => StorageUnitEventSubscriber.java} | 37 +---------------
4 files changed, 102 insertions(+), 37 deletions(-)
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
index 5572b8fd24d..7d213fe8170 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ClusterDispatchEventSubscriberRegistry.java
@@ -46,7 +46,6 @@ public class ClusterDispatchEventSubscriberRegistry implements EventSubscriberRe
eventBusContext = contextManager.getComputeNodeInstanceContext().getEventBusContext();
repository = (ClusterPersistRepository) contextManager.getRepository();
subscribers = Arrays.asList(new RuleItemChangedSubscriber(contextManager),
- new ConfigurationChangedSubscriber(contextManager),
new ResourceMetaDataChangedSubscriber(contextManager),
new ListenerAssistedMetaDataChangedSubscriber(contextManager),
new StateChangedSubscriber(contextManager),
@@ -54,7 +53,10 @@ public class ClusterDispatchEventSubscriberRegistry implements EventSubscriberRe
new ProcessListChangedSubscriber(contextManager),
new CacheEvictedSubscriber(),
new ComputeNodeOnlineSubscriber(contextManager),
- new QualifiedDataSourceSubscriber(contextManager));
+ new QualifiedDataSourceSubscriber(contextManager),
+ new StorageUnitEventSubscriber(contextManager),
+ new GlobalRuleConfigurationEventSubscriber(contextManager),
+ new PropertiesEventSubscriber(contextManager));
}
@Override
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/GlobalRuleConfigurationEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/GlobalRuleConfigurationEventSubscriber.java
new file mode 100644
index 00000000000..8e8f426e793
--- /dev/null
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/GlobalRuleConfigurationEventSubscriber.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
+
+import com.google.common.eventbus.Subscribe;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
+import org.apache.shardingsphere.mode.event.config.AlterGlobalRuleConfigurationEvent;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+
+/**
+ * Global rule configuration event subscriber.
+ */
+@RequiredArgsConstructor
+public final class GlobalRuleConfigurationEventSubscriber implements EventSubscriber {
+
+ private final ContextManager contextManager;
+
+ /**
+ * Renew for global rule configuration.
+ *
+ * @param event global rule alter event
+ */
+ @Subscribe
+ public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) {
+ if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
+ .getActiveVersionByFullPath(event.getActiveVersionKey()))) {
+ return;
+ }
+ contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().load(event.getRuleSimpleName())
+ .ifPresent(optional -> contextManager.getMetaDataContextManager().getConfigurationManager().alterGlobalRuleConfiguration(optional));
+
+ }
+}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/PropertiesEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/PropertiesEventSubscriber.java
new file mode 100644
index 00000000000..80a16ff58d9
--- /dev/null
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/PropertiesEventSubscriber.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
+
+import com.google.common.eventbus.Subscribe;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
+import org.apache.shardingsphere.mode.event.config.AlterPropertiesEvent;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+
+/**
+ * Properties event subscriber.
+ */
+@RequiredArgsConstructor
+public final class PropertiesEventSubscriber implements EventSubscriber {
+
+ private final ContextManager contextManager;
+
+ /**
+ * Renew for global properties.
+ *
+ * @param event global properties alter event
+ */
+ @Subscribe
+ public synchronized void renew(final AlterPropertiesEvent event) {
+ if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
+ .getActiveVersionByFullPath(event.getActiveVersionKey()))) {
+ return;
+ }
+ contextManager.getMetaDataContextManager().getConfigurationManager().alterProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().load());
+ }
+}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StorageUnitEventSubscriber.java
similarity index 66%
rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StorageUnitEventSubscriber.java
index 78348cdfd13..717b790adc6 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StorageUnitEventSubscriber.java
@@ -20,19 +20,16 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
import com.google.common.eventbus.Subscribe;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber;
-import org.apache.shardingsphere.mode.event.config.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.mode.event.config.AlterPropertiesEvent;
import org.apache.shardingsphere.mode.event.datasource.unit.AlterStorageUnitEvent;
import org.apache.shardingsphere.mode.event.datasource.unit.RegisterStorageUnitEvent;
import org.apache.shardingsphere.mode.event.datasource.unit.UnregisterStorageUnitEvent;
import org.apache.shardingsphere.mode.manager.ContextManager;
/**
- * Configuration changed subscriber.
+ * Storage unit event subscriber.
*/
@RequiredArgsConstructor
-@SuppressWarnings("unused")
-public final class ConfigurationChangedSubscriber implements EventSubscriber {
+public final class StorageUnitEventSubscriber implements EventSubscriber {
private final ContextManager contextManager;
@@ -78,34 +75,4 @@ public final class ConfigurationChangedSubscriber implements EventSubscriber {
}
contextManager.getMetaDataContextManager().getConfigurationManager().unregisterStorageUnit(event.getDatabaseName(), event.getStorageUnitName());
}
-
- /**
- * Renew for global rule configuration.
- *
- * @param event global rule alter event
- */
- @Subscribe
- public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) {
- if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
- .getActiveVersionByFullPath(event.getActiveVersionKey()))) {
- return;
- }
- contextManager.getPersistServiceFacade().getMetaDataPersistService().getGlobalRuleService().load(event.getRuleSimpleName())
- .ifPresent(optional -> contextManager.getMetaDataContextManager().getConfigurationManager().alterGlobalRuleConfiguration(optional));
-
- }
-
- /**
- * Renew for global properties.
- *
- * @param event global properties alter event
- */
- @Subscribe
- public synchronized void renew(final AlterPropertiesEvent event) {
- if (!event.getActiveVersion().equals(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService()
- .getActiveVersionByFullPath(event.getActiveVersionKey()))) {
- return;
- }
- contextManager.getMetaDataContextManager().getConfigurationManager().alterProperties(contextManager.getPersistServiceFacade().getMetaDataPersistService().getPropsService().load());
- }
}