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 9bdf5068dd4 Refactor ClusterContextManagerBuilder (#31253)
9bdf5068dd4 is described below

commit 9bdf5068dd4ae771041f1a1dfa3166f3bf285b65
Author: Liang Zhang <[email protected]>
AuthorDate: Thu May 16 20:10:10 2024 +0800

    Refactor ClusterContextManagerBuilder (#31253)
---
 .../mode/manager/cluster/ClusterContextManagerBuilder.java     | 10 ++++++----
 .../mode/manager/cluster/coordinator/RegistryCenter.java       |  5 -----
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 5ccf4f4cb3b..d97d32bab41 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.subscriber.ShardingSphereSchemaDataRegistrySubscriber;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.subscriber.ClusterProcessSubscriber;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.service.ClusterStatusService;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.subscriber.ClusterStatusSubscriber;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.subscriber.ComputeNodeStatusSubscriber;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber.QualifiedDataSourceStatusSubscriber;
@@ -66,7 +67,7 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
         setContextManagerAware(result);
         createSubscribers(eventBusContext, repository);
         registerOnline(registryCenter, param, result);
-        setClusterStatus(registryCenter, result);
+        setClusterState(repository, result);
         return result;
     }
     
@@ -102,12 +103,13 @@ public final class ClusterContextManagerBuilder 
implements ContextManagerBuilder
         new ClusterEventSubscriberRegistry(contextManager, 
registryCenter).register();
     }
     
-    private void setClusterStatus(final RegistryCenter registryCenter, final 
ContextManager contextManager) {
-        Optional<ClusterState> clusterState = 
registryCenter.getClusterStatusService().load();
+    private void setClusterState(final ClusterPersistRepository repository, 
final ContextManager contextManager) {
+        ClusterStatusService clusterStatusService = new 
ClusterStatusService(repository);
+        Optional<ClusterState> clusterState = clusterStatusService.load();
         if (clusterState.isPresent()) {
             contextManager.updateClusterState(clusterState.get());
         } else {
-            registryCenter.getClusterStatusService().persist(ClusterState.OK);
+            clusterStatusService.persist(ClusterState.OK);
         }
     }
     
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
index b7c05e0f5ce..0b92eff5d3f 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/RegistryCenter.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.instance.metadata.jdbc.JDBCInstanceMetaDa
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.GlobalLockPersistService;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory;
-import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.service.ClusterStatusService;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
@@ -47,9 +46,6 @@ public final class RegistryCenter {
     
     private final Map<String, DatabaseConfiguration> databaseConfigs;
     
-    @Getter
-    private final ClusterStatusService clusterStatusService;
-    
     @Getter
     private final QualifiedDataSourceStatusService 
qualifiedDataSourceStatusService;
     
@@ -66,7 +62,6 @@ public final class RegistryCenter {
         this.repository = repository;
         this.instanceMetaData = instanceMetaData;
         this.databaseConfigs = databaseConfigs;
-        clusterStatusService = new ClusterStatusService(repository);
         qualifiedDataSourceStatusService = new 
QualifiedDataSourceStatusService(repository);
         computeNodeStatusService = new ComputeNodeStatusService(repository);
         globalLockPersistService = new 
GlobalLockPersistService(initDistributedLockHolder(repository));

Reply via email to